light-service 0.10.3 → 0.11.0

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: 35d148e9bdcc089cd30046a2a99eff468ec77fde
4
- data.tar.gz: 95b6d152ab5eca62471cfb245be0f60c2d4bfc73
3
+ metadata.gz: 591c6fcf80629485e608c41881fc41ebd8db307c
4
+ data.tar.gz: fdb6a27728e5201513be58cefd4b4335274509cd
5
5
  SHA512:
6
- metadata.gz: 20fe035e150978da67f5cc624c9e142fc5299c7b20cc1f71d89c90a665577daa85ec73e32f695950f7d5d52ce0a4604159b08d367b195d27191819c18f497b38
7
- data.tar.gz: 829ccc813a76c16da7ceb7aaa02262d30c555b5486224212b016588a45c2f172e050e6a2c6adc0c2ebef2c28ce5e9f3968a6c791fbc30c2cf4bee2f2a336824d
6
+ metadata.gz: a2ea84a98fb446cae6616d0c02b30d21e1f0c1a29dc5a5adb7692c4acc9be69a4769ec799c51e5c16ee4888a370d551e915e076b5e7ae9985b28ccac216ea46c
7
+ data.tar.gz: 3770373e92ac2498a72bb9833097541a3f35f44c5c383636e0920cd50eb53c4260abccc156772285da1411486ed8e309c10323602b282cab02ecfaf210549194
data/README.md CHANGED
@@ -3,7 +3,6 @@
3
3
  [![Gem Version](https://img.shields.io/gem/v/light-service.svg)](https://rubygems.org/gems/light-service)
4
4
  [![Build Status](https://secure.travis-ci.org/adomokos/light-service.png)](http://travis-ci.org/adomokos/light-service)
5
5
  [![Code Climate](https://codeclimate.com/github/adomokos/light-service.png)](https://codeclimate.com/github/adomokos/light-service)
6
- [![Dependency Status](https://beta.gemnasium.com/badges/github.com/adomokos/light-service.svg)](https://beta.gemnasium.com/projects/github.com/adomokos/light-service)
7
6
  [![License](https://img.shields.io/badge/license-MIT-green.svg)](http://opensource.org/licenses/MIT)
8
7
 
9
8
  <br><br>
@@ -1,6 +1,9 @@
1
1
  A brief list of new features and changes introduced with the specified version.
2
2
 
3
- ### 0.10.2
3
+ ### 0.11.0
4
+ * [Switch to 'each_with_object' in WithReducer](https://github.com/adomokos/light-service/pull/149).
5
+
6
+ ### 0.10.3
4
7
  * [Adding ContextFactory](https://github.com/adomokos/light-service/pull/147).
5
8
 
6
9
  ### 0.10.2
@@ -25,17 +25,15 @@ module LightService
25
25
  raise "No action(s) were provided" if actions.empty?
26
26
  actions.flatten!
27
27
 
28
- actions.reduce(context) do |current_context, action|
28
+ actions.each_with_object(context) do |action, current_context|
29
29
  begin
30
- result = invoke_action(current_context, action)
30
+ invoke_action(current_context, action)
31
31
  rescue FailWithRollbackError
32
- result = reduce_rollback(actions)
32
+ reduce_rollback(actions)
33
33
  ensure
34
34
  # For logging
35
35
  yield(current_context, action) if block_given?
36
36
  end
37
-
38
- result
39
37
  end
40
38
  end
41
39
 
@@ -1,3 +1,3 @@
1
1
  module LightService
2
- VERSION = "0.10.3".freeze
2
+ VERSION = "0.11.0".freeze
3
3
  end
@@ -44,20 +44,6 @@ describe LightService::Organizer do
44
44
  end
45
45
  end
46
46
 
47
- context "when no starting context is specified" do
48
- it "creates one implicitly" do
49
- expect(TestDoubles::AnAction).to receive(:execute)
50
- .with({})
51
- .and_return(ctx)
52
- expect(TestDoubles::AnotherAction).to receive(:execute)
53
- .with(ctx)
54
- .and_return(ctx)
55
-
56
- expect { TestDoubles::AnOrganizer.do_something_with_no_starting_context }
57
- .not_to raise_error
58
- end
59
- end
60
-
61
47
  context "when aliases are declared" do
62
48
  let(:organizer) do
63
49
  Class.new do
@@ -83,4 +69,25 @@ describe LightService::Organizer do
83
69
  organizer.call
84
70
  end
85
71
  end
72
+
73
+ context "when an organizer is nested and reduced within another" do
74
+ let(:reduced) { TestDoubles::NestingOrganizer.call(ctx) }
75
+ let(:organizer_result) do
76
+ TestDoubles::NotExplicitlyReturningContextOrganizer.call(ctx)
77
+ end
78
+
79
+ it "reduces an organizer which returns something" do
80
+ expect(organizer_result).to eq([1, 2, 3])
81
+ end
82
+
83
+ it "adds :foo and :bar to the context" do
84
+ reduced
85
+ expect(ctx[:foo]).to eq([1, 2, 3])
86
+ expect(ctx[:bar]).to eq(ctx[:foo])
87
+ end
88
+
89
+ it "returns the context" do
90
+ expect(reduced).to eq(ctx)
91
+ end
92
+ end
86
93
  end
@@ -102,6 +102,36 @@ module TestDoubles
102
102
  end
103
103
  end
104
104
 
105
+ class NotExplicitlyReturningContextOrganizer
106
+ extend LightService::Organizer
107
+
108
+ def self.call(context)
109
+ context[:foo] = [1, 2, 3]
110
+ end
111
+ end
112
+
113
+ class NestingOrganizer
114
+ extend LightService::Organizer
115
+
116
+ def self.call(context)
117
+ with(context).reduce(actions)
118
+ end
119
+
120
+ def self.actions
121
+ [NotExplicitlyReturningContextOrganizer, NestedAction]
122
+ end
123
+ end
124
+
125
+ class NestedAction
126
+ extend LightService::Action
127
+
128
+ expects :foo
129
+
130
+ executed do |context|
131
+ context[:bar] = context.foo
132
+ end
133
+ end
134
+
105
135
  class MakesTeaWithMilkAction
106
136
  extend LightService::Action
107
137
  expects :tea, :milk
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: light-service
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.10.3
4
+ version: 0.11.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Attila Domokos
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2018-04-03 00:00:00.000000000 Z
11
+ date: 2018-05-22 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: activesupport