Module: Cadenza::Context::Blocks
- Included in:
- Cadenza::Context
- Defined in:
- lib/cadenza/context/blocks.rb
Instance Attribute Summary collapse
-
#blocks ⇒ Hash
readonly
The block names mapped to their implementing procs.
Instance Method Summary collapse
-
#alias_block(original_name, alias_name) ⇒ Object
creates an alias of the given block name under a different name.
-
#define_block(name) {|Context, Array, *args| ... } ⇒ Object
defines a generic block proc with the given name.
-
#evaluate_block(name, nodes, parameters) ⇒ String
calls the defined generic block proc with the given name and children nodes.
-
#lookup_block(name) ⇒ Proc
looks up the block by name.
Instance Attribute Details
#blocks ⇒ Hash (readonly)
Returns the block names mapped to their implementing procs.
10 11 12 |
# File 'lib/cadenza/context/blocks.rb', line 10 def blocks @blocks ||= {} end |
Instance Method Details
#alias_block(original_name, alias_name) ⇒ Object
creates an alias of the given block name under a different name
42 43 44 |
# File 'lib/cadenza/context/blocks.rb', line 42 def alias_block(original_name, alias_name) define_block alias_name, &lookup_block(original_name) end |
#define_block(name) {|Context, Array, *args| ... } ⇒ Object
defines a generic block proc with the given name
31 32 33 34 |
# File 'lib/cadenza/context/blocks.rb', line 31 def define_block(name, &block) blocks[name.to_sym] = block nil end |
#evaluate_block(name, nodes, parameters) ⇒ String
calls the defined generic block proc with the given name and children nodes.
55 56 57 |
# File 'lib/cadenza/context/blocks.rb', line 55 def evaluate_block(name, nodes, parameters) lookup_block(name).call(self, nodes, parameters) end |
#lookup_block(name) ⇒ Proc
looks up the block by name
19 20 21 |
# File 'lib/cadenza/context/blocks.rb', line 19 def lookup_block(name) blocks.fetch(name.to_sym) { raise BlockNotDefinedError.new("undefined block '#{name}'") } end |