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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 81cef754be11e750d13eb7c4c28596cca62fa8b5
4
- data.tar.gz: a8b9814705f934709c072173a5e03d5f13ef27cf
3
+ metadata.gz: ab098b12a5104178762bdab02134bcd76c5e2db0
4
+ data.tar.gz: 168bf4050f3f21cb425826a6f24165927b85c909
5
5
  SHA512:
6
- metadata.gz: bd3bc62356f10cf94064ea850bd1fca0fc0b499b4b4d5b61fd4b668bad7fa221a16d0eee6326b387dc10e61297ef6a0ca7f7419ea981ce6ca22c1c1cecab663c
7
- data.tar.gz: 540ffe7d99d9f80cec753b61dfae8637e93be7393b449ff0481a1c2dd59d7cb440e153f9ae173528f730dc5d2a8f954be13be63142e608cf07d42bf72461c666
6
+ metadata.gz: e0964f3b499ad5fac687b02ca037e4045529a5013c971b2b237c156a6fbf9231a5eba8cbff6da8dd3fe00dd6b528e316c54f6bb4b5362648375626ec2eaf213c
7
+ data.tar.gz: c60ce1162e529152aef0f846b95f14ea41eb2927438b8b01adfd0f40bfd9cb4c539975f40f8ab3a8a2875aa9fad87b918d7879c993c55ce17fd829289dca0251
@@ -47,9 +47,9 @@ module Subroutine
47
47
 
48
48
  def self.sequence(&lambda)
49
49
  if block_given?
50
- Proc.new{
50
+ Proc.new{|*options|
51
51
  @@sequence += 1
52
- lambda.call(@@sequence)
52
+ lambda.call(*[@@sequence, *options].compact)
53
53
  }
54
54
  else
55
55
  @@sequence += 1
@@ -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
- op = op_class.new(*input_args)
16
- Array(@options[:befores]).each{|block| block.call(op) }
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
- Array(@options[:afters]).each{|block| block.call(op, output) }
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.respond_to?(:call) ? v.call : 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 input_args
38
- args = @args.dup
39
- args.push(inputs)
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
@@ -1,5 +1,5 @@
1
1
  module Subroutine
2
2
  module Factory
3
- VERSION = "0.1.4"
3
+ VERSION = "0.1.5"
4
4
  end
5
5
  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
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-09-17 00:00:00.000000000 Z
11
+ date: 2015-10-22 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: subroutine