Module: AMC::Acts::Importable::SingletonMethods

Defined in:
lib/acts_as_importable.rb

Overview

ClassMethods

Instance Method Summary collapse

Instance Method Details

#flush_lookups!Object



46
47
48
# File 'lib/acts_as_importable.rb', line 46

def flush_lookups!
  @lookups = {}
end

#import(id) ⇒ Object



24
25
26
# File 'lib/acts_as_importable.rb', line 24

def import(id)
  find(id).import
end

#import_all(*args) ⇒ Object



28
29
30
31
32
# File 'lib/acts_as_importable.rb', line 28

def import_all(*args)
  all(*args).each do |legacy_model|
    legacy_model.import
  end
end

#import_all_in_batches(*args) ⇒ Object

This requires a numeric primary key for the legacy tables



35
36
37
38
39
# File 'lib/acts_as_importable.rb', line 35

def import_all_in_batches(*args)
  find_each(*args) do |legacy_model|
    legacy_model.import
  end
end

#lookup(id) ⇒ Object



41
42
43
44
# File 'lib/acts_as_importable.rb', line 41

def lookup(id)
  lookup_class = read_inheritable_attribute(:importable_to) || "#{self.to_s.split('::').last}"
  lookups[id] ||= Kernel.const_get(lookup_class).first(:conditions => {:legacy_id => id, :legacy_class => self.to_s}).try(:id)
end