methodchain 0.3.0 → 0.3.1
Sign up to get free protection for your applications and to get access to all the features.
- data/Rakefile +5 -3
- data/doc/created.rid +1 -1
- data/lib/methodchain/not-included.rb +71 -0
- metadata +3 -7
- data/coverage/-var-lib-gems-1_8-gems-rcov-0_8_0_2-lib-rcov_rb.html +0 -1607
- data/coverage/index.html +0 -347
- data/coverage/lib-methodchain-not_included_rb.html +0 -698
- data/coverage/lib-methodchain_rb.html +0 -635
data/Rakefile
CHANGED
@@ -134,15 +134,17 @@ require 'rake/gempackagetask'
|
|
134
134
|
spec = Gem::Specification.new do |s|
|
135
135
|
s.name = project
|
136
136
|
s.rubyforge_project = project
|
137
|
-
s.version = "0.3.
|
137
|
+
s.version = "0.3.1"
|
138
138
|
s.author = "Greg Weber"
|
139
139
|
s.email = "greg@gregweber.info"
|
140
140
|
s.homepage = "http://projects.gregweber.info/#{project}"
|
141
141
|
s.platform = Gem::Platform::RUBY
|
142
142
|
s.summary = "convenience methods for method chaining"
|
143
|
-
s.files =
|
144
|
-
|
143
|
+
s.files =
|
144
|
+
FileList.new('./**', '*/**', 'lib/methodchain/*') do |fl|
|
145
|
+
fl.exclude('pkg','pkg/*','tmp','tmp/*', 'coverage', 'coverage/*')
|
145
146
|
end
|
147
|
+
p s.files
|
146
148
|
s.require_path = "lib"
|
147
149
|
s.has_rdoc = true
|
148
150
|
s.extra_rdoc_files = ["README"]
|
data/doc/created.rid
CHANGED
@@ -1 +1 @@
|
|
1
|
-
|
1
|
+
Mon, 17 Mar 2008 08:17:16 -0500
|
@@ -0,0 +1,71 @@
|
|
1
|
+
# :main: README
|
2
|
+
module MethodChain
|
3
|
+
|
4
|
+
private
|
5
|
+
|
6
|
+
# arg = Message | Code
|
7
|
+
# Message = Symbol | [Symbol, *arguments]
|
8
|
+
# Code.to_proc = Proc
|
9
|
+
def send_as_function arg
|
10
|
+
case arg
|
11
|
+
when Symbol then __send__ arg
|
12
|
+
when Array then __send__(*arg)
|
13
|
+
else yield_or_eval(&arg)
|
14
|
+
end
|
15
|
+
end
|
16
|
+
|
17
|
+
# send_as_function with multiple args, returns self
|
18
|
+
def send_as_functions *args
|
19
|
+
args.each {|arg| send_as_function arg}
|
20
|
+
self
|
21
|
+
end
|
22
|
+
|
23
|
+
# yield or instance_eval based on the block arity
|
24
|
+
def yield_or_eval &block
|
25
|
+
case block.arity
|
26
|
+
# ruby bug for -1
|
27
|
+
when 0, -1 then instance_eval(&block)
|
28
|
+
when 1 then yield(self)
|
29
|
+
else raise ArgumentError, "too many arguments required by block"
|
30
|
+
end
|
31
|
+
end
|
32
|
+
|
33
|
+
public
|
34
|
+
|
35
|
+
# send messages, evaluate blocks, but always return self
|
36
|
+
def tap *messages, &block
|
37
|
+
send_as_functions *messages unless messages.empty?
|
38
|
+
yield_or_eval(&block) if block_given?
|
39
|
+
self
|
40
|
+
end
|
41
|
+
|
42
|
+
# method chaining with a guard.
|
43
|
+
# If no guard block is given then guard against nil and false
|
44
|
+
def chain *messages, &guard
|
45
|
+
return self if messages.empty? or not(
|
46
|
+
(block_given? ? (yield_or_eval(&guard)) : self))
|
47
|
+
|
48
|
+
(send_as_function (messages.shift)).chain(*messages, &guard)
|
49
|
+
end
|
50
|
+
|
51
|
+
# return self if self evaluates to false, otherwise
|
52
|
+
# evaluate the block or return the default argument
|
53
|
+
def then default=nil, &block
|
54
|
+
if self
|
55
|
+
block_given? ? (yield_or_eval(&block)) : (default || (fail \
|
56
|
+
ArgumentError, "#then must be called with an argument or a block"))
|
57
|
+
else
|
58
|
+
self
|
59
|
+
end
|
60
|
+
end
|
61
|
+
|
62
|
+
# the inverse of then
|
63
|
+
def else arg=nil, &block
|
64
|
+
if self
|
65
|
+
self
|
66
|
+
else
|
67
|
+
block_given? ? (yield_or_eval(&block)) : (arg || (fail \
|
68
|
+
ArgumentError, "#else must be called with an argument or a bloc"))
|
69
|
+
end
|
70
|
+
end
|
71
|
+
end
|
metadata
CHANGED
@@ -3,8 +3,8 @@ rubygems_version: 0.9.4
|
|
3
3
|
specification_version: 1
|
4
4
|
name: methodchain
|
5
5
|
version: !ruby/object:Gem::Version
|
6
|
-
version: 0.3.
|
7
|
-
date: 2008-03-
|
6
|
+
version: 0.3.1
|
7
|
+
date: 2008-03-17 00:00:00 -05:00
|
8
8
|
summary: convenience methods for method chaining
|
9
9
|
require_paths:
|
10
10
|
- lib
|
@@ -34,7 +34,6 @@ files:
|
|
34
34
|
- ./spec
|
35
35
|
- ./Rakefile
|
36
36
|
- ./README
|
37
|
-
- ./coverage
|
38
37
|
- doc/files
|
39
38
|
- doc/index.html
|
40
39
|
- doc/rdoc-style.css
|
@@ -46,10 +45,7 @@ files:
|
|
46
45
|
- lib/methodchain
|
47
46
|
- lib/methodchain.rb
|
48
47
|
- spec/methodchain_spec.rb
|
49
|
-
-
|
50
|
-
- coverage/index.html
|
51
|
-
- coverage/-var-lib-gems-1_8-gems-rcov-0_8_0_2-lib-rcov_rb.html
|
52
|
-
- coverage/lib-methodchain-not_included_rb.html
|
48
|
+
- lib/methodchain/not-included.rb
|
53
49
|
- README
|
54
50
|
test_files: []
|
55
51
|
|