dry-effects 0.1.4 → 0.1.5

Sign up to get free protection for your applications and to get access to all the features.
@@ -1,51 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- class Operation
4
- include Dry::Effects.State(:counter)
5
- include Dry::Effects.Cmp(:feature_enabled)
6
-
7
- def call
8
- if feature_enabled?
9
- self.counter += 10
10
- :with_feature
11
- else
12
- self.counter += 1
13
- :without_feature
14
- end
15
- end
16
- end
17
-
18
- module Handler
19
- include Dry::Effects::Handler.State(:counter, as: :with_counter)
20
- include Dry::Effects::Handler.Cmp(:feature_enabled, as: :test_feature)
21
- end
22
-
23
- class CmpState
24
- include Handler
25
-
26
- def initialize
27
- @operation = Operation.new
28
- end
29
-
30
- def call
31
- test_feature { with_counter(0) { @operation.call } }
32
- end
33
- end
34
-
35
- class StateCmp
36
- include Handler
37
-
38
- def initialize
39
- @operation = Operation.new
40
- end
41
-
42
- def call
43
- with_counter(0) { test_feature { @operation.call } }
44
- end
45
- end
46
-
47
- cmp_then_state = CmpState.new
48
- state_then_cmp = State.Cmp.new
49
-
50
- cmp_then_state.() # => [[1, :without_feature], [10, :with_feature]]
51
- state_then_cmp.() # => [11, [:without_feature, :with_feature]]
@@ -1,29 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- class Operation
4
- include Dry::Effects.State(:counter)
5
-
6
- def call
7
- 3.times do
8
- self.counter += 1
9
- end
10
-
11
- :done
12
- end
13
- end
14
-
15
- class Wrapper
16
- include Dry::Effects::Handler.State(:counter)
17
-
18
- def initialize
19
- @operation = Operation.new
20
- end
21
-
22
- def call
23
- with_counter(0) { @operation.call }
24
- end
25
- end
26
-
27
- __END__
28
-
29
- Wrapper.new.call # => [3, :done]
@@ -1,2 +0,0 @@
1
- name: dry-effects
2
- codacy_id: 158a8a584a3845eba4a67a71ad540210