functional-light-service 6.1.0 → 6.2.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 +4 -4
- data/.gitignore +2 -0
- data/CHANGELOG.md +19 -0
- data/README.md +96 -11
- data/functional-light-service.gemspec +3 -1
- data/lib/functional-light-service/action.rb +48 -0
- data/lib/functional-light-service/configuration.rb +12 -2
- data/lib/functional-light-service/context/key_verifier.rb +1 -1
- data/lib/functional-light-service/context.rb +15 -2
- data/lib/functional-light-service/errors.rb +1 -0
- data/lib/functional-light-service/i18n/localization_adapter.rb +50 -0
- data/lib/functional-light-service/localization_adapter.rb +19 -28
- data/lib/functional-light-service/localization_map.rb +9 -0
- data/lib/functional-light-service/organizer/reduce_case.rb +50 -0
- data/lib/functional-light-service/organizer/reduce_if_else.rb +23 -0
- data/lib/functional-light-service/organizer/reduce_until.rb +1 -1
- data/lib/functional-light-service/organizer/reduce_while.rb +31 -0
- data/lib/functional-light-service/organizer/scoped_reducable.rb +2 -2
- data/lib/functional-light-service/organizer/with_reducer_log_decorator.rb +2 -1
- data/lib/functional-light-service/organizer.rb +18 -3
- data/lib/functional-light-service/version.rb +1 -1
- data/lib/functional-light-service.rb +5 -0
- data/spec/acceptance/organizer/add_to_context_spec.rb +24 -0
- data/spec/acceptance/organizer/context_failure_and_skipping_spec.rb +22 -0
- data/spec/acceptance/organizer/execute_spec.rb +21 -0
- data/spec/acceptance/organizer/reduce_case_spec.rb +65 -0
- data/spec/acceptance/organizer/reduce_if_else_spec.rb +60 -0
- data/spec/acceptance/organizer/reduce_while_spec.rb +96 -0
- data/spec/acceptance/skip_all_remaining_spec.rb +139 -0
- data/spec/action_optional_expected_keys_spec.rb +107 -0
- data/spec/context/inspect_spec.rb +13 -3
- data/spec/context_spec.rb +12 -0
- data/spec/i18n_localization_adapter_spec.rb +83 -0
- data/spec/localization_adapter_spec.rb +66 -83
- data/spec/spec_helper.rb +3 -0
- data/spec/test_doubles.rb +28 -0
- metadata +26 -15
|
@@ -0,0 +1,83 @@
|
|
|
1
|
+
require "spec_helper"
|
|
2
|
+
require 'test_doubles'
|
|
3
|
+
|
|
4
|
+
describe FunctionalLightService::I18n::LocalizationAdapter do
|
|
5
|
+
let(:action_class) { TestDoubles::AnAction }
|
|
6
|
+
let(:adapter) { described_class.new }
|
|
7
|
+
|
|
8
|
+
describe "#failure" do
|
|
9
|
+
subject { adapter.failure(message_or_key, action_class) }
|
|
10
|
+
|
|
11
|
+
context "when provided a Symbol" do
|
|
12
|
+
let(:message_or_key) { :not_found }
|
|
13
|
+
|
|
14
|
+
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")
|
|
34
|
+
end
|
|
35
|
+
end
|
|
36
|
+
|
|
37
|
+
context "when provided a String" do
|
|
38
|
+
let(:message_or_key) { "action failed" }
|
|
39
|
+
|
|
40
|
+
it "returns the message" do
|
|
41
|
+
expect(subject).to eq(message_or_key)
|
|
42
|
+
end
|
|
43
|
+
end
|
|
44
|
+
end
|
|
45
|
+
|
|
46
|
+
describe "#success" do
|
|
47
|
+
subject { adapter.success(message_or_key, action_class) }
|
|
48
|
+
|
|
49
|
+
context "when provided a Symbol" do
|
|
50
|
+
let(:message_or_key) { :not_found }
|
|
51
|
+
|
|
52
|
+
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")
|
|
72
|
+
end
|
|
73
|
+
end
|
|
74
|
+
|
|
75
|
+
context "when provided a String" do
|
|
76
|
+
let(:message_or_key) { "action failed" }
|
|
77
|
+
|
|
78
|
+
it "returns the message" do
|
|
79
|
+
expect(subject).to eq(message_or_key)
|
|
80
|
+
end
|
|
81
|
+
end
|
|
82
|
+
end
|
|
83
|
+
end
|
|
@@ -1,83 +1,66 @@
|
|
|
1
|
-
require "spec_helper"
|
|
2
|
-
require 'test_doubles'
|
|
3
|
-
|
|
4
|
-
describe FunctionalLightService::LocalizationAdapter do
|
|
5
|
-
let(:action_class) { TestDoubles::AnAction }
|
|
6
|
-
let(:adapter) { described_class.new }
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
subject = adapter.success(message_or_key,
|
|
68
|
-
action_class,
|
|
69
|
-
:i18n_variable => "value")
|
|
70
|
-
|
|
71
|
-
expect(subject).to eq("message")
|
|
72
|
-
end
|
|
73
|
-
end
|
|
74
|
-
|
|
75
|
-
context "when provided a String" do
|
|
76
|
-
let(:message_or_key) { "action failed" }
|
|
77
|
-
|
|
78
|
-
it "returns the message" do
|
|
79
|
-
expect(subject).to eq(message_or_key)
|
|
80
|
-
end
|
|
81
|
-
end
|
|
82
|
-
end
|
|
83
|
-
end
|
|
1
|
+
require "spec_helper"
|
|
2
|
+
require 'test_doubles'
|
|
3
|
+
|
|
4
|
+
describe FunctionalLightService::LocalizationAdapter do
|
|
5
|
+
let(:action_class) { TestDoubles::AnAction }
|
|
6
|
+
let(:adapter) { described_class.new }
|
|
7
|
+
|
|
8
|
+
before do
|
|
9
|
+
FunctionalLightService::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
|
+
|
|
23
|
+
after do
|
|
24
|
+
FunctionalLightService::LocalizationMap.instance.clear
|
|
25
|
+
end
|
|
26
|
+
|
|
27
|
+
describe "#failure" do
|
|
28
|
+
subject { adapter.failure(message_or_key, action_class) }
|
|
29
|
+
|
|
30
|
+
context "when provided a Symbol" do
|
|
31
|
+
let(:message_or_key) { :not_found }
|
|
32
|
+
|
|
33
|
+
it "translates the message" do
|
|
34
|
+
expect(subject).to eq("failure message")
|
|
35
|
+
end
|
|
36
|
+
end
|
|
37
|
+
|
|
38
|
+
context "when provided a String" do
|
|
39
|
+
let(:message_or_key) { "action failed" }
|
|
40
|
+
|
|
41
|
+
it "returns the message" do
|
|
42
|
+
expect(subject).to eq(message_or_key)
|
|
43
|
+
end
|
|
44
|
+
end
|
|
45
|
+
end
|
|
46
|
+
|
|
47
|
+
describe "#success" do
|
|
48
|
+
subject { adapter.success(message_or_key, action_class) }
|
|
49
|
+
|
|
50
|
+
context "when provided a Symbol" do
|
|
51
|
+
let(:message_or_key) { :not_found }
|
|
52
|
+
|
|
53
|
+
it "translates the message" do
|
|
54
|
+
expect(subject).to eq("success message")
|
|
55
|
+
end
|
|
56
|
+
end
|
|
57
|
+
|
|
58
|
+
context "when provided a String" do
|
|
59
|
+
let(:message_or_key) { "action failed" }
|
|
60
|
+
|
|
61
|
+
it "returns the message" do
|
|
62
|
+
expect(subject).to eq(message_or_key)
|
|
63
|
+
end
|
|
64
|
+
end
|
|
65
|
+
end
|
|
66
|
+
end
|
data/spec/spec_helper.rb
CHANGED
|
@@ -16,6 +16,9 @@ if ENV['RUN_COVERAGE_REPORT']
|
|
|
16
16
|
SimpleCov.formatter = SimpleCov::Formatter::CoberturaFormatter
|
|
17
17
|
end
|
|
18
18
|
|
|
19
|
+
# i18n non e' piu una dipendenza runtime della gem: viene caricata qui
|
|
20
|
+
# per testare l'adapter I18n e la selezione automatica in Configuration
|
|
21
|
+
require "i18n"
|
|
19
22
|
require "functional-light-service"
|
|
20
23
|
require "functional-light-service/testing"
|
|
21
24
|
require "functional-light-service/functional/null"
|
data/spec/test_doubles.rb
CHANGED
|
@@ -599,6 +599,34 @@ module TestDoubles
|
|
|
599
599
|
end
|
|
600
600
|
end
|
|
601
601
|
|
|
602
|
+
class AddsNumbersWithOptionalDefaults
|
|
603
|
+
extend FunctionalLightService::Action
|
|
604
|
+
|
|
605
|
+
expects :first_number
|
|
606
|
+
expects :second_number, :default => ->(ctx) { ctx[:first_number] + 7 }
|
|
607
|
+
expects :third_number, :default => 10
|
|
608
|
+
promises :total
|
|
609
|
+
|
|
610
|
+
executed do |ctx|
|
|
611
|
+
ctx.total = ctx.first_number + ctx.second_number + ctx.third_number
|
|
612
|
+
end
|
|
613
|
+
end
|
|
614
|
+
|
|
615
|
+
class OrganizerWithActionsUsingDefaults
|
|
616
|
+
extend FunctionalLightService::Organizer
|
|
617
|
+
|
|
618
|
+
def self.call
|
|
619
|
+
with(:first_number => 1, :number => 1).reduce(actions)
|
|
620
|
+
end
|
|
621
|
+
|
|
622
|
+
def self.actions
|
|
623
|
+
[
|
|
624
|
+
AddsNumbersWithOptionalDefaults,
|
|
625
|
+
AddToTotalAction
|
|
626
|
+
]
|
|
627
|
+
end
|
|
628
|
+
end
|
|
629
|
+
|
|
602
630
|
class AnOrganizerThatAddsToContext
|
|
603
631
|
extend FunctionalLightService::Organizer
|
|
604
632
|
|
metadata
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
|
2
2
|
name: functional-light-service
|
|
3
3
|
version: !ruby/object:Gem::Version
|
|
4
|
-
version: 6.
|
|
4
|
+
version: 6.2.0
|
|
5
5
|
platform: ruby
|
|
6
6
|
authors:
|
|
7
7
|
- Boscolo Michele
|
|
@@ -30,39 +30,39 @@ dependencies:
|
|
|
30
30
|
- !ruby/object:Gem::Version
|
|
31
31
|
version: '2'
|
|
32
32
|
- !ruby/object:Gem::Dependency
|
|
33
|
-
name:
|
|
33
|
+
name: logger
|
|
34
34
|
requirement: !ruby/object:Gem::Requirement
|
|
35
35
|
requirements:
|
|
36
36
|
- - "~>"
|
|
37
37
|
- !ruby/object:Gem::Version
|
|
38
|
-
version: '1.
|
|
39
|
-
- - ">="
|
|
40
|
-
- !ruby/object:Gem::Version
|
|
41
|
-
version: 1.8.11
|
|
38
|
+
version: '1.5'
|
|
42
39
|
type: :runtime
|
|
43
40
|
prerelease: false
|
|
44
41
|
version_requirements: !ruby/object:Gem::Requirement
|
|
45
42
|
requirements:
|
|
46
43
|
- - "~>"
|
|
47
44
|
- !ruby/object:Gem::Version
|
|
48
|
-
version: '1.
|
|
49
|
-
- - ">="
|
|
50
|
-
- !ruby/object:Gem::Version
|
|
51
|
-
version: 1.8.11
|
|
45
|
+
version: '1.5'
|
|
52
46
|
- !ruby/object:Gem::Dependency
|
|
53
|
-
name:
|
|
47
|
+
name: i18n
|
|
54
48
|
requirement: !ruby/object:Gem::Requirement
|
|
55
49
|
requirements:
|
|
56
50
|
- - "~>"
|
|
57
51
|
- !ruby/object:Gem::Version
|
|
58
|
-
version: '1.
|
|
59
|
-
|
|
52
|
+
version: '1.8'
|
|
53
|
+
- - ">="
|
|
54
|
+
- !ruby/object:Gem::Version
|
|
55
|
+
version: 1.8.11
|
|
56
|
+
type: :development
|
|
60
57
|
prerelease: false
|
|
61
58
|
version_requirements: !ruby/object:Gem::Requirement
|
|
62
59
|
requirements:
|
|
63
60
|
- - "~>"
|
|
64
61
|
- !ruby/object:Gem::Version
|
|
65
|
-
version: '1.
|
|
62
|
+
version: '1.8'
|
|
63
|
+
- - ">="
|
|
64
|
+
- !ruby/object:Gem::Version
|
|
65
|
+
version: 1.8.11
|
|
66
66
|
- !ruby/object:Gem::Dependency
|
|
67
67
|
name: rake
|
|
68
68
|
requirement: !ruby/object:Gem::Requirement
|
|
@@ -232,12 +232,17 @@ files:
|
|
|
232
232
|
- lib/functional-light-service/functional/option.rb
|
|
233
233
|
- lib/functional-light-service/functional/result.rb
|
|
234
234
|
- lib/functional-light-service/functional/sequencer.rb
|
|
235
|
+
- lib/functional-light-service/i18n/localization_adapter.rb
|
|
235
236
|
- lib/functional-light-service/localization_adapter.rb
|
|
237
|
+
- lib/functional-light-service/localization_map.rb
|
|
236
238
|
- lib/functional-light-service/organizer.rb
|
|
237
239
|
- lib/functional-light-service/organizer/execute.rb
|
|
238
240
|
- lib/functional-light-service/organizer/iterate.rb
|
|
241
|
+
- lib/functional-light-service/organizer/reduce_case.rb
|
|
239
242
|
- lib/functional-light-service/organizer/reduce_if.rb
|
|
243
|
+
- lib/functional-light-service/organizer/reduce_if_else.rb
|
|
240
244
|
- lib/functional-light-service/organizer/reduce_until.rb
|
|
245
|
+
- lib/functional-light-service/organizer/reduce_while.rb
|
|
241
246
|
- lib/functional-light-service/organizer/scoped_reducable.rb
|
|
242
247
|
- lib/functional-light-service/organizer/with_callback.rb
|
|
243
248
|
- lib/functional-light-service/organizer/with_reducer.rb
|
|
@@ -265,14 +270,19 @@ files:
|
|
|
265
270
|
- spec/acceptance/organizer/context_failure_and_skipping_spec.rb
|
|
266
271
|
- spec/acceptance/organizer/execute_spec.rb
|
|
267
272
|
- spec/acceptance/organizer/iterate_spec.rb
|
|
273
|
+
- spec/acceptance/organizer/reduce_case_spec.rb
|
|
274
|
+
- spec/acceptance/organizer/reduce_if_else_spec.rb
|
|
268
275
|
- spec/acceptance/organizer/reduce_if_spec.rb
|
|
269
276
|
- spec/acceptance/organizer/reduce_until_spec.rb
|
|
277
|
+
- spec/acceptance/organizer/reduce_while_spec.rb
|
|
270
278
|
- spec/acceptance/organizer/with_callback_spec.rb
|
|
271
279
|
- spec/acceptance/organizer_entry_point_spec.rb
|
|
272
280
|
- spec/acceptance/rollback_spec.rb
|
|
281
|
+
- spec/acceptance/skip_all_remaining_spec.rb
|
|
273
282
|
- spec/acceptance/testing/context_factory_spec.rb
|
|
274
283
|
- spec/action_expected_keys_spec.rb
|
|
275
284
|
- spec/action_expects_and_promises_spec.rb
|
|
285
|
+
- spec/action_optional_expected_keys_spec.rb
|
|
276
286
|
- spec/action_promised_keys_spec.rb
|
|
277
287
|
- spec/action_spec.rb
|
|
278
288
|
- spec/context/inspect_spec.rb
|
|
@@ -280,6 +290,7 @@ files:
|
|
|
280
290
|
- spec/examples/amount_spec.rb
|
|
281
291
|
- spec/examples/controller_spec.rb
|
|
282
292
|
- spec/examples/validate_address_spec.rb
|
|
293
|
+
- spec/i18n_localization_adapter_spec.rb
|
|
283
294
|
- spec/lib/deterministic/class_mixin_spec.rb
|
|
284
295
|
- spec/lib/deterministic/currify_spec.rb
|
|
285
296
|
- spec/lib/deterministic/monad_axioms.rb
|
|
@@ -334,7 +345,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
|
334
345
|
- !ruby/object:Gem::Version
|
|
335
346
|
version: '0'
|
|
336
347
|
requirements: []
|
|
337
|
-
rubygems_version:
|
|
348
|
+
rubygems_version: 3.6.9
|
|
338
349
|
specification_version: 4
|
|
339
350
|
summary: A service skeleton with an emphasis on simplicity with a pinch a functional
|
|
340
351
|
programming
|