light-service 0.17.0 → 0.19.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.
Files changed (50) hide show
  1. checksums.yaml +4 -4
  2. data/.github/workflows/project-build.yml +3 -6
  3. data/.rubocop.yml +117 -3
  4. data/README.md +101 -31
  5. data/RELEASES.md +11 -0
  6. data/lib/generators/light_service/generator_utils.rb +0 -2
  7. data/lib/light-service/action.rb +3 -5
  8. data/lib/light-service/configuration.rb +10 -2
  9. data/lib/light-service/context/key_verifier.rb +4 -2
  10. data/lib/light-service/context.rb +10 -15
  11. data/lib/light-service/deprecation_warning.rb +17 -0
  12. data/lib/light-service/errors.rb +4 -0
  13. data/lib/light-service/i18n/localization_adapter.rb +46 -0
  14. data/lib/light-service/localization_adapter.rb +14 -27
  15. data/lib/light-service/localization_map.rb +7 -0
  16. data/lib/light-service/orchestrator.rb +3 -3
  17. data/lib/light-service/organizer/reduce_case.rb +48 -0
  18. data/lib/light-service/organizer/verify_call_method_exists.rb +1 -1
  19. data/lib/light-service/organizer/with_reducer.rb +6 -8
  20. data/lib/light-service/organizer/with_reducer_log_decorator.rb +2 -2
  21. data/lib/light-service/organizer.rb +5 -3
  22. data/lib/light-service/testing/context_factory.rb +4 -0
  23. data/lib/light-service/version.rb +1 -1
  24. data/lib/light-service.rb +5 -2
  25. data/light-service.gemspec +3 -6
  26. data/spec/acceptance/after_actions_spec.rb +3 -9
  27. data/spec/acceptance/before_actions_spec.rb +3 -9
  28. data/spec/acceptance/include_warning_spec.rb +2 -2
  29. data/spec/acceptance/message_localization_spec.rb +7 -7
  30. data/spec/acceptance/not_having_call_method_warning_spec.rb +3 -3
  31. data/spec/acceptance/organizer/reduce_case_spec.rb +53 -0
  32. data/spec/acceptance/organizer/reduce_if_spec.rb +2 -0
  33. data/spec/acceptance/skip_all_warning_spec.rb +1 -1
  34. data/spec/context/inspect_spec.rb +5 -21
  35. data/spec/context_spec.rb +2 -2
  36. data/spec/i18n_localization_adapter_spec.rb +83 -0
  37. data/spec/lib/generators/action_generator_advanced_spec.rb +1 -1
  38. data/spec/lib/generators/action_generator_simple_spec.rb +1 -1
  39. data/spec/lib/generators/organizer_generator_advanced_spec.rb +1 -1
  40. data/spec/lib/generators/organizer_generator_simple_spec.rb +1 -1
  41. data/spec/localization_adapter_spec.rb +17 -38
  42. data/spec/sample/calculates_tax_spec.rb +0 -1
  43. data/spec/sample/looks_up_tax_percentage_action_spec.rb +3 -1
  44. data/spec/support.rb +1 -1
  45. data/spec/test_doubles.rb +20 -5
  46. data/spec/testing/context_factory_spec.rb +15 -0
  47. metadata +19 -42
  48. data/Appraisals +0 -11
  49. data/gemfiles/activesupport_5.gemfile +0 -7
  50. data/gemfiles/activesupport_6.gemfile +0 -7
@@ -5,6 +5,21 @@ describe LightService::LocalizationAdapter do
5
5
  let(:action_class) { TestDoubles::AnAction }
6
6
  let(:adapter) { described_class.new }
7
7
 
8
+ before do
9
+ LightService::LocalizationMap.instance[:en] = {
10
+ :'test_doubles/an_action' => {
11
+ :light_service => {
12
+ :failures => {
13
+ :not_found => "failure message"
14
+ },
15
+ :successes => {
16
+ :not_found => "success message"
17
+ }
18
+ }
19
+ }
20
+ }
21
+ end
22
+
8
23
  describe "#failure" do
9
24
  subject { adapter.failure(message_or_key, action_class) }
10
25
 
@@ -12,25 +27,7 @@ describe LightService::LocalizationAdapter do
12
27
  let(:message_or_key) { :not_found }
13
28
 
14
29
  it "translates the message" do
15
- expected_scope = "test_doubles/an_action.light_service.failures"
16
-
17
- expect(I18n).to receive(:t)
18
- .with(message_or_key, :scope => expected_scope)
19
- .and_return("message")
20
-
21
- expect(subject).to eq("message")
22
- end
23
-
24
- it "allows passing interpolation options to I18n layer" do
25
- expect(I18n).to receive(:t)
26
- .with(message_or_key, hash_including(:i18n_variable => "value"))
27
- .and_return("message")
28
-
29
- subject = adapter.failure(message_or_key,
30
- action_class,
31
- :i18n_variable => "value")
32
-
33
- expect(subject).to eq("message")
30
+ expect(subject).to eq("failure message")
34
31
  end
35
32
  end
36
33
 
@@ -50,25 +47,7 @@ describe LightService::LocalizationAdapter do
50
47
  let(:message_or_key) { :not_found }
51
48
 
52
49
  it "translates the message" do
53
- expected_scope = "test_doubles/an_action.light_service.successes"
54
-
55
- expect(I18n).to receive(:t)
56
- .with(message_or_key, :scope => expected_scope)
57
- .and_return("message")
58
-
59
- expect(subject).to eq("message")
60
- end
61
-
62
- it "allows passing interpolation options to I18n layer" do
63
- expect(I18n).to receive(:t)
64
- .with(message_or_key, hash_including(:i18n_variable => "value"))
65
- .and_return("message")
66
-
67
- subject = adapter.success(message_or_key,
68
- action_class,
69
- :i18n_variable => "value")
70
-
71
- expect(subject).to eq("message")
50
+ expect(subject).to eq("success message")
72
51
  end
73
52
  end
74
53
 
@@ -10,7 +10,6 @@ describe CalculatesTax do
10
10
 
11
11
  it "calls the actions in order" do
12
12
  allow(LightService::Context).to receive(:make)
13
- .with(:order => order)
14
13
  .and_return(ctx)
15
14
 
16
15
  allow(LooksUpTaxPercentageAction).to receive(:execute)
@@ -1,7 +1,9 @@
1
1
  require 'spec_helper'
2
2
  require_relative 'tax/looks_up_tax_percentage_action'
3
3
 
4
- class TaxRange; end
4
+ class TaxRange
5
+ extend LightService::Action
6
+ end
5
7
 
6
8
  describe LooksUpTaxPercentageAction do
7
9
  let(:region) { double('region') }
data/spec/support.rb CHANGED
@@ -1,6 +1,6 @@
1
1
  RSpec.shared_context 'expect orchestrator warning' do
2
2
  before do
3
- expect(ActiveSupport::Deprecation)
3
+ expect(LightService::Deprecation)
4
4
  .to receive(:warn)
5
5
  .with(/^`Orchestrator#/)
6
6
  .at_least(:once)
data/spec/test_doubles.rb CHANGED
@@ -45,6 +45,7 @@ module TestDoubles
45
45
 
46
46
  class TestLogger
47
47
  attr_accessor :logs
48
+
48
49
  def initialize
49
50
  @logs = []
50
51
  end
@@ -93,8 +94,13 @@ module TestDoubles
93
94
  end
94
95
  end
95
96
 
96
- class AnAction; end
97
- class AnotherAction; end
97
+ class AnAction
98
+ extend LightService::Action
99
+ end
100
+
101
+ class AnotherAction
102
+ extend LightService::Action
103
+ end
98
104
 
99
105
  class AnOrganizer
100
106
  extend LightService::Organizer
@@ -112,6 +118,15 @@ module TestDoubles
112
118
  end
113
119
  end
114
120
 
121
+ class NamedArgumentOrganiser
122
+ extend LightService::Organizer
123
+
124
+ def self.call(number:)
125
+ with(number: number) # rubocop:disable Style/HashSyntax
126
+ .reduce([AddsTwoAction])
127
+ end
128
+ end
129
+
115
130
  class NotExplicitlyReturningContextOrganizer
116
131
  extend LightService::Organizer
117
132
 
@@ -176,9 +191,7 @@ module TestDoubles
176
191
  promises :latte
177
192
 
178
193
  executed do |context|
179
- if context.milk == :very_hot
180
- context.fail!("Can't make a latte from a milk that's very hot!")
181
- end
194
+ context.fail!("Can't make a latte from a milk that's very hot!") if context.milk == :very_hot
182
195
 
183
196
  if context.milk == :super_hot
184
197
  error_message = "Can't make a latte from a milk that's super hot!"
@@ -488,7 +501,9 @@ module TestDoubles
488
501
  class NullAction
489
502
  extend LightService::Action
490
503
 
504
+ # rubocop:disable Lint/EmptyBlock
491
505
  executed { |_ctx| }
506
+ # rubocop:enable Lint/EmptyBlock
492
507
  end
493
508
 
494
509
  class TestIterate
@@ -60,3 +60,18 @@ describe 'ContextFactory - used with AdditionOrganizer' do
60
60
  end
61
61
  end
62
62
  end
63
+
64
+ describe 'ContextFactory - used with NamedArgumentOrganiser' do
65
+ let(:organizer) { TestDoubles::NamedArgumentOrganiser }
66
+
67
+ # it's relevant to test this as handling of named arguments changed between ruby 2.7 and 3.0
68
+ it 'pass named arguments to the organiser' do
69
+ ctx =
70
+ LightService::Testing::ContextFactory
71
+ .make_from(organizer)
72
+ .for(TestDoubles::AddsTwoAction)
73
+ .with(number: 2) # rubocop:disable Style/HashSyntax
74
+
75
+ expect(ctx[:number]).to eq(2)
76
+ end
77
+ end
metadata CHANGED
@@ -1,29 +1,15 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: light-service
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.17.0
4
+ version: 0.19.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Attila Domokos
8
- autorequire:
8
+ autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2021-09-14 00:00:00.000000000 Z
11
+ date: 2024-09-08 00:00:00.000000000 Z
12
12
  dependencies:
13
- - !ruby/object:Gem::Dependency
14
- name: activesupport
15
- requirement: !ruby/object:Gem::Requirement
16
- requirements:
17
- - - ">="
18
- - !ruby/object:Gem::Version
19
- version: 4.0.0
20
- type: :runtime
21
- prerelease: false
22
- version_requirements: !ruby/object:Gem::Requirement
23
- requirements:
24
- - - ">="
25
- - !ruby/object:Gem::Version
26
- version: 4.0.0
27
13
  - !ruby/object:Gem::Dependency
28
14
  name: generator_spec
29
15
  requirement: !ruby/object:Gem::Requirement
@@ -52,20 +38,6 @@ dependencies:
52
38
  - - "~>"
53
39
  - !ruby/object:Gem::Version
54
40
  version: '3.0'
55
- - !ruby/object:Gem::Dependency
56
- name: appraisal
57
- requirement: !ruby/object:Gem::Requirement
58
- requirements:
59
- - - "~>"
60
- - !ruby/object:Gem::Version
61
- version: '2.3'
62
- type: :development
63
- prerelease: false
64
- version_requirements: !ruby/object:Gem::Requirement
65
- requirements:
66
- - - "~>"
67
- - !ruby/object:Gem::Version
68
- version: '2.3'
69
41
  - !ruby/object:Gem::Dependency
70
42
  name: rspec
71
43
  requirement: !ruby/object:Gem::Requirement
@@ -114,14 +86,14 @@ dependencies:
114
86
  requirements:
115
87
  - - "~>"
116
88
  - !ruby/object:Gem::Version
117
- version: 0.68.0
89
+ version: 1.26.0
118
90
  type: :development
119
91
  prerelease: false
120
92
  version_requirements: !ruby/object:Gem::Requirement
121
93
  requirements:
122
94
  - - "~>"
123
95
  - !ruby/object:Gem::Version
124
- version: 0.68.0
96
+ version: 1.26.0
125
97
  - !ruby/object:Gem::Dependency
126
98
  name: rubocop-performance
127
99
  requirement: !ruby/object:Gem::Requirement
@@ -142,14 +114,14 @@ dependencies:
142
114
  requirements:
143
115
  - - "~>"
144
116
  - !ruby/object:Gem::Version
145
- version: 0.12.2
117
+ version: '0.14'
146
118
  type: :development
147
119
  prerelease: false
148
120
  version_requirements: !ruby/object:Gem::Requirement
149
121
  requirements:
150
122
  - - "~>"
151
123
  - !ruby/object:Gem::Version
152
- version: 0.12.2
124
+ version: '0.14'
153
125
  description: A service skeleton with an emphasis on simplicity
154
126
  email:
155
127
  - adomokos@gmail.com
@@ -162,15 +134,12 @@ files:
162
134
  - ".rspec"
163
135
  - ".rubocop.yml"
164
136
  - ".travis.yml"
165
- - Appraisals
166
137
  - CODE_OF_CONDUCT.md
167
138
  - Gemfile
168
139
  - LICENSE
169
140
  - README.md
170
141
  - RELEASES.md
171
142
  - Rakefile
172
- - gemfiles/activesupport_5.gemfile
173
- - gemfiles/activesupport_6.gemfile
174
143
  - lib/generators/light_service/action_generator.rb
175
144
  - lib/generators/light_service/generator_utils.rb
176
145
  - lib/generators/light_service/organizer_generator.rb
@@ -183,12 +152,16 @@ files:
183
152
  - lib/light-service/configuration.rb
184
153
  - lib/light-service/context.rb
185
154
  - lib/light-service/context/key_verifier.rb
155
+ - lib/light-service/deprecation_warning.rb
186
156
  - lib/light-service/errors.rb
157
+ - lib/light-service/i18n/localization_adapter.rb
187
158
  - lib/light-service/localization_adapter.rb
159
+ - lib/light-service/localization_map.rb
188
160
  - lib/light-service/orchestrator.rb
189
161
  - lib/light-service/organizer.rb
190
162
  - lib/light-service/organizer/execute.rb
191
163
  - lib/light-service/organizer/iterate.rb
164
+ - lib/light-service/organizer/reduce_case.rb
192
165
  - lib/light-service/organizer/reduce_if.rb
193
166
  - lib/light-service/organizer/reduce_if_else.rb
194
167
  - lib/light-service/organizer/reduce_until.rb
@@ -230,6 +203,7 @@ files:
230
203
  - spec/acceptance/organizer/execute_spec.rb
231
204
  - spec/acceptance/organizer/execute_with_add_to_context_spec.rb
232
205
  - spec/acceptance/organizer/iterate_spec.rb
206
+ - spec/acceptance/organizer/reduce_case_spec.rb
233
207
  - spec/acceptance/organizer/reduce_if_else_spec.rb
234
208
  - spec/acceptance/organizer/reduce_if_spec.rb
235
209
  - spec/acceptance/organizer/reduce_until_spec.rb
@@ -244,6 +218,7 @@ files:
244
218
  - spec/action_spec.rb
245
219
  - spec/context/inspect_spec.rb
246
220
  - spec/context_spec.rb
221
+ - spec/i18n_localization_adapter_spec.rb
247
222
  - spec/lib/generators/action_generator_advanced_spec.rb
248
223
  - spec/lib/generators/action_generator_simple_spec.rb
249
224
  - spec/lib/generators/full_generator_test_blobs.rb
@@ -273,7 +248,7 @@ homepage: https://github.com/adomokos/light-service
273
248
  licenses:
274
249
  - MIT
275
250
  metadata: {}
276
- post_install_message:
251
+ post_install_message:
277
252
  rdoc_options: []
278
253
  require_paths:
279
254
  - lib
@@ -281,15 +256,15 @@ required_ruby_version: !ruby/object:Gem::Requirement
281
256
  requirements:
282
257
  - - ">="
283
258
  - !ruby/object:Gem::Version
284
- version: 2.5.0
259
+ version: 2.6.0
285
260
  required_rubygems_version: !ruby/object:Gem::Requirement
286
261
  requirements:
287
262
  - - ">="
288
263
  - !ruby/object:Gem::Version
289
264
  version: '0'
290
265
  requirements: []
291
- rubygems_version: 3.1.6
292
- signing_key:
266
+ rubygems_version: 3.5.3
267
+ signing_key:
293
268
  specification_version: 4
294
269
  summary: A service skeleton with an emphasis on simplicity
295
270
  test_files:
@@ -317,6 +292,7 @@ test_files:
317
292
  - spec/acceptance/organizer/execute_spec.rb
318
293
  - spec/acceptance/organizer/execute_with_add_to_context_spec.rb
319
294
  - spec/acceptance/organizer/iterate_spec.rb
295
+ - spec/acceptance/organizer/reduce_case_spec.rb
320
296
  - spec/acceptance/organizer/reduce_if_else_spec.rb
321
297
  - spec/acceptance/organizer/reduce_if_spec.rb
322
298
  - spec/acceptance/organizer/reduce_until_spec.rb
@@ -331,6 +307,7 @@ test_files:
331
307
  - spec/action_spec.rb
332
308
  - spec/context/inspect_spec.rb
333
309
  - spec/context_spec.rb
310
+ - spec/i18n_localization_adapter_spec.rb
334
311
  - spec/lib/generators/action_generator_advanced_spec.rb
335
312
  - spec/lib/generators/action_generator_simple_spec.rb
336
313
  - spec/lib/generators/full_generator_test_blobs.rb
data/Appraisals DELETED
@@ -1,11 +0,0 @@
1
- appraise "activesupport-4" do
2
- gem "activesupport", "~> 4.0"
3
- end
4
-
5
- appraise "activesupport-5" do
6
- gem "activesupport", "~> 5.0"
7
- end
8
-
9
- appraise "activesupport-6" do
10
- gem "activesupport", "~> 6.0"
11
- end
@@ -1,7 +0,0 @@
1
- # This file was generated by Appraisal
2
-
3
- source "https://rubygems.org"
4
-
5
- gem "activesupport", "~> 5.0"
6
-
7
- gemspec :path => "../"
@@ -1,7 +0,0 @@
1
- # This file was generated by Appraisal
2
-
3
- source "https://rubygems.org"
4
-
5
- gem "activesupport", "~> 6.0"
6
-
7
- gemspec :path => "../"