require 'active_resource'

class Import::Resources::Base < ActiveResource::Base
  self.site = ""

  def self.import(&block)
    define_method(:_create_data_from_import, &block)
  end
  
  def self.with_import_url(import_url)
    self.site = import_url
    @import_url = import_url
    self
  end

  def self.collection_path(prefix_options = {}, query_options = nil)
    @import_url
  end
end

Add Resource Base class for imports
Add Resource Base class for imports

This is the base class for all import resources. It can be used as
follows:

class Import::Resources::User < Import::Resources::Base
    validates :name, presence: true
    import do
      ::User.create(name: name)
    end
end

The import is only triggered if the model is valid (in terms of
ActiveModel). Otherwise an error is logged.
