Class: Lustr::ParseContext
- Inherits:
-
Object
- Object
- Lustr::ParseContext
- Defined in:
- lib/lustr/parse_context.rb
Instance Attribute Summary collapse
-
#gadget_builders ⇒ Object
readonly
Returns the value of attribute gadget_builders.
Instance Method Summary collapse
- #add_builder(name, options) ⇒ Object
- #attach_builder(builder, name = nil) ⇒ Object
- #current_builder ⇒ Object
- #handle_event(name, callable) ⇒ Object
-
#initialize ⇒ ParseContext
constructor
A new instance of ParseContext.
Constructor Details
#initialize ⇒ ParseContext
Returns a new instance of ParseContext.
20 21 22 23 24 25 26 |
# File 'lib/lustr/parse_context.rb', line 20 def initialize @gadget_builders={} @builder_stack=[] builder=GadgetBuilder.new gadget_builders[nil]=builder @builder_stack.push builder end |
Instance Attribute Details
#gadget_builders ⇒ Object (readonly)
Returns the value of attribute gadget_builders.
18 19 20 |
# File 'lib/lustr/parse_context.rb', line 18 def gadget_builders @gadget_builders end |
Instance Method Details
#add_builder(name, options) ⇒ Object
32 33 34 35 36 37 38 39 40 41 42 43 44 |
# File 'lib/lustr/parse_context.rb', line 32 def add_builder(name, ) current=current_builder builder_klass=Lustr.get_builder_klass(name) if builder_klass.kind_of?(Class) child=builder_klass.new() else child=builder_klass.dup_from() end current << child attach_builder(child) { yield if block_given? } end |
#attach_builder(builder, name = nil) ⇒ Object
46 47 48 49 50 51 |
# File 'lib/lustr/parse_context.rb', line 46 def attach_builder(builder, name=nil) @builder_stack.push builder gadget_builders[name]=builder if name && builder.kind_of?(GadgetBuilder) yield if block_given? @builder_stack.pop end |
#current_builder ⇒ Object
28 29 30 |
# File 'lib/lustr/parse_context.rb', line 28 def current_builder @builder_stack.last end |
#handle_event(name, callable) ⇒ Object
53 54 55 |
# File 'lib/lustr/parse_context.rb', line 53 def handle_event(name, callable) current_builder.event_handlers[name]=callable end |