Class: Cadenza::BlockNode

Inherits:
Object
  • Object
show all
Defined in:
lib/cadenza/nodes/block_node.rb

Overview

The BlockNode is a general container with a given name meant to implement Cadenza's template inheritance feature. Blocks defined in a template will override the definition of blocks defined in the parent template.

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(name, children = []) ⇒ BlockNode

creates a new block node with the given name and child nodes

Parameters:

  • name (String)

    the name for this block node

  • children (Array) (defaults to: [])

    the child nodes belonging to this block node



15
16
17
18
# File 'lib/cadenza/nodes/block_node.rb', line 15

def initialize(name, children=[])
   @name = name
   @children = children
end

Instance Attribute Details

#childrenArray

Returns the child nodes belonging to this block

Returns:

  • (Array)

    the child nodes belonging to this block



10
11
12
# File 'lib/cadenza/nodes/block_node.rb', line 10

def children
  @children
end

#nameString

Returns the name of the node

Returns:

  • (String)

    the name of the node



7
8
9
# File 'lib/cadenza/nodes/block_node.rb', line 7

def name
  @name
end

Instance Method Details

#==(rhs) ⇒ Boolean

Returns true if the given Cadenza::BlockNode is equivalent to the this node by value.

Parameters:

Returns:

  • (Boolean)

    true if the given Cadenza::BlockNode is equivalent to the this node by value.



29
30
31
32
# File 'lib/cadenza/nodes/block_node.rb', line 29

def ==(rhs)
   @name == rhs.name and
   @children == rhs.children
end

#implied_globalsArray

Returns a list of any implied global variable names defined by this block's children.

Returns:

  • (Array)

    a list of any implied global variable names defined by this block's children.



22
23
24
# File 'lib/cadenza/nodes/block_node.rb', line 22

def implied_globals
   @children.map(&:implied_globals).flatten.uniq
end