Class: DynamoidAdvancedWhere::Nodes::RootNode

Inherits:
BaseNode
  • Object
show all
Extended by:
Forwardable
Defined in:
lib/dynamoid_advanced_where/nodes/root_node.rb

Instance Attribute Summary collapse

Attributes inherited from BaseNode

#expression_prefix

Instance Method Summary collapse

Methods inherited from BaseNode

#expression_attribute_names, #expression_attribute_values

Constructor Details

#initialize(klass:, &blk) ⇒ RootNode

Returns a new instance of RootNode.



12
13
14
15
16
17
# File 'lib/dynamoid_advanced_where/nodes/root_node.rb', line 12

def initialize(klass:, &blk)
  self.klass = klass
  evaluate_block(blk) if blk
  self.child_node ||= AndNode.new
  freeze
end

Dynamic Method Handling

This class handles dynamic methods through the method_missing method

#method_missing(method, *args, &blk) ⇒ Object



19
20
21
22
23
24
25
# File 'lib/dynamoid_advanced_where/nodes/root_node.rb', line 19

def method_missing(method, *args, &blk)
  if allowed_field?(method)
    FieldNode.create_node(attr_config: klass.attributes[method], field_path: method)
  else
    super
  end
end

Instance Attribute Details

#child_nodeObject

Returns the value of attribute child_node.



10
11
12
# File 'lib/dynamoid_advanced_where/nodes/root_node.rb', line 10

def child_node
  @child_node
end

#klassObject

Returns the value of attribute klass.



10
11
12
# File 'lib/dynamoid_advanced_where/nodes/root_node.rb', line 10

def klass
  @klass
end

Instance Method Details

#allowed_field?(method) ⇒ Boolean

Returns:

  • (Boolean)


31
32
33
# File 'lib/dynamoid_advanced_where/nodes/root_node.rb', line 31

def allowed_field?(method)
  klass.attributes.key?(method.to_sym)
end

#respond_to_missing?(method, _i) ⇒ Boolean

Returns:

  • (Boolean)


27
28
29
# File 'lib/dynamoid_advanced_where/nodes/root_node.rb', line 27

def respond_to_missing?(method, _i)
  allowed_field?(method)
end