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)
-
- (Object) ar_class
The ActiveRecord class to use.
-
- (Object) find_method
The find method to use (as a symbol).
Instance Method Summary (collapse)
-
- (ActiveRecordResolver) initialize(ar_class, find_method)
constructor
Initialize the resolver.
-
- (Object) resolve(value)
Resolve the value.
Constructor Details
- (ActiveRecordResolver) initialize(ar_class, find_method)
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
- (Object) ar_class
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 |
- (Object) find_method
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
- (Object) resolve(value)
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 |