Class: Arel::Enhance::Path

Inherits:
Object
  • Object
show all
Defined in:
lib/arel/enhance/path.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(nodes = []) ⇒ Path

Returns a new instance of Path.



6
7
8
# File 'lib/arel/enhance/path.rb', line 6

def initialize(nodes = [])
  @nodes = nodes
end

Instance Attribute Details

#nodesObject (readonly)

Returns the value of attribute nodes.



4
5
6
# File 'lib/arel/enhance/path.rb', line 4

def nodes
  @nodes
end

Instance Method Details

#append(path_node) ⇒ Object



10
11
12
# File 'lib/arel/enhance/path.rb', line 10

def append(path_node)
  Path.new(nodes + [path_node])
end

#currentObject



26
27
28
# File 'lib/arel/enhance/path.rb', line 26

def current
  nodes.last
end

#dig_send(object) ⇒ Object



14
15
16
17
18
19
20
# File 'lib/arel/enhance/path.rb', line 14

def dig_send(object)
  selected_object = object
  nodes.each do |path_node|
    selected_object = selected_object.send(*path_node.method)
  end
  selected_object
end

#inspectObject



30
31
32
33
34
35
# File 'lib/arel/enhance/path.rb', line 30

def inspect
  nodes.inspect
  string = '['
  string << nodes.map(&:inspect).join(', ')
  string << ']'
end

#to_aObject



22
23
24
# File 'lib/arel/enhance/path.rb', line 22

def to_a
  nodes.map(&:value)
end