block-chainable 0.0.2 → 0.0.3

Sign up to get free protection for your applications and to get access to all the features.
data/History.txt CHANGED
@@ -1,4 +1,9 @@
1
- === 0.0.1 / 2008-03-07
1
+ === 0.0.3 / 2008-03-27
2
+
3
+ * 1 minor enhancement
4
+ * Classes inheriting from a parent class that mixes in BlockChainable will gain all functionality
5
+
6
+ === 0.0.2 / 2008-03-07
2
7
 
3
8
  * 1 minor enhancement
4
9
  * Classes instantiated through blocks (using start) return the instance of the class for chaining
data/Manifest.txt CHANGED
@@ -2,6 +2,14 @@ History.txt
2
2
  Manifest.txt
3
3
  README.txt
4
4
  Rakefile
5
+ example/roster.rb
6
+ example/roster_dsl.rb
7
+ example/student.rb
5
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
6
15
  test/test_block_chainable.rb
7
- spec/block_chainable_spec.rb
data/README.txt CHANGED
@@ -18,7 +18,7 @@ you to assert values within the blocks as well as calling any other methods from
18
18
 
19
19
  * 2 major features
20
20
  * Block instantiation of classes
21
- * Method calls will look "up-scope" for receives when called inside BlockChainable blocks
21
+ * Method calls will look "up-scope" for receivers when called inside BlockChainable blocks
22
22
  * 1 minor problem
23
23
  * Stack trace should be simplified on errors within BlockChainable blocks
24
24
 
data/Rakefile CHANGED
@@ -6,7 +6,7 @@ require 'need'
6
6
  require 'spec/rake/spectask'
7
7
  need{'./lib/block_chainable.rb'}
8
8
 
9
- Hoe.new('block-chainable', '0.0.2') do |p|
9
+ Hoe.new('block-chainable', '0.0.3') do |p|
10
10
  p.rubyforge_name = 'block-chainable'
11
11
  p.author = 'Drew Olson'
12
12
  p.email = 'olsonas@gmail.com'
data/example/roster.rb ADDED
@@ -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
@@ -3,16 +3,14 @@ module BlockChainable
3
3
  def start(*args,&block)
4
4
  klass_instance = self.new(*args)
5
5
 
6
- klass_instance.instance_eval do
7
- @__parent = eval("self",block.binding)
8
- end
6
+ klass_instance.instance_variable_set("@__parent",eval("self",block))
9
7
 
10
8
  class << klass_instance
11
9
  def method_missing(name,*args)
12
10
  if chain_respond_to?(name)
13
11
  @__parent.send(name,*args)
14
12
  else
15
- super(name,*args)
13
+ super
16
14
  end
17
15
  end
18
16
  end
@@ -21,6 +19,10 @@ module BlockChainable
21
19
 
22
20
  klass_instance
23
21
  end
22
+
23
+ def inherited klass
24
+ klass.class_eval{include BlockChainable}
25
+ end
24
26
  end
25
27
 
26
28
  def self.included(klass)
data/spec/bar.rb ADDED
@@ -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
data/spec/foo.rb ADDED
@@ -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
data/test/bar.rb ADDED
@@ -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
data/test/baz.rb ADDED
@@ -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
data/test/foo.rb ADDED
@@ -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
@@ -2,6 +2,7 @@ require 'rubygems'
2
2
  require 'need'
3
3
  need{"foo"}
4
4
  need{"bar"}
5
+ need{"baz"}
5
6
 
6
7
  require "test/unit"
7
8
 
@@ -37,4 +38,10 @@ class TestBlockChainable < Test::Unit::TestCase
37
38
  end
38
39
  end
39
40
  end
41
+
42
+ def test_block_chainable_works_with_inheritance
43
+ Baz do
44
+ assert is_baz?
45
+ end
46
+ end
40
47
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: block-chainable
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.2
4
+ version: 0.0.3
5
5
  platform: ruby
6
6
  authors:
7
7
  - Drew Olson
@@ -9,7 +9,7 @@ autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
11
 
12
- date: 2008-03-07 00:00:00 -06:00
12
+ date: 2008-03-27 00:00:00 -07:00
13
13
  default_executable:
14
14
  dependencies:
15
15
  - !ruby/object:Gem::Dependency
@@ -37,7 +37,7 @@ dependencies:
37
37
  requirements:
38
38
  - - ">="
39
39
  - !ruby/object:Gem::Version
40
- version: 1.5.0
40
+ version: 1.5.1
41
41
  version:
42
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
43
  email: olsonas@gmail.com
@@ -54,9 +54,17 @@ files:
54
54
  - Manifest.txt
55
55
  - README.txt
56
56
  - Rakefile
57
+ - example/roster.rb
58
+ - example/roster_dsl.rb
59
+ - example/student.rb
57
60
  - lib/block_chainable.rb
58
- - test/test_block_chainable.rb
61
+ - spec/bar.rb
59
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
60
68
  has_rdoc: true
61
69
  homepage: http://block-chainable.rubyforge.org
62
70
  post_install_message: