Class: DslBlockEngine::DslBlockEngine
- Inherits:
-
Object
- Object
- DslBlockEngine::DslBlockEngine
show all
- Defined in:
- lib/dsl-block-engine.rb
Instance Attribute Summary collapse
Instance Method Summary
collapse
Constructor Details
Returns a new instance of DslBlockEngine.
18
19
20
21
|
# File 'lib/dsl-block-engine.rb', line 18
def initialize
@blocks = {}
@categories = []
end
|
Dynamic Method Handling
This class handles dynamic methods through the method_missing method
#method_missing(name, *args, &block) ⇒ Object
44
45
46
47
48
49
50
|
# File 'lib/dsl-block-engine.rb', line 44
def method_missing name, *args, &block
category = name
event = args[0]
super.method_missing(name, args, &block) unless @categories.include? category
@blocks[category] ||= {}
@blocks[category][event] = block
end
|
Instance Attribute Details
#categories ⇒ Object
Returns the value of attribute categories.
16
17
18
|
# File 'lib/dsl-block-engine.rb', line 16
def categories
@categories
end
|
Instance Method Details
#blocks ⇒ Object
27
28
29
|
# File 'lib/dsl-block-engine.rb', line 27
def blocks
@blocks
end
|
#create_context(*attrs) ⇒ Object
31
32
33
34
35
36
37
|
# File 'lib/dsl-block-engine.rb', line 31
def create_context *attrs
o = Object.new
attrs.each do |attr|
o.class.send :attr_accessor, attr
end
o
end
|
#execute_in_context(ctx, category, event) ⇒ Object
39
40
41
42
|
# File 'lib/dsl-block-engine.rb', line 39
def execute_in_context ctx, category, event
b = @blocks[category][event]
ctx.instance_eval &b
end
|
#load(code) ⇒ Object
23
24
25
|
# File 'lib/dsl-block-engine.rb', line 23
def load code
self.instance_eval code
end
|