drewolson-block-chainable 0.1.1

Sign up to get free protection for your applications and to get access to all the features.
@@ -0,0 +1,27 @@
1
+ === 0.1.1 / 2008-05-23
2
+
3
+ * 1 minor enhancement
4
+ * Classes instantiated through blocks (using start) return the result of executing the block
5
+
6
+ === 0.1.0 / 2008-04-08
7
+
8
+ * 1 major enhancement
9
+ * Methods with implicit blocks with be propagated correctly to parent scopes
10
+
11
+ === 0.0.3 / 2008-03-27
12
+
13
+ * 1 minor enhancement
14
+ * Classes inheriting from a parent class that mixes in BlockChainable will gain all functionality
15
+
16
+ === 0.0.2 / 2008-03-07
17
+
18
+ * 1 minor enhancement
19
+ * Classes instantiated through blocks (using start) return the instance of the class for chaining
20
+
21
+ === 0.0.1 / 2008-02-24
22
+
23
+ * 2 major enhancements
24
+ * Block instantiation of classes
25
+ * Method calls within block instantiated classes can jump "up-scope" to parent classes
26
+ * 1 minor bug
27
+ * Stack trace on errors should be simplified
@@ -0,0 +1,15 @@
1
+ History.txt
2
+ Manifest.txt
3
+ README.txt
4
+ Rakefile
5
+ example/roster.rb
6
+ example/roster_dsl.rb
7
+ example/student.rb
8
+ lib/block_chainable.rb
9
+ spec/bar.rb
10
+ spec/block_chainable_spec.rb
11
+ spec/foo.rb
12
+ test/bar.rb
13
+ test/baz.rb
14
+ test/foo.rb
15
+ test/test_block_chainable.rb
@@ -0,0 +1,26 @@
1
+ # -*- ruby -*-
2
+
3
+ require 'rubygems'
4
+ require 'hoe'
5
+ require 'need'
6
+ require 'spec/rake/spectask'
7
+ need{'./lib/block_chainable.rb'}
8
+
9
+ Hoe.new('block-chainable', '0.1.1') do |p|
10
+ p.rubyforge_name = 'block-chainable'
11
+ p.author = 'Drew Olson'
12
+ p.email = 'drew@drewolson.org'
13
+ p.summary = 'tool for building DSLs with blocks'
14
+ p.description = p.paragraphs_of('README.txt', 2..5).join("\n\n")
15
+ p.url = "http://block-chainable.rubyforge.org"
16
+ p.changes = p.paragraphs_of('History.txt', 0..1).join("\n\n")
17
+ p.extra_deps << ['need', '>= 1.0.1']
18
+ p.extra_deps << ['rspec', '>= 1.1.3']
19
+ p.remote_rdoc_dir = ''
20
+ end
21
+
22
+ Spec::Rake::SpecTask.new do |t|
23
+ t.warning = true
24
+ end
25
+
26
+ # vim: syntax=Ruby
@@ -0,0 +1,21 @@
1
+ require 'rubygems'
2
+ require 'need'
3
+ need{"../lib/block_chainable"}
4
+
5
+ class Roster
6
+ include BlockChainable
7
+
8
+ def initialize(subject)
9
+ @subject = subject
10
+ @students = []
11
+ end
12
+
13
+ def add_student_to_class student
14
+ @students << student
15
+ end
16
+
17
+ def print_roster
18
+ puts "Roster for #{@subject}:"
19
+ @students.each{|s| puts " #{s}"}
20
+ end
21
+ end
@@ -0,0 +1,32 @@
1
+ require 'rubygems'
2
+ require 'need'
3
+ need{"roster"}
4
+ need{"student"}
5
+
6
+ Roster :Math do
7
+ Student do
8
+ first_name "Drew"
9
+ last_name "Olson"
10
+ age 25
11
+
12
+ add_to_roster
13
+ end
14
+
15
+ Student do
16
+ first_name "John"
17
+ last_name "Doe"
18
+ age 17
19
+
20
+ add_to_roster
21
+ end
22
+
23
+ Student do
24
+ first_name "Jane"
25
+ last_name "Doe"
26
+ age 19
27
+
28
+ add_to_roster
29
+ end
30
+
31
+ print_roster
32
+ end
@@ -0,0 +1,27 @@
1
+ require 'rubygems'
2
+ require 'need'
3
+ need{"../lib/block_chainable"}
4
+
5
+ class Student
6
+ include BlockChainable
7
+
8
+ def add_to_roster
9
+ add_student_to_class self
10
+ end
11
+
12
+ def to_s
13
+ "#{@last_name}, #{@first_name} - age #{@age}"
14
+ end
15
+
16
+ def first_name name
17
+ @first_name = name
18
+ end
19
+
20
+ def last_name name
21
+ @last_name = name
22
+ end
23
+
24
+ def age years
25
+ @age = years
26
+ end
27
+ end
@@ -0,0 +1,42 @@
1
+ module BlockChainable
2
+ module ClassMethods
3
+ def start(*args,&block)
4
+ klass_instance = self.new(*args)
5
+
6
+ klass_instance.instance_variable_set("@__parent",eval("self",block))
7
+
8
+ class << klass_instance
9
+ def method_missing(name,*args,&block)
10
+ if chain_respond_to?(name)
11
+ @__parent.send(name,*args,&block)
12
+ else
13
+ super
14
+ end
15
+ end
16
+ end
17
+
18
+ klass_instance.instance_eval(&block)
19
+ end
20
+
21
+ def inherited(klass)
22
+ klass.class_eval{include BlockChainable}
23
+ end
24
+ end
25
+
26
+ def self.included(klass)
27
+ klass.extend(ClassMethods)
28
+
29
+ Object.class_eval <<-EOS
30
+ def #{klass}(*args,&block)
31
+ #{klass}.start(*args,&block)
32
+ end
33
+ EOS
34
+ end
35
+
36
+ def chain_respond_to?(name)
37
+ self.respond_to?(name) ||
38
+ (@__parent &&
39
+ (@__parent.respond_to?(name) ||
40
+ (@__parent.respond_to?(:chain_respond_to?) && @__parent.chain_respond_to?(name))))
41
+ end
42
+ end
@@ -0,0 +1,11 @@
1
+ require 'rubygems'
2
+ require 'need'
3
+ need{"../lib/block_chainable"}
4
+
5
+ class Bar
6
+ include BlockChainable
7
+
8
+ def is_bar?
9
+ true
10
+ end
11
+ end
@@ -0,0 +1,38 @@
1
+ require 'rubygems'
2
+ require 'need'
3
+ need{"foo"}
4
+ need{"bar"}
5
+
6
+ describe "test block chainable" do
7
+ it "should work on standard method calls" do
8
+ Foo do
9
+ is_foo?.should == true
10
+ end
11
+ end
12
+
13
+ it "should work for standard method calls on nested blocks" do
14
+ Foo do
15
+ Bar do
16
+ is_bar?.should == true
17
+ end
18
+ end
19
+ end
20
+
21
+ it "it should allow calls to outer block methods from inner blocks" do
22
+ Foo do
23
+ Bar do
24
+ is_foo?.should == true
25
+ end
26
+ end
27
+ end
28
+
29
+ it "should not allow method calls to inner blocks from outer blocks" do
30
+ lambda do
31
+ Foo do
32
+ is_bar?
33
+ Bar do
34
+ end
35
+ end
36
+ end.should raise_error(NoMethodError)
37
+ end
38
+ end
@@ -0,0 +1,11 @@
1
+ require 'rubygems'
2
+ require 'need'
3
+ need{"../lib/block_chainable"}
4
+
5
+ class Foo
6
+ include BlockChainable
7
+
8
+ def is_foo?
9
+ true
10
+ end
11
+ end
@@ -0,0 +1,11 @@
1
+ require 'rubygems'
2
+ require 'need'
3
+ need{"../lib/block_chainable"}
4
+
5
+ class Bar
6
+ include BlockChainable
7
+
8
+ def is_bar?
9
+ true
10
+ end
11
+ end
@@ -0,0 +1,9 @@
1
+ require 'rubygems'
2
+ require 'need'
3
+ need{'foo'}
4
+
5
+ class Baz < Foo
6
+ def is_baz?
7
+ true
8
+ end
9
+ end
@@ -0,0 +1,15 @@
1
+ require 'rubygems'
2
+ require 'need'
3
+ need{"../lib/block_chainable"}
4
+
5
+ class Foo
6
+ include BlockChainable
7
+
8
+ def is_foo?
9
+ true
10
+ end
11
+
12
+ def call_block &block
13
+ block.call
14
+ end
15
+ end
@@ -0,0 +1,55 @@
1
+ require 'rubygems'
2
+ require 'need'
3
+ need{"foo"}
4
+ need{"bar"}
5
+ need{"baz"}
6
+
7
+ require "test/unit"
8
+
9
+ class TestBlockChainable < Test::Unit::TestCase
10
+ def test_standard_method_call
11
+ Foo do
12
+ assert is_foo?
13
+ end
14
+ end
15
+
16
+ def test_standard_method_call_inner_block
17
+ Foo do
18
+ Bar do
19
+ assert is_bar?
20
+ end
21
+ end
22
+ end
23
+
24
+ def test_outer_block_method_call_from_inner_block
25
+ Foo do
26
+ Bar do
27
+ assert is_foo?
28
+ end
29
+ end
30
+ end
31
+
32
+ def test_inner_block_method_call_from_outer_block_fails
33
+ assert_raises NoMethodError do
34
+ Foo do
35
+ is_bar?
36
+ Bar do
37
+ end
38
+ end
39
+ end
40
+ end
41
+
42
+ def test_block_chainable_works_with_inheritance
43
+ Baz do
44
+ assert is_baz?
45
+ end
46
+ end
47
+
48
+ def test_method_with_block_in_parent_scope
49
+ Foo do
50
+ Bar do
51
+ assert(call_block{true})
52
+ end
53
+ end
54
+ end
55
+ end
metadata ADDED
@@ -0,0 +1,96 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: drewolson-block-chainable
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.1
5
+ platform: ruby
6
+ authors:
7
+ - Drew Olson
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+
12
+ date: 2008-12-02 00:00:00 -08:00
13
+ default_executable:
14
+ dependencies:
15
+ - !ruby/object:Gem::Dependency
16
+ name: need
17
+ version_requirement:
18
+ version_requirements: !ruby/object:Gem::Requirement
19
+ requirements:
20
+ - - ">="
21
+ - !ruby/object:Gem::Version
22
+ version: 1.0.1
23
+ version:
24
+ - !ruby/object:Gem::Dependency
25
+ name: rspec
26
+ version_requirement:
27
+ version_requirements: !ruby/object:Gem::Requirement
28
+ requirements:
29
+ - - ">="
30
+ - !ruby/object:Gem::Version
31
+ version: 1.1.3
32
+ version:
33
+ - !ruby/object:Gem::Dependency
34
+ name: hoe
35
+ version_requirement:
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - ">="
39
+ - !ruby/object:Gem::Version
40
+ version: 1.8.2
41
+ version:
42
+ description: "== DESCRIPTION: BlockChainable is a module to aid in the creation of Domain Specific Languages using block structure. By including BlockChainable into your classes, you will be able to instantiate that class using the class name itself, followed by any parameters to be passed to initialize, followed by a block to be executed within the instantiated class. BlockChainable also allows methods to search up the chain of classes, meaning that although a block is executed in the scope of the instantiated class, any methods not found in the class but found in a class \"up-scope\" will be called successfully on the up-scope class. This chaining of method calls allows you to assert values within the blocks as well as calling any other methods from \"up-scope\" classes. == FEATURES/PROBLEMS:"
43
+ email: drew@drewolson.org
44
+ executables: []
45
+
46
+ extensions: []
47
+
48
+ extra_rdoc_files:
49
+ - History.txt
50
+ - Manifest.txt
51
+ - README.txt
52
+ files:
53
+ - History.txt
54
+ - Manifest.txt
55
+ - README.txt
56
+ - Rakefile
57
+ - example/roster.rb
58
+ - example/roster_dsl.rb
59
+ - example/student.rb
60
+ - lib/block_chainable.rb
61
+ - spec/bar.rb
62
+ - spec/block_chainable_spec.rb
63
+ - spec/foo.rb
64
+ - test/bar.rb
65
+ - test/baz.rb
66
+ - test/foo.rb
67
+ - test/test_block_chainable.rb
68
+ has_rdoc: true
69
+ homepage: http://block-chainable.rubyforge.org
70
+ post_install_message:
71
+ rdoc_options:
72
+ - --main
73
+ - README.txt
74
+ require_paths:
75
+ - lib
76
+ required_ruby_version: !ruby/object:Gem::Requirement
77
+ requirements:
78
+ - - ">="
79
+ - !ruby/object:Gem::Version
80
+ version: "0"
81
+ version:
82
+ required_rubygems_version: !ruby/object:Gem::Requirement
83
+ requirements:
84
+ - - ">="
85
+ - !ruby/object:Gem::Version
86
+ version: "0"
87
+ version:
88
+ requirements: []
89
+
90
+ rubyforge_project: block-chainable
91
+ rubygems_version: 1.2.0
92
+ signing_key:
93
+ specification_version: 2
94
+ summary: tool for building DSLs with blocks
95
+ test_files:
96
+ - test/test_block_chainable.rb