Class: ActiveRecordResolver
- Defined in:
- lib/etl/transform/foreign_key_lookup_transform.rb
Overview
Resolver which resolves using ActiveRecord.
Instance Attribute Summary collapse
-
#ar_class ⇒ Object
The ActiveRecord class to use.
-
#find_method ⇒ Object
The find method to use (as a symbol).
Instance Method Summary collapse
-
#initialize(ar_class, find_method) ⇒ ActiveRecordResolver
constructor
Initialize the resolver.
-
#resolve(value) ⇒ Object
Resolve the value.
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.
73 74 75 76 |
# File 'lib/etl/transform/foreign_key_lookup_transform.rb', line 73 def initialize(ar_class, find_method) @ar_class = ar_class @find_method = find_method end |
Instance Attribute Details
#ar_class ⇒ Object
The ActiveRecord class to use
61 62 63 |
# File 'lib/etl/transform/foreign_key_lookup_transform.rb', line 61 def ar_class @ar_class end |
#find_method ⇒ Object
The find method to use (as a symbol)
64 65 66 |
# File 'lib/etl/transform/foreign_key_lookup_transform.rb', line 64 def find_method @find_method end |
Instance Method Details
#resolve(value) ⇒ Object
Resolve the value
79 80 81 82 |
# File 'lib/etl/transform/foreign_key_lookup_transform.rb', line 79 def resolve(value) rec = ar_class.__send__(find_method, value) rec.nil? ? nil : rec.id end |