dsl-block-engine 0.0.3

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
data/LICENSE ADDED
@@ -0,0 +1,20 @@
1
+ Copyright (c) 2009 Niclas Nilsson
2
+
3
+ Permission is hereby granted, free of charge, to any person obtaining
4
+ a copy of this software and associated documentation files (the
5
+ "Software"), to deal in the Software without restriction, including
6
+ without limitation the rights to use, copy, modify, merge, publish,
7
+ distribute, sublicense, and/or sell copies of the Software, and to
8
+ permit persons to whom the Software is furnished to do so, subject to
9
+ the following conditions:
10
+
11
+ The above copyright notice and this permission notice shall be
12
+ included in all copies or substantial portions of the Software.
13
+
14
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
15
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
16
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
17
+ NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
18
+ LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
19
+ OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
20
+ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
data/README.rdoc ADDED
@@ -0,0 +1,48 @@
1
+ = dsl-block-engine
2
+
3
+ * http://github.com/#{github_username}/#{project_name}
4
+
5
+ == DESCRIPTION:
6
+
7
+ FIX (describe your package)
8
+
9
+ == FEATURES/PROBLEMS:
10
+
11
+ * FIX (list of features or problems)
12
+
13
+ == SYNOPSIS:
14
+
15
+ FIX (code sample of usage)
16
+
17
+ == REQUIREMENTS:
18
+
19
+ * FIX (list of requirements)
20
+
21
+ == INSTALL:
22
+
23
+ * FIX (sudo gem install, anything else)
24
+
25
+ == LICENSE:
26
+
27
+ (The MIT License)
28
+
29
+ Copyright (c) 2009 Niclas Nilsson
30
+
31
+ Permission is hereby granted, free of charge, to any person obtaining
32
+ a copy of this software and associated documentation files (the
33
+ 'Software'), to deal in the Software without restriction, including
34
+ without limitation the rights to use, copy, modify, merge, publish,
35
+ distribute, sublicense, and/or sell copies of the Software, and to
36
+ permit persons to whom the Software is furnished to do so, subject to
37
+ the following conditions:
38
+
39
+ The above copyright notice and this permission notice shall be
40
+ included in all copies or substantial portions of the Software.
41
+
42
+ THE SOFTWARE IS PROVIDED 'AS IS', WITHOUT WARRANTY OF ANY KIND,
43
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
44
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
45
+ IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
46
+ CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
47
+ TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
48
+ SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
data/Rakefile ADDED
@@ -0,0 +1,62 @@
1
+ require 'rubygems'
2
+
3
+ #$hoe = Hoe.spec 'dsl-block-engine' do
4
+ # self.developer 'Niclas Nilsson', 'niclas@niclasnilsson.se'
5
+ # self.rubyforge_name = self.name # TODO this is default value
6
+ # self.extra_deps = [['activesupport','>= 2.0.2']]
7
+
8
+ #end
9
+
10
+ #require 'newgem/tasks'
11
+ #Dir['tasks/**/*.rake'].each { |t| load t }
12
+
13
+ # TODO - want other tests/tasks run by default? Add them to the list
14
+ # remove_task :default
15
+ # task :default => [:spec, :features]
16
+
17
+ begin
18
+ require 'jeweler'
19
+ Jeweler::Tasks.new do |gemspec|
20
+ gemspec.name = "dsl-block-engine"
21
+ gemspec.summary = "A DSL named block engine"
22
+ gemspec.description = "A gem to ease definition and execution of named blocks, often used in DSLs"
23
+ gemspec.email = "niclas.nilsson@factor10.com"
24
+ gemspec.homepage = "http://github.com/niclasnilsson/dsl-block-engine"
25
+ gemspec.description = "..."
26
+ gemspec.authors = ["Niclas Nilsson"]
27
+ end
28
+ rescue LoadError
29
+ puts "Jeweler not available. Install it with: sudo gem install technicalpickles-jeweler -s http://gems.github.com"
30
+ end
31
+
32
+ task :default => :spec
33
+
34
+ require 'spec/rake/spectask'
35
+ Spec::Rake::SpecTask.new(:spec) do |spec|
36
+ spec.libs << 'lib' << 'spec'
37
+ spec.spec_files = FileList['spec/**/*_spec.rb']
38
+ end
39
+
40
+ Spec::Rake::SpecTask.new(:rcov) do |spec|
41
+ spec.libs << 'lib' << 'spec'
42
+ spec.pattern = 'spec/**/*_spec.rb'
43
+ spec.rcov = true
44
+ end
45
+
46
+ task :spec => :check_dependencies
47
+
48
+ task :default => :spec
49
+
50
+ require 'rake/rdoctask'
51
+ Rake::RDocTask.new do |rdoc|
52
+ if File.exist?('VERSION')
53
+ version = File.read('VERSION')
54
+ else
55
+ version = ""
56
+ end
57
+
58
+ rdoc.rdoc_dir = 'rdoc'
59
+ rdoc.title = "foogem #{version}"
60
+ rdoc.rdoc_files.include('README*')
61
+ rdoc.rdoc_files.include('lib/**/*.rb')
62
+ end
@@ -0,0 +1,47 @@
1
+ # Generated by jeweler
2
+ # DO NOT EDIT THIS FILE
3
+ # Instead, edit Jeweler::Tasks in Rakefile, and run `rake gemspec`
4
+ # -*- encoding: utf-8 -*-
5
+
6
+ Gem::Specification.new do |s|
7
+ s.name = %q{dsl-block-engine}
8
+ s.version = "0.0.3"
9
+
10
+ s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
11
+ s.authors = ["Niclas Nilsson"]
12
+ s.date = %q{2009-10-05}
13
+ s.description = %q{...}
14
+ s.email = %q{niclas.nilsson@factor10.com}
15
+ s.extra_rdoc_files = [
16
+ "LICENSE",
17
+ "README.rdoc"
18
+ ]
19
+ s.files = [
20
+ "README.rdoc",
21
+ "Rakefile",
22
+ "dsl-block-engine.gemspec",
23
+ "lib/dsl-block-engine.rb",
24
+ "spec/dsl-block-engine_spec.rb",
25
+ "spec/spec.opts",
26
+ "spec/spec_helper.rb"
27
+ ]
28
+ s.homepage = %q{http://github.com/niclasnilsson/dsl-block-engine}
29
+ s.rdoc_options = ["--charset=UTF-8"]
30
+ s.require_paths = ["lib"]
31
+ s.rubygems_version = %q{1.3.5}
32
+ s.summary = %q{A DSL named block engine}
33
+ s.test_files = [
34
+ "spec/dsl-block-engine_spec.rb",
35
+ "spec/spec_helper.rb"
36
+ ]
37
+
38
+ if s.respond_to? :specification_version then
39
+ current_version = Gem::Specification::CURRENT_SPECIFICATION_VERSION
40
+ s.specification_version = 3
41
+
42
+ if Gem::Version.new(Gem::RubyGemsVersion) >= Gem::Version.new('1.2.0') then
43
+ else
44
+ end
45
+ else
46
+ end
47
+ end
@@ -0,0 +1,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
+ attrs.each do |attr|
34
+ o.class.send :attr_accessor, attr
35
+ end
36
+ o
37
+ end
38
+
39
+ def execute_in_context ctx, category, event
40
+ b = @blocks[category][event]
41
+ ctx.instance_eval &b
42
+ end
43
+
44
+ def method_missing name, *args, &block
45
+ category = name
46
+ event = args[0]
47
+ super.method_missing(name, args, &block) unless @categories.include? category
48
+ @blocks[category] ||= {}
49
+ @blocks[category][event] = block
50
+ end
51
+
52
+ end
53
+
54
+ end
@@ -0,0 +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
+
data/spec/spec.opts ADDED
@@ -0,0 +1 @@
1
+ --colour
@@ -0,0 +1,9 @@
1
+ $LOAD_PATH.unshift(File.dirname(__FILE__))
2
+ $LOAD_PATH.unshift(File.join(File.dirname(__FILE__), '..', 'lib'))
3
+ require 'dsl-block-engine'
4
+ require 'spec'
5
+ require 'spec/autorun'
6
+
7
+ Spec::Runner.configure do |config|
8
+
9
+ end
metadata ADDED
@@ -0,0 +1,64 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: dsl-block-engine
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.3
5
+ platform: ruby
6
+ authors:
7
+ - Niclas Nilsson
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+
12
+ date: 2009-10-05 00:00:00 +02:00
13
+ default_executable:
14
+ dependencies: []
15
+
16
+ description: ...
17
+ email: niclas.nilsson@factor10.com
18
+ executables: []
19
+
20
+ extensions: []
21
+
22
+ extra_rdoc_files:
23
+ - LICENSE
24
+ - README.rdoc
25
+ files:
26
+ - README.rdoc
27
+ - Rakefile
28
+ - dsl-block-engine.gemspec
29
+ - lib/dsl-block-engine.rb
30
+ - spec/dsl-block-engine_spec.rb
31
+ - spec/spec.opts
32
+ - spec/spec_helper.rb
33
+ - LICENSE
34
+ has_rdoc: true
35
+ homepage: http://github.com/niclasnilsson/dsl-block-engine
36
+ licenses: []
37
+
38
+ post_install_message:
39
+ rdoc_options:
40
+ - --charset=UTF-8
41
+ require_paths:
42
+ - lib
43
+ required_ruby_version: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - ">="
46
+ - !ruby/object:Gem::Version
47
+ version: "0"
48
+ version:
49
+ required_rubygems_version: !ruby/object:Gem::Requirement
50
+ requirements:
51
+ - - ">="
52
+ - !ruby/object:Gem::Version
53
+ version: "0"
54
+ version:
55
+ requirements: []
56
+
57
+ rubyforge_project:
58
+ rubygems_version: 1.3.5
59
+ signing_key:
60
+ specification_version: 3
61
+ summary: A DSL named block engine
62
+ test_files:
63
+ - spec/dsl-block-engine_spec.rb
64
+ - spec/spec_helper.rb