Class: ActiveRecordResolver

Inherits:
Object
  • Object
show all
Defined in:
lib/etl/transform/foreign_key_lookup_transform.rb

Overview

Resolver which resolves using ActiveRecord.

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(ar_class, find_method) ⇒ ActiveRecordResolver

Initialize the resolver. The ar_class argument should extend from ActiveRecord::Base. The find_method argument must be a symbol for the finder method used. For example:

ActiveRecordResolver.new(Person, :find_by_name)

Note that the find method defined must only take a single argument.



69
70
71
72
# File 'lib/etl/transform/foreign_key_lookup_transform.rb', line 69

def initialize(ar_class, find_method)
  @ar_class = ar_class
  @find_method = find_method
end

Instance Attribute Details

#ar_classObject

The ActiveRecord class to use



57
58
59
# File 'lib/etl/transform/foreign_key_lookup_transform.rb', line 57

def ar_class
  @ar_class
end

#find_methodObject

The find method to use (as a symbol)



60
61
62
# File 'lib/etl/transform/foreign_key_lookup_transform.rb', line 60

def find_method
  @find_method
end

Instance Method Details

#resolve(value) ⇒ Object

Resolve the value



75
76
77
78
# File 'lib/etl/transform/foreign_key_lookup_transform.rb', line 75

def resolve(value)
  rec = ar_class.__send__(find_method, value)
  rec.nil? ? nil : rec.id
end