Class: Realize::Value::Resolve
- Inherits:
-
Object
- Object
- Realize::Value::Resolve
- Defined in:
- lib/realize/value/resolve.rb
Overview
Basic transformer that can take an object and extract a value based off the transformer’s key. If the value passed in is an array then it will select the first record.
Instance Attribute Summary collapse
-
#key ⇒ Object
readonly
Returns the value of attribute key.
Instance Method Summary collapse
-
#initialize(key:) ⇒ Resolve
constructor
A new instance of Resolve.
- #transform(resolver, value, _time, _record) ⇒ Object
Constructor Details
#initialize(key:) ⇒ Resolve
Returns a new instance of Resolve.
19 20 21 22 23 24 25 |
# File 'lib/realize/value/resolve.rb', line 19 def initialize(key:) raise ArgumentError, 'key is required' if key.to_s.empty? @key = key freeze end |
Instance Attribute Details
#key ⇒ Object (readonly)
Returns the value of attribute key.
17 18 19 |
# File 'lib/realize/value/resolve.rb', line 17 def key @key end |
Instance Method Details
#transform(resolver, value, _time, _record) ⇒ Object
27 28 29 30 31 |
# File 'lib/realize/value/resolve.rb', line 27 def transform(resolver, value, _time, _record) record = first(value) resolver.get(record, key) end |