Module: Plumb::VisitorHandlers

Included in:
JSONSchemaVisitor, MetadataVisitor
Defined in:
lib/plumb/visitor_handlers.rb

Defined Under Namespace

Modules: ClassMethods

Class Method Summary collapse

Instance Method Summary collapse

Class Method Details

.included(base) ⇒ Object



5
6
7
# File 'lib/plumb/visitor_handlers.rb', line 5

def self.included(base)
  base.extend(ClassMethods)
end

Instance Method Details

#on_missing_handler(node, _props, method_name) ⇒ Object



39
40
41
# File 'lib/plumb/visitor_handlers.rb', line 39

def on_missing_handler(node, _props, method_name)
  raise "No handler for #{node.inspect} with :#{method_name}"
end

#visit(node, props = BLANK_HASH) ⇒ Object



20
21
22
23
24
25
26
27
28
# File 'lib/plumb/visitor_handlers.rb', line 20

def visit(node, props = BLANK_HASH)
  method_name = if node.respond_to?(:node_name)
                  node.node_name
                else
                  :"#{(node.is_a?(::Class) ? node : node.class)}_class"
                end

  visit_name(method_name, node, props)
end

#visit_children(node, props = BLANK_HASH) ⇒ Object



43
44
45
46
47
# File 'lib/plumb/visitor_handlers.rb', line 43

def visit_children(node, props = BLANK_HASH)
  node.children.reduce(props) do |acc, child|
    visit(child, acc)
  end
end

#visit_name(method_name, node, props = BLANK_HASH) ⇒ Object



30
31
32
33
34
35
36
37
# File 'lib/plumb/visitor_handlers.rb', line 30

def visit_name(method_name, node, props = BLANK_HASH)
  method_name = :"visit_#{method_name}"
  if respond_to?(method_name)
    send(method_name, node, props)
  else
    on_missing_handler(node, props, method_name)
  end
end