Class: DynamoidAdvancedWhere::Nodes::FieldNode
- Defined in:
- lib/dynamoid_advanced_where/nodes/field_node.rb
Direct Known Subclasses
CustomClassAttributeNode, IntegerSetAttributeNode, MapAttributeNode, NativeBooleanAttributeNode, NumberAttributeNode, NumericDateAttributeNode, NumericDatetimeAttributeNode, RawAttributeNode, StringAttributeNode, StringBooleanAttributeNode, StringSetAttributeNode
Instance Attribute Summary collapse
-
#attr_prefix ⇒ Object
Returns the value of attribute attr_prefix.
-
#field_path ⇒ Object
Returns the value of attribute field_path.
Attributes inherited from BaseNode
Class Method Summary collapse
Instance Method Summary collapse
- #expression_attribute_names ⇒ Object
- #expression_attribute_values ⇒ Object
-
#initialize(field_path:) ⇒ FieldNode
constructor
A new instance of FieldNode.
- #to_expression ⇒ Object
Methods included from Concerns::SupportsExistance
Methods included from Concerns::SupportsEquality
Constructor Details
#initialize(field_path:) ⇒ FieldNode
Returns a new instance of FieldNode.
31 32 33 34 35 |
# File 'lib/dynamoid_advanced_where/nodes/field_node.rb', line 31 def initialize(field_path:) self.field_path = field_path.is_a?(Array) ? field_path : [field_path] self.attr_prefix = SecureRandom.hex freeze end |
Instance Attribute Details
#attr_prefix ⇒ Object
Returns the value of attribute attr_prefix.
15 16 17 |
# File 'lib/dynamoid_advanced_where/nodes/field_node.rb', line 15 def attr_prefix @attr_prefix end |
#field_path ⇒ Object
Returns the value of attribute field_path.
15 16 17 |
# File 'lib/dynamoid_advanced_where/nodes/field_node.rb', line 15 def field_path @field_path end |
Class Method Details
.create_node(field_path:, attr_config:) ⇒ Object
18 19 20 21 22 23 24 25 26 27 28 |
# File 'lib/dynamoid_advanced_where/nodes/field_node.rb', line 18 def create_node(field_path:, attr_config:) specific_klass = FIELD_MAPPING.detect do |config, _type| config.respond_to?(:call) ? config.call(attr_config) : config <= attr_config end&.last unless specific_klass raise ArgumentError, "unable to find field type for `#{attr_config}`" end specific_klass.new(field_path: field_path) end |
Instance Method Details
#expression_attribute_names ⇒ Object
50 51 52 53 54 55 56 |
# File 'lib/dynamoid_advanced_where/nodes/field_node.rb', line 50 def expression_attribute_names field_path.each_with_object({}).with_index do |(segment, hsh), i| next if segment.is_a?(Integer) hsh["##{attr_prefix}#{i}"] = segment end end |
#expression_attribute_values ⇒ Object
58 59 60 |
# File 'lib/dynamoid_advanced_where/nodes/field_node.rb', line 58 def expression_attribute_values {} end |
#to_expression ⇒ Object
37 38 39 40 41 42 43 44 45 46 47 48 |
# File 'lib/dynamoid_advanced_where/nodes/field_node.rb', line 37 def to_expression String.new.tap do |s| field_path.collect.with_index do |segment, i| if segment.is_a?(Integer) s << "[#{segment}]" else s << '.' unless s.blank? s << "##{attr_prefix}#{i}" end end end end |