dsl-block-engine 0.0.3 → 0.1.0
Sign up to get free protection for your applications and to get access to all the features.
- data/.gitignore +1 -0
- data/VERSION +1 -0
- data/dsl-block-engine.gemspec +6 -3
- data/lib/dsl-block-engine.rb +60 -54
- data/spec/dsl-block-engine_spec.rb +64 -64
- metadata +5 -3
data/.gitignore
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
pkg
|
data/VERSION
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
0.1.0
|
data/dsl-block-engine.gemspec
CHANGED
@@ -5,11 +5,11 @@
|
|
5
5
|
|
6
6
|
Gem::Specification.new do |s|
|
7
7
|
s.name = %q{dsl-block-engine}
|
8
|
-
s.version = "0.0
|
8
|
+
s.version = "0.1.0"
|
9
9
|
|
10
10
|
s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
|
11
11
|
s.authors = ["Niclas Nilsson"]
|
12
|
-
s.date = %q{2009-10-
|
12
|
+
s.date = %q{2009-10-06}
|
13
13
|
s.description = %q{...}
|
14
14
|
s.email = %q{niclas.nilsson@factor10.com}
|
15
15
|
s.extra_rdoc_files = [
|
@@ -17,8 +17,11 @@ Gem::Specification.new do |s|
|
|
17
17
|
"README.rdoc"
|
18
18
|
]
|
19
19
|
s.files = [
|
20
|
-
"
|
20
|
+
".gitignore",
|
21
|
+
"LICENSE",
|
22
|
+
"README.rdoc",
|
21
23
|
"Rakefile",
|
24
|
+
"VERSION",
|
22
25
|
"dsl-block-engine.gemspec",
|
23
26
|
"lib/dsl-block-engine.rb",
|
24
27
|
"spec/dsl-block-engine_spec.rb",
|
data/lib/dsl-block-engine.rb
CHANGED
@@ -1,54 +1,60 @@
|
|
1
|
-
$:.unshift(File.dirname(__FILE__)) unless
|
2
|
-
$:.include?(File.dirname(__FILE__)) || $:.include?(File.expand_path(File.dirname(__FILE__)))
|
3
|
-
|
4
|
-
module DslBlockEngine
|
5
|
-
VERSION = '0.0.4'
|
6
|
-
|
7
|
-
class Context
|
8
|
-
def attr_accessor *names
|
9
|
-
names.each do |name|
|
10
|
-
self.class.send :attr_accessor, name
|
11
|
-
end
|
12
|
-
end
|
13
|
-
end
|
14
|
-
|
15
|
-
class DslBlockEngine
|
16
|
-
attr_accessor :categories
|
17
|
-
|
18
|
-
def initialize
|
19
|
-
@blocks = {}
|
20
|
-
@categories = []
|
21
|
-
end
|
22
|
-
|
23
|
-
def load code
|
24
|
-
self.instance_eval code
|
25
|
-
end
|
26
|
-
|
27
|
-
def blocks
|
28
|
-
@blocks
|
29
|
-
end
|
30
|
-
|
31
|
-
def create_context *attrs
|
32
|
-
o = Object.new
|
33
|
-
|
34
|
-
|
35
|
-
|
36
|
-
|
37
|
-
|
38
|
-
|
39
|
-
|
40
|
-
|
41
|
-
|
42
|
-
|
43
|
-
|
44
|
-
|
45
|
-
|
46
|
-
|
47
|
-
|
48
|
-
|
49
|
-
|
50
|
-
|
51
|
-
|
52
|
-
|
53
|
-
|
54
|
-
|
1
|
+
$:.unshift(File.dirname(__FILE__)) unless
|
2
|
+
$:.include?(File.dirname(__FILE__)) || $:.include?(File.expand_path(File.dirname(__FILE__)))
|
3
|
+
|
4
|
+
module DslBlockEngine
|
5
|
+
VERSION = '0.0.4'
|
6
|
+
|
7
|
+
class Context
|
8
|
+
def attr_accessor *names
|
9
|
+
names.each do |name|
|
10
|
+
self.class.send :attr_accessor, name
|
11
|
+
end
|
12
|
+
end
|
13
|
+
end
|
14
|
+
|
15
|
+
class DslBlockEngine
|
16
|
+
attr_accessor :categories
|
17
|
+
|
18
|
+
def initialize
|
19
|
+
@blocks = {}
|
20
|
+
@categories = []
|
21
|
+
end
|
22
|
+
|
23
|
+
def load code
|
24
|
+
self.instance_eval code
|
25
|
+
end
|
26
|
+
|
27
|
+
def blocks
|
28
|
+
@blocks
|
29
|
+
end
|
30
|
+
|
31
|
+
def create_context *attrs
|
32
|
+
o = Object.new
|
33
|
+
|
34
|
+
def o.add_attribute name
|
35
|
+
self.class.send :attr_accessor, name
|
36
|
+
end
|
37
|
+
|
38
|
+
attrs.each do |attr|
|
39
|
+
o.add_attribute attr
|
40
|
+
end
|
41
|
+
|
42
|
+
o
|
43
|
+
end
|
44
|
+
|
45
|
+
def execute_in_context ctx, category, event
|
46
|
+
b = @blocks[category][event]
|
47
|
+
ctx.instance_eval &b
|
48
|
+
end
|
49
|
+
|
50
|
+
def method_missing name, *args, &block
|
51
|
+
category = name
|
52
|
+
event = args[0]
|
53
|
+
super.method_missing(name, args, &block) unless @categories.include? category
|
54
|
+
@blocks[category] ||= {}
|
55
|
+
@blocks[category][event] = block
|
56
|
+
end
|
57
|
+
|
58
|
+
end
|
59
|
+
|
60
|
+
end
|
@@ -1,64 +1,64 @@
|
|
1
|
-
require File.dirname(__FILE__) + '/spec_helper.rb'
|
2
|
-
|
3
|
-
describe DslBlockEngine do
|
4
|
-
|
5
|
-
before do
|
6
|
-
@engine = DslBlockEngine::DslBlockEngine.new
|
7
|
-
end
|
8
|
-
|
9
|
-
it "should load named blocks" do
|
10
|
-
code = %q{
|
11
|
-
on :event1 do
|
12
|
-
end
|
13
|
-
|
14
|
-
on :event2 do
|
15
|
-
end
|
16
|
-
}
|
17
|
-
|
18
|
-
@engine.categories = [:on]
|
19
|
-
@engine.load code
|
20
|
-
@engine.blocks[:on].size.should == 2
|
21
|
-
end
|
22
|
-
|
23
|
-
it "should provide properties accessible for the block" do
|
24
|
-
code = %q{
|
25
|
-
on :event1 do
|
26
|
-
a + b
|
27
|
-
end
|
28
|
-
}
|
29
|
-
|
30
|
-
@engine.categories = [:on]
|
31
|
-
@engine.load code
|
32
|
-
context = @engine.create_context :a, :b
|
33
|
-
|
34
|
-
context.a = 2
|
35
|
-
context.b = 4
|
36
|
-
|
37
|
-
result = @engine.execute_in_context context, :on, :event1
|
38
|
-
result.should == 6
|
39
|
-
end
|
40
|
-
|
41
|
-
it "should support different names for the categories" do
|
42
|
-
code = %q{
|
43
|
-
before :event1 do
|
44
|
-
end
|
45
|
-
|
46
|
-
on :event1 do
|
47
|
-
end
|
48
|
-
|
49
|
-
on :event2 do
|
50
|
-
end
|
51
|
-
|
52
|
-
after :event2 do
|
53
|
-
end
|
54
|
-
}
|
55
|
-
|
56
|
-
@engine.categories = [:before, :on, :after]
|
57
|
-
@engine.load code
|
58
|
-
@engine.blocks[:before].size.should == 1
|
59
|
-
@engine.blocks[:on].size.should == 2
|
60
|
-
@engine.blocks[:after].size.should == 1
|
61
|
-
end
|
62
|
-
|
63
|
-
end
|
64
|
-
|
1
|
+
require File.dirname(__FILE__) + '/spec_helper.rb'
|
2
|
+
|
3
|
+
describe DslBlockEngine do
|
4
|
+
|
5
|
+
before do
|
6
|
+
@engine = DslBlockEngine::DslBlockEngine.new
|
7
|
+
end
|
8
|
+
|
9
|
+
it "should load named blocks" do
|
10
|
+
code = %q{
|
11
|
+
on :event1 do
|
12
|
+
end
|
13
|
+
|
14
|
+
on :event2 do
|
15
|
+
end
|
16
|
+
}
|
17
|
+
|
18
|
+
@engine.categories = [:on]
|
19
|
+
@engine.load code
|
20
|
+
@engine.blocks[:on].size.should == 2
|
21
|
+
end
|
22
|
+
|
23
|
+
it "should provide properties accessible for the block" do
|
24
|
+
code = %q{
|
25
|
+
on :event1 do
|
26
|
+
a + b
|
27
|
+
end
|
28
|
+
}
|
29
|
+
|
30
|
+
@engine.categories = [:on]
|
31
|
+
@engine.load code
|
32
|
+
context = @engine.create_context :a, :b
|
33
|
+
|
34
|
+
context.a = 2
|
35
|
+
context.b = 4
|
36
|
+
|
37
|
+
result = @engine.execute_in_context context, :on, :event1
|
38
|
+
result.should == 6
|
39
|
+
end
|
40
|
+
|
41
|
+
it "should support different names for the categories" do
|
42
|
+
code = %q{
|
43
|
+
before :event1 do
|
44
|
+
end
|
45
|
+
|
46
|
+
on :event1 do
|
47
|
+
end
|
48
|
+
|
49
|
+
on :event2 do
|
50
|
+
end
|
51
|
+
|
52
|
+
after :event2 do
|
53
|
+
end
|
54
|
+
}
|
55
|
+
|
56
|
+
@engine.categories = [:before, :on, :after]
|
57
|
+
@engine.load code
|
58
|
+
@engine.blocks[:before].size.should == 1
|
59
|
+
@engine.blocks[:on].size.should == 2
|
60
|
+
@engine.blocks[:after].size.should == 1
|
61
|
+
end
|
62
|
+
|
63
|
+
end
|
64
|
+
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: dsl-block-engine
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0
|
4
|
+
version: 0.1.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Niclas Nilsson
|
@@ -9,7 +9,7 @@ autorequire:
|
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
11
|
|
12
|
-
date: 2009-10-
|
12
|
+
date: 2009-10-06 00:00:00 +02:00
|
13
13
|
default_executable:
|
14
14
|
dependencies: []
|
15
15
|
|
@@ -23,14 +23,16 @@ extra_rdoc_files:
|
|
23
23
|
- LICENSE
|
24
24
|
- README.rdoc
|
25
25
|
files:
|
26
|
+
- .gitignore
|
27
|
+
- LICENSE
|
26
28
|
- README.rdoc
|
27
29
|
- Rakefile
|
30
|
+
- VERSION
|
28
31
|
- dsl-block-engine.gemspec
|
29
32
|
- lib/dsl-block-engine.rb
|
30
33
|
- spec/dsl-block-engine_spec.rb
|
31
34
|
- spec/spec.opts
|
32
35
|
- spec/spec_helper.rb
|
33
|
-
- LICENSE
|
34
36
|
has_rdoc: true
|
35
37
|
homepage: http://github.com/niclasnilsson/dsl-block-engine
|
36
38
|
licenses: []
|