Class: Prato::Types::RubyColumn
- Inherits:
-
Object
- Object
- Prato::Types::RubyColumn
- Defined in:
- lib/prato/types/ruby_column.rb
Instance Attribute Summary collapse
-
#filter ⇒ Object
readonly
Returns the value of attribute filter.
-
#includes ⇒ Object
readonly
Returns the value of attribute includes.
-
#loader ⇒ Object
readonly
Returns the value of attribute loader.
Instance Method Summary collapse
- #extract_value(record, ruby_data) ⇒ Object
-
#initialize(loader, key:, filter: nil, includes: nil) ⇒ RubyColumn
constructor
A new instance of RubyColumn.
Constructor Details
#initialize(loader, key:, filter: nil, includes: nil) ⇒ RubyColumn
Returns a new instance of RubyColumn.
8 9 10 11 12 13 |
# File 'lib/prato/types/ruby_column.rb', line 8 def initialize(loader, key:, filter: nil, includes: nil) @loader = loader @key = key || :id @filter = filter @includes = includes end |
Instance Attribute Details
#filter ⇒ Object (readonly)
Returns the value of attribute filter.
6 7 8 |
# File 'lib/prato/types/ruby_column.rb', line 6 def filter @filter end |
#includes ⇒ Object (readonly)
Returns the value of attribute includes.
6 7 8 |
# File 'lib/prato/types/ruby_column.rb', line 6 def includes @includes end |
#loader ⇒ Object (readonly)
Returns the value of attribute loader.
6 7 8 |
# File 'lib/prato/types/ruby_column.rb', line 6 def loader @loader end |
Instance Method Details
#extract_value(record, ruby_data) ⇒ Object
15 16 17 18 19 20 21 22 23 24 25 26 27 28 |
# File 'lib/prato/types/ruby_column.rb', line 15 def extract_value(record, ruby_data) key_value = case @key when Proc @key.call(record) when Array @key.reduce(record) { |obj, method| obj.public_send(method) } when Symbol record.public_send(@key) else @key end ruby_data[@loader]&.[](key_value) end |