subroutine-factory 0.1.4 → 0.1.5
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/lib/subroutine/factory.rb +2 -2
- data/lib/subroutine/factory/builder.rb +20 -10
- data/lib/subroutine/factory/config.rb +8 -0
- data/lib/subroutine/factory/version.rb +1 -1
- 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: ab098b12a5104178762bdab02134bcd76c5e2db0
|
4
|
+
data.tar.gz: 168bf4050f3f21cb425826a6f24165927b85c909
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: e0964f3b499ad5fac687b02ca037e4045529a5013c971b2b237c156a6fbf9231a5eba8cbff6da8dd3fe00dd6b528e316c54f6bb4b5362648375626ec2eaf213c
|
7
|
+
data.tar.gz: c60ce1162e529152aef0f846b95f14ea41eb2927438b8b01adfd0f40bfd9cb4c539975f40f8ab3a8a2875aa9fad87b918d7879c993c55ce17fd829289dca0251
|
data/lib/subroutine/factory.rb
CHANGED
@@ -6,17 +6,28 @@ module Subroutine
|
|
6
6
|
|
7
7
|
def initialize(config, *args)
|
8
8
|
@config = config
|
9
|
-
@options = config.options
|
10
|
-
@args = args
|
9
|
+
@options = config.options.dup
|
10
|
+
@args = args.dup
|
11
11
|
@overrides = @args.extract_options!
|
12
12
|
end
|
13
13
|
|
14
14
|
def execute!
|
15
|
-
|
16
|
-
|
15
|
+
args = @args.dup
|
16
|
+
|
17
|
+
Array(@options[:setups]).each{|block| block.call(args, @options) }
|
18
|
+
|
19
|
+
args.push(inputs)
|
20
|
+
|
21
|
+
op = op_class.new(*args)
|
22
|
+
|
23
|
+
Array(@options[:befores]).each{|block| block.call(op, @options) }
|
24
|
+
|
17
25
|
op.submit!
|
26
|
+
|
18
27
|
output = extract_output(op)
|
19
|
-
|
28
|
+
|
29
|
+
Array(@options[:afters]).each{|block| block.call(op, output, @options) }
|
30
|
+
|
20
31
|
output
|
21
32
|
end
|
22
33
|
|
@@ -27,17 +38,16 @@ module Subroutine
|
|
27
38
|
if @overrides.has_key?(k)
|
28
39
|
out[k] = @overrides[k]
|
29
40
|
else
|
30
|
-
out[k] = v
|
41
|
+
out[k] = invoke_input(v)
|
31
42
|
end
|
32
43
|
end
|
33
44
|
|
34
45
|
out
|
35
46
|
end
|
36
47
|
|
37
|
-
def
|
38
|
-
|
39
|
-
|
40
|
-
args
|
48
|
+
def invoke_input(input)
|
49
|
+
return input unless input.respond_to?(:call)
|
50
|
+
input.arity.zero? ? input.call : input.call(@options)
|
41
51
|
end
|
42
52
|
|
43
53
|
def op_class
|
@@ -35,6 +35,10 @@ module Subroutine
|
|
35
35
|
end
|
36
36
|
end
|
37
37
|
|
38
|
+
def setup(&block)
|
39
|
+
@options[:setups].push(block)
|
40
|
+
end
|
41
|
+
|
38
42
|
def before(&block)
|
39
43
|
@options[:befores].push(block)
|
40
44
|
end
|
@@ -74,8 +78,12 @@ module Subroutine
|
|
74
78
|
outputs(*@options[:outputs]) if @options[:outputs]
|
75
79
|
output(@options[:output]) if @options[:output]
|
76
80
|
|
81
|
+
@options[:setups] = @options[:setups].dup if @options[:setups]
|
82
|
+
@options[:setups] ||= []
|
83
|
+
|
77
84
|
@options[:befores] = @options[:befores].dup if @options[:befores]
|
78
85
|
@options[:befores] ||= []
|
86
|
+
|
79
87
|
@options[:afters] = @options[:afters].dup if @options[:afters]
|
80
88
|
@options[:afters] ||= []
|
81
89
|
end
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: subroutine-factory
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.1.
|
4
|
+
version: 0.1.5
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Mike Nelson
|
8
8
|
autorequire:
|
9
9
|
bindir: exe
|
10
10
|
cert_chain: []
|
11
|
-
date: 2015-
|
11
|
+
date: 2015-10-22 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: subroutine
|