Class: CommandBuilder::CodeGenerator::NodeCodeGenerator

Inherits:
Object
  • Object
show all
Defined in:
lib/command_builder/code_generator/node_code_generator.rb

Instance Method Summary collapse

Constructor Details

#initialize(node, command, writer) ⇒ NodeCodeGenerator

Returns a new instance of NodeCodeGenerator.



9
10
11
12
13
# File 'lib/command_builder/code_generator/node_code_generator.rb', line 9

def initialize(node, command, writer)
  @node = node
  @command = command
  @writer = writer
end

Instance Method Details

#renderObject



15
16
17
18
# File 'lib/command_builder/code_generator/node_code_generator.rb', line 15

def render
  render_branch_node if @node.branch?
  render_leaf_node if @node.leaf?
end

#render_methodObject



20
21
22
23
24
25
26
27
28
29
30
# File 'lib/command_builder/code_generator/node_code_generator.rb', line 20

def render_method
  @writer.write_method node_code_names.method_name, node_code_names.method_args do
    if @node.branch?
      render_branch_node_method_body
    else
      render_leaf_node_method_body
      @writer.write_line 'yield @b if block_given?'
      @writer.write_line 'self'
    end
  end
end