block-chainable 0.0.1 → 0.0.2
Sign up to get free protection for your applications and to get access to all the features.
- data/History.txt +5 -0
- data/README.txt +54 -6
- data/Rakefile +2 -1
- data/lib/block_chainable.rb +2 -0
- metadata +2 -2
data/History.txt
CHANGED
data/README.txt
CHANGED
@@ -23,16 +23,65 @@ you to assert values within the blocks as well as calling any other methods from
|
|
23
23
|
* Stack trace should be simplified on errors within BlockChainable blocks
|
24
24
|
|
25
25
|
== SYNOPSIS:
|
26
|
+
# a simple nonsense example showing the ability to call methods in outer block scopes
|
27
|
+
|
28
|
+
# create some simple classes that include BlockChainable
|
29
|
+
require 'block_chainable'
|
26
30
|
|
31
|
+
class Foo
|
32
|
+
include BlockChainable
|
33
|
+
|
34
|
+
def hi_from_foo
|
35
|
+
puts "hello from foo"
|
36
|
+
end
|
37
|
+
end
|
38
|
+
|
39
|
+
class Bar
|
40
|
+
include BlockChainable
|
41
|
+
|
42
|
+
def hi_from_bar
|
43
|
+
puts "hello from bar"
|
44
|
+
end
|
45
|
+
end
|
46
|
+
|
47
|
+
class Boo
|
48
|
+
include BlockChainable
|
49
|
+
|
50
|
+
def hi_from_boo
|
51
|
+
puts "hello from boo"
|
52
|
+
end
|
53
|
+
end
|
54
|
+
|
55
|
+
|
56
|
+
# we can now use the classes in a DSL manner. notice that calls can happen from with blocks to
|
57
|
+
# "outer-block" methods.
|
58
|
+
Foo do
|
59
|
+
hi_from_foo
|
60
|
+
|
61
|
+
Bar do
|
62
|
+
hi_from_bar
|
63
|
+
hi_from_foo
|
64
|
+
|
65
|
+
Boo do
|
66
|
+
hi_from_boo
|
67
|
+
hi_from_bar
|
68
|
+
hi_from_foo
|
69
|
+
end
|
70
|
+
end
|
71
|
+
end
|
72
|
+
|
73
|
+
# A slighty more complicated example.
|
27
74
|
# a simple dsl for creating classroom rosters and printing them out. code can be found in the
|
28
75
|
# example directory.
|
76
|
+
|
77
|
+
require 'block_chainable'
|
29
78
|
|
30
79
|
# first, define our roster
|
31
80
|
class Roster
|
32
81
|
include BlockChainable
|
33
82
|
|
34
83
|
def initialize(subject)
|
35
|
-
|
84
|
+
@subject = subject
|
36
85
|
@students = []
|
37
86
|
end
|
38
87
|
|
@@ -41,20 +90,20 @@ you to assert values within the blocks as well as calling any other methods from
|
|
41
90
|
end
|
42
91
|
|
43
92
|
def print_roster
|
44
|
-
|
93
|
+
puts "Roster for #{@subject}:"
|
45
94
|
@students.each{|s| puts " #{s}"}
|
46
95
|
end
|
47
96
|
end
|
48
97
|
|
49
98
|
# next, define our student. the only tricky part here is add_to_roster, which calls
|
50
|
-
# the method
|
51
|
-
# BlockChainable will automatically send this method to the
|
99
|
+
# the method add_student_to_roster, which is actually defined on the Roster class.
|
100
|
+
# BlockChainable will automatically send this method to the Roster class with the
|
52
101
|
# Student instance as a parameter.
|
53
102
|
class Student
|
54
103
|
include BlockChainable
|
55
104
|
|
56
105
|
def add_to_roster
|
57
|
-
|
106
|
+
add_student_to_roster self
|
58
107
|
end
|
59
108
|
|
60
109
|
def to_s
|
@@ -76,7 +125,6 @@ you to assert values within the blocks as well as calling any other methods from
|
|
76
125
|
|
77
126
|
# we now have all the pieces we need for creating a simple dsl for building
|
78
127
|
# and printing a class roster
|
79
|
-
require 'block_chainable'
|
80
128
|
|
81
129
|
Roster :Math do
|
82
130
|
Student do
|
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.
|
9
|
+
Hoe.new('block-chainable', '0.0.2') do |p|
|
10
10
|
p.rubyforge_name = 'block-chainable'
|
11
11
|
p.author = 'Drew Olson'
|
12
12
|
p.email = 'olsonas@gmail.com'
|
@@ -16,6 +16,7 @@ Hoe.new('block-chainable', '0.0.1') do |p|
|
|
16
16
|
p.changes = p.paragraphs_of('History.txt', 0..1).join("\n\n")
|
17
17
|
p.extra_deps << ['need', '>= 1.0.1']
|
18
18
|
p.extra_deps << ['rspec', '>= 1.1.3']
|
19
|
+
p.remote_rdoc_dir = ''
|
19
20
|
end
|
20
21
|
|
21
22
|
Spec::Rake::SpecTask.new do |t|
|
data/lib/block_chainable.rb
CHANGED
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.
|
4
|
+
version: 0.0.2
|
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-
|
12
|
+
date: 2008-03-07 00:00:00 -06:00
|
13
13
|
default_executable:
|
14
14
|
dependencies:
|
15
15
|
- !ruby/object:Gem::Dependency
|