Class: Arel::Enhance::Path
- Inherits:
-
Object
- Object
- Arel::Enhance::Path
- Defined in:
- lib/arel/enhance/path.rb
Instance Attribute Summary collapse
-
#nodes ⇒ Object
readonly
Returns the value of attribute nodes.
Instance Method Summary collapse
- #append(path_node) ⇒ Object
- #current ⇒ Object
- #dig_send(object) ⇒ Object
-
#initialize(nodes = []) ⇒ Path
constructor
A new instance of Path.
- #inspect ⇒ Object
- #to_a ⇒ Object
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
#nodes ⇒ Object (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 |
#current ⇒ Object
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 |
#inspect ⇒ Object
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_a ⇒ Object
22 23 24 |
# File 'lib/arel/enhance/path.rb', line 22 def to_a nodes.map(&:value) end |