Class: AgnosticBackend::Indexable::Field
- Inherits:
-
Object
- Object
- AgnosticBackend::Indexable::Field
- Defined in:
- lib/agnostic_backend/indexable/field.rb
Instance Attribute Summary collapse
-
#from ⇒ Object
Returns the value of attribute from.
-
#type ⇒ Object
Returns the value of attribute type.
-
#value ⇒ Object
Returns the value of attribute value.
Instance Method Summary collapse
- #evaluate(context:) ⇒ Object
-
#initialize(value, type, from: nil, **options) ⇒ Field
constructor
A new instance of Field.
Constructor Details
#initialize(value, type, from: nil, **options) ⇒ Field
Returns a new instance of Field.
8 9 10 11 12 13 14 15 |
# File 'lib/agnostic_backend/indexable/field.rb', line 8 def initialize(value, type, from: nil, **) if type == FieldType::STRUCT && from.nil? raise "A nested type requires the specification of a target class using the `from` argument" end @value = value.respond_to?(:call) ? value : value.to_sym @from = (from.is_a?(Enumerable) ? from : [from]) unless from.nil? @type = FieldType.new(type, **) end |
Instance Attribute Details
#from ⇒ Object
Returns the value of attribute from.
6 7 8 |
# File 'lib/agnostic_backend/indexable/field.rb', line 6 def from @from end |
#type ⇒ Object
Returns the value of attribute type.
6 7 8 |
# File 'lib/agnostic_backend/indexable/field.rb', line 6 def type @type end |
#value ⇒ Object
Returns the value of attribute value.
6 7 8 |
# File 'lib/agnostic_backend/indexable/field.rb', line 6 def value @value end |
Instance Method Details
#evaluate(context:) ⇒ Object
17 18 19 20 21 |
# File 'lib/agnostic_backend/indexable/field.rb', line 17 def evaluate(context:) value.respond_to?(:call) ? context.instance_eval(&value) : context.send(value) end |