Class: ActiveRecordResolver
- Inherits:
-
Object
- Object
- 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.
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_class ⇒ Object
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_method ⇒ Object
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 |