carry_out 1.2.0 → 1.3.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 16830ee088c7b7c1b7dc3fb7de84d5df9f521dea
4
- data.tar.gz: 44e1f37324820a73e7e4a68e9c0da07cc89723ed
3
+ metadata.gz: 93f80c00a226b8751663d149943b30aeb5c2dd35
4
+ data.tar.gz: 4561dba1b6110b7dbc1a4712ba4fde4204910608
5
5
  SHA512:
6
- metadata.gz: 80581596bd631638de21ab30b4401464237303e4932f37d9f33546318bc31c38603c095da3e1fe78da855d4449042f9708ee139b175d088f175370aed26481ac
7
- data.tar.gz: bd634f1d8d8a24cbf91a54c4014e26a477865adb38c80f0bf3b1df5c81ec9dfd5732fc689c895a46592b1eed2577dba9147b73c67e6131d5cf6c473460aa40a2
6
+ metadata.gz: 3f5521e863a205ae3345357df363613e5ef14c29974a31e08f67367aab963c0c7303caa2a43fa78db1dab3d8b8890fe18825dbf4273e1a7f7f27b538ca4f84bc
7
+ data.tar.gz: a390316064acff75e07c46dbb9124278bdcc27baa9584a1f75de23cf4be38a894dd27adb7a27759c6edbafe9c3353222d5c0d85832199f16b88426104dbc46ea
data/lib/carry_out.rb CHANGED
@@ -18,6 +18,14 @@ module CarryOut
18
18
  def plan(options = {}, &block)
19
19
  CarryOut.plan(Hash.new.merge(@options).merge(options), &block)
20
20
  end
21
+
22
+ def call_unit(*args, &block)
23
+ CarryOut.call_unit(*args)
24
+ end
25
+ end
26
+
27
+ def self.call_unit(*args, &block)
28
+ PlanRunner.call_unit(*args, &block)
21
29
  end
22
30
 
23
31
  def self.configure(&block)
@@ -29,7 +37,7 @@ module CarryOut
29
37
  plan = PlanBuilder.build(merged_options, &block)
30
38
 
31
39
  Proc.new do |context = nil, &block|
32
- PlanRunner.run(plan, context).tap do |result|
40
+ PlanRunner.call(plan, context).tap do |result|
33
41
  block.call(result) unless block.nil?
34
42
  end
35
43
  end
@@ -1,10 +1,6 @@
1
1
  module CarryOut
2
2
  class PlanRunner
3
- def self.run(plan, context = {})
4
- PlanRunner.new.run(plan, context)
5
- end
6
-
7
- def run(plan, context = {})
3
+ def self.call(plan, context = {})
8
4
  Result.new(context).tap do |plan_result|
9
5
  node = plan
10
6
 
@@ -27,5 +23,12 @@ module CarryOut
27
23
  end
28
24
  end
29
25
  end
26
+
27
+ def self.call_unit(unit, context = {}, &block)
28
+ node = Plan::Node.new(unit)
29
+ Plan::NodeContext.new(node).instance_eval(&block) unless block.nil?
30
+
31
+ call(node, context)
32
+ end
30
33
  end
31
34
  end
@@ -9,11 +9,16 @@ module CarryOut
9
9
 
10
10
  def add(group, object)
11
11
  if object.kind_of?(CarryOut::Error)
12
- errors << ResultError.new(
13
- group: group,
12
+ object = ResultError.new(
14
13
  message: object.message,
15
14
  details: object.details
16
15
  )
16
+ end
17
+
18
+ if object.kind_of?(CarryOut::ResultError)
19
+ group = group || :_unlabeled
20
+ errors[group] ||= []
21
+ errors[group] << object
17
22
  elsif object.kind_of?(Enumerable) && object.all? { |o| o.kind_of?(CarryOut::Error) }
18
23
  object.each { |o| add(group, o) }
19
24
  else
@@ -22,10 +27,12 @@ module CarryOut
22
27
  artifacts[group] ||= {}
23
28
  object.each { |k,v| artifacts[group][k] = v }
24
29
  elsif object.kind_of?(Result)
25
- add(group, object.to_hash)
26
-
27
- object.errors.each do |error|
28
- add([group, error.group].flatten(1), e)
30
+ add(group, object.artifacts)
31
+
32
+ object.errors.each do |g, errors|
33
+ error_group = [ group, g ]
34
+
35
+ errors.each { |e| add(error_group, e) }
29
36
  end
30
37
  else
31
38
  artifacts[group] = object
@@ -39,25 +46,11 @@ module CarryOut
39
46
  end
40
47
 
41
48
  def errors
42
- @errors ||= []
43
- end
44
-
45
- def errors_hash
46
- Hash.new.tap do |h|
47
- errors.each do |e|
48
- if e.details.kind_of?(Hash)
49
- h.merge!(e.details)
50
- end
51
- end
52
- end
49
+ @errors ||= {}
53
50
  end
54
51
 
55
52
  def success?
56
53
  @errors.nil? || @errors.empty?
57
54
  end
58
-
59
- def to_hash
60
- artifacts
61
- end
62
55
  end
63
56
  end
@@ -1,12 +1,10 @@
1
1
  module CarryOut
2
2
  class ResultError
3
3
  attr_reader :details
4
- attr_reader :group
5
4
  attr_reader :message
6
5
 
7
6
  def initialize(options = {})
8
7
  @details = options[:details]
9
- @group = options[:group]
10
8
  @message = options[:message]
11
9
  end
12
10
  end
@@ -1,3 +1,3 @@
1
1
  module CarryOut
2
- VERSION = "1.2.0"
2
+ VERSION = "1.3.0"
3
3
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: carry_out
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.2.0
4
+ version: 1.3.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Ryan Fields
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2017-04-13 00:00:00.000000000 Z
11
+ date: 2017-04-14 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler