class Realize::Value::Resolve
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.
Attributes
key[R]
Public Class Methods
new(key:)
click to toggle source
# 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
Public Instance Methods
transform(resolver, value, _time, _record)
click to toggle source
# File lib/realize/value/resolve.rb, line 27 def transform(resolver, value, _time, _record) record = first(value) resolver.get(record, key) end
Private Instance Methods
first(value)
click to toggle source
# File lib/realize/value/resolve.rb, line 35 def first(value) value.is_a?(Array) ? value.first : value end