lib/arel/enhance/node.rb in arel_toolkit-0.4.5 vs lib/arel/enhance/node.rb in arel_toolkit-0.4.6

- old
+ new

@@ -1,33 +1,27 @@ module Arel module Enhance class Node + attr_reader :local_path attr_reader :object attr_reader :parent - attr_reader :local_path - attr_reader :fields - attr_reader :children attr_reader :root_node - attr_reader :context def initialize(object) @object = object @root_node = self - @fields = [] - @children = {} @dirty = false - @context = {} end def inspect recursive_inspect('') end def value return unless value? - @fields.first + fields.first end def each(&block) return enum_for(:each) unless block_given? @@ -56,11 +50,11 @@ def add(path_node, node) node.local_path = path_node node.parent = self node.root_node = root_node - @children[path_node.value.to_s] = node + children[path_node.value.to_s] = node end def to_sql(engine = Table.engine) return nil if children.empty? @@ -76,23 +70,23 @@ def to_sql_and_binds(engine = Table.engine) object.to_sql_and_binds(engine) end def method_missing(name, *args, &block) - child = @children[name.to_s] + child = children[name.to_s] return super if child.nil? child end def respond_to_missing?(method, include_private = false) - child = @children[method.to_s] + child = children[method.to_s] child.present? || super end def [](key) - @children.fetch(key.to_s) + children.fetch(key.to_s) end def child_at_path(path_items) selected_node = self path_items.each do |path_item| @@ -114,9 +108,21 @@ the_path.unshift current_parent.local_path current_parent = current_parent.parent end the_path.compact + end + + def children + @children ||= {} + end + + def fields + @fields ||= [] + end + + def context + @context ||= {} end protected attr_writer :local_path