module DeepCover::Node::Mixin::CanAugmentChildren
Public Class Methods
included(base)
click to toggle source
# File lib/deep_cover/node/mixin/can_augment_children.rb, line 6 def self.included(base) base.has_child_handler('remap_%{name}') base.singleton_class.prepend ClassMethods end
Public Instance Methods
remap_child(child, name = nil)
click to toggle source
# File lib/deep_cover/node/mixin/can_augment_children.rb, line 30 def remap_child(child, name = nil) return unless child.is_a?(Parser::AST::Node) class_name = Tools.camelize(child.type) Node.const_defined?(class_name) ? Node.const_get(class_name) : Node end
Private Instance Methods
augment_children(child_base_nodes)
click to toggle source
Augment creates a covered node from the child_base_node. Caution: receiver is not fully constructed since it is also being augmented.
don't call `children`
# File lib/deep_cover/node/mixin/can_augment_children.rb, line 14 def augment_children(child_base_nodes) if child_base_nodes.size < (sz = self.class.min_children) child_base_nodes = child_base_nodes.dup child_base_nodes[sz..-1] = [] # Fill with nil end child_base_nodes.map.with_index do |child, child_index| child_name = self.class.child_index_to_name(child_index, child_base_nodes.size) if (klass = remap_child(child, child_name)) klass.new(child, parent: self, index: child_index) else child end end end