function_chain 0.0.1 → 0.0.2
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/README.md +5 -4
- data/lib/function_chain/pull_chain.rb +2 -2
- data/lib/function_chain/version.rb +1 -1
- data/spec/function_chain_spec.rb +13 -0
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: fdf003460177adf194c6282fc22e83659bb93c5a
|
4
|
+
data.tar.gz: fcf5395ab9889a3ede9cfbbea020de00644ce4d8
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 8b3821ebdc3b4234bbbcaae2bc502c832fa63f6a4e2df14f08b8baa18ea334add047f2e48724901c00609d63a81e193b91001d6e37fef9b9c253cf02fbf5d37a
|
7
|
+
data.tar.gz: 2f9afcd3051e99adfd032558cea80309e09b2c09954f4a6f652fbf1eb721bcb3cf74b9518e37c12979995842b00359c01768c41fde149cc3402aeb2a7d558ee3
|
data/README.md
CHANGED
@@ -130,7 +130,7 @@ What should do in this case?
|
|
130
130
|
|
131
131
|
###### Solution
|
132
132
|
|
133
|
-
1. **Array, format is [Symbol, [\*Args, Proc]]
|
133
|
+
1. **Array, format is [Symbol, [\*Args, Proc]]**
|
134
134
|
```ruby
|
135
135
|
chain = PullChain.new([1,2,3,4,5])
|
136
136
|
chain << [:inject, [3, lambda { |sum, n| sum + n }]]
|
@@ -374,8 +374,9 @@ end
|
|
374
374
|
lambda's format is following.
|
375
375
|
```ruby
|
376
376
|
# parameter: chain is chain object.
|
377
|
-
# parameter:
|
378
|
-
|
377
|
+
# parameter: *args is previous functions output.
|
378
|
+
# *args_of_next_func is next functions input.
|
379
|
+
lambda {|chain, *args| chain.call( *args_of_next_func ) }.
|
379
380
|
```
|
380
381
|
can call next function by chain object.
|
381
382
|
```ruby
|
@@ -411,7 +412,7 @@ end
|
|
411
412
|
|
412
413
|
chain = RelayChain.new(Decorator.new, :decorate1, :decorate2)
|
413
414
|
|
414
|
-
#
|
415
|
+
# insert conditional chain stopper
|
415
416
|
chain.insert(1, create_stopper { |value| value =~ /\d/ })
|
416
417
|
chain.call("Van Halen 1984") # => ( Van Halen 1984 ) not enclosed to {}
|
417
418
|
chain.call("Van Halen Jump") # => { ( Van Halen Jump ) } enclosed to {}
|
@@ -212,12 +212,12 @@ module FunctionChain
|
|
212
212
|
|
213
213
|
def extract_args_and_block(array_function_param)
|
214
214
|
if array_function_param.is_a? Proc
|
215
|
-
return result_accessor.instance_eval(&array_function_param)
|
215
|
+
return result_accessor.instance_eval(&array_function_param), nil
|
216
216
|
end
|
217
217
|
if array_function_param.last.is_a? Proc
|
218
218
|
return array_function_param[0...-1], array_function_param.last
|
219
219
|
end
|
220
|
-
array_function_param
|
220
|
+
return array_function_param, nil
|
221
221
|
end
|
222
222
|
|
223
223
|
def create_chain_element_by_string(string)
|
data/spec/function_chain_spec.rb
CHANGED
@@ -24,6 +24,13 @@ describe FunctionChain::PullChain do
|
|
24
24
|
}
|
25
25
|
@city = City.new(BookStore.new(shelves, :mystery))
|
26
26
|
|
27
|
+
class Concatter
|
28
|
+
def concat(value1, value2)
|
29
|
+
"#{value1} to #{value2}"
|
30
|
+
end
|
31
|
+
end
|
32
|
+
@concatter = Concatter.new
|
33
|
+
|
27
34
|
PullChain = FunctionChain::PullChain
|
28
35
|
end
|
29
36
|
|
@@ -66,6 +73,12 @@ describe FunctionChain::PullChain do
|
|
66
73
|
expect(chain.call).to eq(@city.bookstore.shelves[:mystery])
|
67
74
|
end
|
68
75
|
|
76
|
+
it "[success case] array type function with proc(return multi value)" do
|
77
|
+
chain = PullChain.new(@concatter)
|
78
|
+
chain << [:concat, Proc.new { next "Stairway", "Heaven" }]
|
79
|
+
expect(chain.call).to eq(@concatter.concat("Stairway", "Heaven"))
|
80
|
+
end
|
81
|
+
|
69
82
|
it "[success case] string type function" do
|
70
83
|
chain = PullChain.new(@city)
|
71
84
|
chain << "/bookstore/shelves[:programing]/books[1]/title"
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: function_chain
|
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
|
- Kenji Suzuki
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2014-10-
|
11
|
+
date: 2014-10-15 00:00:00.000000000 Z
|
12
12
|
dependencies: []
|
13
13
|
description: 'FunctionChain objectifies of the method chain.chain objects can call
|
14
14
|
later or add chain or insert chain or delete chain.supported chain type is following:
|