dry-effects 0.1.1 → 0.1.2

Sign up to get free protection for your applications and to get access to all the features.
Files changed (37) hide show
  1. checksums.yaml +4 -4
  2. data/.github/ISSUE_TEMPLATE/---bug-report.md +1 -5
  3. data/.rubocop.yml +6 -0
  4. data/CHANGELOG.md +8 -0
  5. data/docsite/source/effects/interrupt.html.md +4 -4
  6. data/lib/dry/effects/all.rb +3 -2
  7. data/lib/dry/effects/effect.rb +23 -2
  8. data/lib/dry/effects/effects/async.rb +2 -2
  9. data/lib/dry/effects/effects/cache.rb +4 -2
  10. data/lib/dry/effects/effects/current_time.rb +6 -4
  11. data/lib/dry/effects/effects/state.rb +1 -1
  12. data/lib/dry/effects/effects/timestamp.rb +1 -1
  13. data/lib/dry/effects/frame.rb +11 -5
  14. data/lib/dry/effects/handler.rb +10 -2
  15. data/lib/dry/effects/initializer.rb +4 -2
  16. data/lib/dry/effects/provider.rb +24 -1
  17. data/lib/dry/effects/provider/class_interface.rb +5 -5
  18. data/lib/dry/effects/providers/async.rb +3 -2
  19. data/lib/dry/effects/providers/cache.rb +3 -3
  20. data/lib/dry/effects/providers/cmp.rb +5 -5
  21. data/lib/dry/effects/providers/current_time.rb +6 -4
  22. data/lib/dry/effects/providers/defer.rb +8 -7
  23. data/lib/dry/effects/providers/env.rb +3 -3
  24. data/lib/dry/effects/providers/fork.rb +3 -2
  25. data/lib/dry/effects/providers/implicit.rb +3 -3
  26. data/lib/dry/effects/providers/interrupt.rb +1 -1
  27. data/lib/dry/effects/providers/lock.rb +2 -2
  28. data/lib/dry/effects/providers/parallel.rb +6 -3
  29. data/lib/dry/effects/providers/reader.rb +5 -5
  30. data/lib/dry/effects/providers/resolve.rb +3 -3
  31. data/lib/dry/effects/providers/retry.rb +2 -2
  32. data/lib/dry/effects/providers/state.rb +2 -2
  33. data/lib/dry/effects/providers/timeout.rb +2 -2
  34. data/lib/dry/effects/providers/timestamp.rb +5 -4
  35. data/lib/dry/effects/stack.rb +10 -10
  36. data/lib/dry/effects/version.rb +1 -1
  37. metadata +2 -2
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: a830eaa18fc97f22045d9f3aaffe905729749e6a69d05b0d4e5e7de435a3f5ab
4
- data.tar.gz: 414d49b7b5e1be23f327aa33511a575153aefc5ff50dc429def6739b81cb4571
3
+ metadata.gz: 2b27bb0be01cba09f3ce2957a46f61c89ab25f3ff06cfc4ecea30b20ebaa9817
4
+ data.tar.gz: d9066e6045bdf2c57f4102d17aefdd4733d4c97698740eafc463881f675770b7
5
5
  SHA512:
6
- metadata.gz: d599d1e85269f9a65bfdef7d9b6c60b37c91c1b340c8b18d2b8e40980be4a312a8cd9e5573f905b6b84a0d800aaac480b3eb422c6cc3d63eaa2b5578690b801e
7
- data.tar.gz: 39809721fe1bb1d1b0e190fd75cf58c772ad36fe4f6ecec734da4e48a2226923da084ddb0425589bdff781c9640a7ba4323c53b8a72f4bb82c9017f2784adadf
6
+ metadata.gz: 27e4ad1dbdb3dca88b20e8da65828060961319d1b16e21144c5361df94078018c5a2626ddc5387efe70cfc6e4d580da3c856ea703ba8b26be7c02d9943c8d579
7
+ data.tar.gz: 1eb0f585c19f17cf75c9411a297e460107654af280b414bb9be582054de33e09117ff6d52b429cce0df221e7bb9dc6e90ee8df53a84536b26cf6b36186077a73
@@ -9,11 +9,7 @@ assignees: ''
9
9
 
10
10
  **Before you submit this: WE ONLY ACCEPT BUG REPORTS AND FEATURE REQUESTS**
11
11
 
12
- For more information see [our contribution guidelines](https://github.com/rom-rb/rom/blob/master/CONTRIBUTING.md)
13
-
14
- **Before you report**
15
-
16
- :warning: If you have a problem related to a schema, please **report it under [dry-schema issues](https://github.com/dry-rb/dry-schema/issues/new?assignees=&labels=bug&template=---bug-report.md&title=)** instead.
12
+ For more information see `CONTRIBUTING.md`.
17
13
 
18
14
  **Describe the bug**
19
15
 
data/.rubocop.yml CHANGED
@@ -87,3 +87,9 @@ Naming/MethodName:
87
87
 
88
88
  Style/AsciiComments:
89
89
  Enabled: false
90
+
91
+ Style/DateTime:
92
+ Enabled: false
93
+
94
+ Style/IfUnlessModifier:
95
+ Enabled: false
data/CHANGELOG.md CHANGED
@@ -1,3 +1,11 @@
1
+ # v0.1.2 - 2019-12-15
2
+
3
+ ## Fixed
4
+
5
+ - Keyword warnings issued by Ruby 2.7 (flash-gordon)
6
+
7
+ [Compare v0.1.1...v0.1.2](https://github.com/dry-rb/dry-effects/compare/v0.1.1...v0.1.2)
8
+
1
9
  # v0.1.1 - 2019-11-30
2
10
 
3
11
  ## Added
@@ -17,14 +17,14 @@ class RunDivision
17
17
  include Dry::Effects::Handler.Interrupt(:division_by_zero, as: :catch_zero_division)
18
18
 
19
19
  def call
20
- success, answer = catch_zero_division do
20
+ error, answer = catch_zero_division do
21
21
  yield
22
22
  end
23
23
 
24
- if success
25
- answer
26
- else
24
+ if error
27
25
  :error
26
+ else
27
+ answer
28
28
  end
29
29
  end
30
30
  end
@@ -30,6 +30,7 @@ module Dry
30
30
  ::Dry::Effects.effects[key].new(*args).freeze
31
31
  end
32
32
  end
33
+ ruby2_keywords(class_name) if respond_to?(:ruby2_keywords, true)
33
34
  end
34
35
  end
35
36
 
@@ -39,8 +40,8 @@ module Dry
39
40
  Providers.const_get(Inflector.camelize(key))
40
41
  end
41
42
 
42
- Handler.singleton_class.send(:define_method, class_name) do |*args|
43
- ::Dry::Effects.providers[key].mixin(*args)
43
+ Handler.singleton_class.send(:define_method, class_name) do |*args, **kwargs|
44
+ ::Dry::Effects.providers[key].mixin(*args, **kwargs)
44
45
  end
45
46
  end
46
47
  end
@@ -8,7 +8,7 @@ module Dry
8
8
  class Effect
9
9
  extend Initializer
10
10
 
11
- include ::Dry::Equalizer(:type, :name, :payload)
11
+ include ::Dry::Equalizer(:type, :name, :payload, :keywords)
12
12
 
13
13
  option :type
14
14
 
@@ -16,6 +16,8 @@ module Dry
16
16
 
17
17
  option :payload, default: -> { EMPTY_ARRAY }
18
18
 
19
+ option :keywords, default: -> { EMPTY_HASH }
20
+
19
21
  def payload(*payload)
20
22
  if payload.empty?
21
23
  @payload
@@ -23,7 +25,26 @@ module Dry
23
25
  with(payload: payload)
24
26
  end
25
27
  end
26
- alias_method :call, :payload
28
+
29
+ def keywords(**keywords)
30
+ if keywords.empty?
31
+ @keywords
32
+ else
33
+ with(keywords: @keywords.merge(keywords))
34
+ end
35
+ end
36
+
37
+ def call(*args, **kwargs)
38
+ if args.empty?
39
+ if kwargs.empty?
40
+ self
41
+ else
42
+ keywords(**kwargs)
43
+ end
44
+ else
45
+ with(payload: args, keywords: @keywords.merge(kwargs))
46
+ end
47
+ end
27
48
  end
28
49
  end
29
50
  end
@@ -12,8 +12,8 @@ module Dry
12
12
 
13
13
  def initialize
14
14
  module_eval do
15
- define_method(:async) { |&block| ::Dry::Effects.yield(Async.payload(block)) }
16
- define_method(:await) { |task| ::Dry::Effects.yield(Await.payload(task)) }
15
+ define_method(:async) { |&block| ::Dry::Effects.yield(Async.(block)) }
16
+ define_method(:await) { |task| ::Dry::Effects.yield(Await.(task)) }
17
17
  end
18
18
  end
19
19
  end
@@ -10,8 +10,10 @@ module Dry
10
10
  option :scope
11
11
  end
12
12
 
13
- def initialize(scope, shared: false)
14
- if scope.is_a?(::Hash)
13
+ def initialize(scope = nil, shared: false, **kw)
14
+ if !kw.empty?
15
+ scope, as = kw.to_a[0]
16
+ elsif scope.is_a?(::Hash)
15
17
  scope, as = scope.to_a[0]
16
18
  else
17
19
  as = :cache
@@ -13,19 +13,21 @@ module Dry
13
13
  if kwargs.empty?
14
14
  CurrentTime
15
15
  else
16
- CurrentTime.payload(kwargs)
16
+ CurrentTime.(**kwargs)
17
17
  end
18
18
  end
19
19
 
20
- def initialize(options = EMPTY_HASH)
20
+ def initialize(**options)
21
21
  module_eval do
22
- define_method(:current_time) do |round: Undefined, refresh: false|
22
+ define_method(:current_time) do |opts = EMPTY_HASH|
23
+ round = opts.fetch(:round, Undefined)
24
+ refresh = opts.fetch(:refresh, false)
23
25
  round_to = Undefined.coalesce(round, options.fetch(:round, Undefined))
24
26
 
25
27
  if Undefined.equal?(round_to) && refresh.equal?(false)
26
28
  effect = CurrentTime
27
29
  else
28
- effect = CurrentTime.payload(round_to: round_to, refresh: refresh)
30
+ effect = CurrentTime.(round_to: round_to, refresh: refresh)
29
31
  end
30
32
 
31
33
  ::Dry::Effects.yield(effect)
@@ -48,7 +48,7 @@ module Dry
48
48
 
49
49
  if writer
50
50
  define_method(:"#{as}=") do |value|
51
- ::Dry::Effects.yield(write.(value))
51
+ ::Dry::Effects.yield(write.(value: value))
52
52
  end
53
53
  end
54
54
  end
@@ -16,7 +16,7 @@ module Dry
16
16
  if Undefined.equal?(round_to)
17
17
  ::Dry::Effects.yield(Timestamp)
18
18
  else
19
- ::Dry::Effects.yield(Timestamp.payload(round_to: round_to))
19
+ ::Dry::Effects.yield(Timestamp.keywords(round_to: round_to))
20
20
  end
21
21
  end
22
22
  end
@@ -66,13 +66,19 @@ module Dry
66
66
  # @param [Array<Object>] args Handler arguments
67
67
  # @param [Proc] block Program to run
68
68
  # @api private
69
- def call(args = EMPTY_ARRAY, &block)
69
+ def call(*args, &block)
70
70
  stack = Frame.stack
71
+ prov = provider.dup
72
+ was_empty = stack.empty?
71
73
 
72
- if stack.empty?
73
- stack.push(provider.dup, args) { Frame.spawn_fiber(stack, &block) }
74
- else
75
- stack.push(provider.dup, args, &block)
74
+ prov.(*args) do
75
+ if was_empty
76
+ stack.push(prov) do
77
+ Frame.spawn_fiber(stack, &block)
78
+ end
79
+ else
80
+ stack.push(prov, &block)
81
+ end
76
82
  end
77
83
  end
78
84
  end
@@ -12,8 +12,16 @@ module Dry
12
12
  @frame = Frame.new(provider)
13
13
  end
14
14
 
15
- def call(*args, &block)
16
- frame.(args, &block)
15
+ if RUBY_VERSION >= '2.7'
16
+ class_eval(<<~RUBY, __FILE__, __LINE__ + 1)
17
+ def call(...)
18
+ frame.(...)
19
+ end
20
+ RUBY
21
+ else
22
+ def call(*args, &block)
23
+ frame.(*args, &block)
24
+ end
17
25
  end
18
26
 
19
27
  def to_s
@@ -14,6 +14,7 @@ module Dry
14
14
  __define_with__
15
15
  end
16
16
  end
17
+ ruby2_keywords(:param) if respond_to?(:ruby2_keywords, true)
17
18
 
18
19
  # @api private
19
20
  def option(*)
@@ -22,6 +23,7 @@ module Dry
22
23
  @has_options = true
23
24
  end
24
25
  end
26
+ ruby2_keywords(:option) if respond_to?(:ruby2_keywords, true)
25
27
 
26
28
  # @api private
27
29
  def params_arity
@@ -52,11 +54,11 @@ module Dry
52
54
  undef_method(:with) if method_defined?(:with)
53
55
 
54
56
  class_eval(<<-RUBY, __FILE__, __LINE__ + 1)
55
- def with(new_options = EMPTY_HASH)
57
+ def with(**new_options)
56
58
  if new_options.empty?
57
59
  self
58
60
  else
59
- self.class.new(#{seq_names}options.merge(new_options))
61
+ self.class.new(#{seq_names}**options, **new_options)
60
62
  end
61
63
  end
62
64
  RUBY
@@ -15,7 +15,7 @@ module Dry
15
15
  # yield the block with the handler installed
16
16
  #
17
17
  # @api private
18
- def call(_stack)
18
+ def call
19
19
  yield
20
20
  end
21
21
 
@@ -43,6 +43,29 @@ module Dry
43
43
  def provide?(effect)
44
44
  type.equal?(effect.type)
45
45
  end
46
+
47
+ # @return [String]
48
+ # @api public
49
+ def inspect
50
+ "#<#{self.class.name} #{represent}>"
51
+ end
52
+
53
+ private
54
+
55
+ def value_with_options_from_args(args)
56
+ case args.size
57
+ when 2
58
+ args
59
+ when 1
60
+ if args[0].is_a?(::Hash)
61
+ [Undefined, args[0]]
62
+ else
63
+ [args[0], EMPTY_HASH]
64
+ end
65
+ when 0
66
+ [Undefined, EMPTY_HASH]
67
+ end
68
+ end
46
69
  end
47
70
  end
48
71
  end
@@ -40,15 +40,15 @@ module Dry
40
40
  end
41
41
  end
42
42
 
43
- def mixin(*args, **kwargs)
44
- handle_method = handle_method(*args, **kwargs)
43
+ def mixin(*as, **kw)
44
+ handle_method = handle_method(*as, **kw)
45
45
 
46
- provider = new(*args, **kwargs).freeze
46
+ provider = new(*as, **kw).freeze
47
47
  frame = Frame.new(provider)
48
48
 
49
49
  ::Module.new do
50
- define_method(handle_method) do |*xs, &block|
51
- frame.(xs, &block)
50
+ define_method(handle_method) do |*args, &block|
51
+ frame.(*args, &block)
52
52
  end
53
53
  end
54
54
  end
@@ -1,6 +1,7 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  require 'dry/effects/provider'
4
+ require 'dry/effects/frame'
4
5
 
5
6
  module Dry
6
7
  module Effects
@@ -23,8 +24,8 @@ module Dry
23
24
  # Yield the block with the handler installed
24
25
  #
25
26
  # @api private
26
- def call(stack)
27
- @stack = stack
27
+ def call
28
+ @stack = Frame.stack
28
29
  super
29
30
  nil
30
31
  end
@@ -7,7 +7,7 @@ module Dry
7
7
  module Effects
8
8
  module Providers
9
9
  class Cache < Provider[:cache]
10
- include Dry::Equalizer(:scope, :cache)
10
+ include ::Dry::Equalizer(:scope, :cache, inspect: false)
11
11
 
12
12
  param :scope
13
13
 
@@ -24,9 +24,9 @@ module Dry
24
24
  # Yield the block with the handler installed
25
25
  #
26
26
  # @api private
27
- def call(stack, cache = EMPTY_HASH.dup)
27
+ def call(cache = EMPTY_HASH.dup)
28
28
  @cache = cache
29
- super(stack)
29
+ yield
30
30
  end
31
31
 
32
32
  # @param [Effect] effect
@@ -6,7 +6,7 @@ module Dry
6
6
  module Effects
7
7
  module Providers
8
8
  class Cmp < Provider[:cmp]
9
- include Dry::Equalizer(:id, :value)
9
+ include ::Dry::Equalizer(:id, :value, inspect: false)
10
10
 
11
11
  attr_reader :value
12
12
 
@@ -20,15 +20,15 @@ module Dry
20
20
  #
21
21
  # @return [Array(Any, Any)]
22
22
  # @api private
23
- def call(stack, value = Undefined)
23
+ def call(value = Undefined)
24
24
  if Undefined.equal?(value)
25
25
  @value = false
26
- first = super(stack)
26
+ first = yield
27
27
  @value = true
28
- [first, super(stack)]
28
+ [first, yield]
29
29
  else
30
30
  @value = value
31
- super(stack)
31
+ yield
32
32
  end
33
33
  end
34
34
 
@@ -1,5 +1,6 @@
1
1
  # frozen_string_literal: true
2
2
 
3
+ require 'time'
3
4
  require 'dry/effects/provider'
4
5
  require 'dry/effects/providers/current_time/time_generators'
5
6
 
@@ -7,7 +8,7 @@ module Dry
7
8
  module Effects
8
9
  module Providers
9
10
  class CurrentTime < Provider[:current_time]
10
- include Dry::Equalizer(:fixed, :round)
11
+ include ::Dry::Equalizer(:fixed, :round, inspect: false)
11
12
  include TimeGenetators
12
13
 
13
14
  Locate = Effect.new(type: :current_time, name: :locate)
@@ -23,9 +24,10 @@ module Dry
23
24
  # Yield the block with the handler installed
24
25
  #
25
26
  # @api private
26
- def call(stack, generator = Undefined, **options)
27
- @generator = build_generator(generator, **options)
28
- super(stack)
27
+ def call(*args)
28
+ gen, options = value_with_options_from_args(args)
29
+ @generator = build_generator(gen, **options)
30
+ yield
29
31
  end
30
32
 
31
33
  def current_time(round_to: Undefined, **options)
@@ -2,12 +2,13 @@
2
2
 
3
3
  require 'concurrent/promise'
4
4
  require 'dry/effects/provider'
5
+ require 'dry/effects/frame'
5
6
 
6
7
  module Dry
7
8
  module Effects
8
9
  module Providers
9
10
  class Defer < Provider[:defer]
10
- include Dry::Equalizer(:executor)
11
+ include ::Dry::Equalizer(:executor, inspect: false)
11
12
 
12
13
  option :executor, default: -> { :io }
13
14
 
@@ -50,21 +51,21 @@ module Dry
50
51
  # Yield the block with the handler installed
51
52
  #
52
53
  # @api private
53
- def call(stack, executor: Undefined)
54
- unless Undefined.equal?(executor)
55
- @executor = executor
54
+ def call(options = { executor: Undefined })
55
+ unless Undefined.equal?(options[:executor])
56
+ @executor = options[:executor]
56
57
  end
57
58
 
58
- @stack = stack
59
+ @stack = Frame.stack
59
60
  @later_calls = []
60
- super(stack)
61
+ yield
61
62
  ensure
62
63
  later_calls.each(&:execute)
63
64
  end
64
65
 
65
66
  def dup
66
67
  if defined? @later_calls
67
- super.tap { |p| p.instance_exec { @later_calls = EMPTY_ARRAY } }
68
+ super.tap { |p| p.instance_variable_set(:@later_calls, EMPTY_ARRAY) }
68
69
  else
69
70
  super
70
71
  end
@@ -7,7 +7,7 @@ module Dry
7
7
  module Effects
8
8
  module Providers
9
9
  class Env < Provider[:env]
10
- include Dry::Equalizer(:values, :dynamic)
10
+ include ::Dry::Equalizer(:values, :dynamic, inspect: false)
11
11
 
12
12
  Locate = Effect.new(type: :env, name: :locate)
13
13
 
@@ -41,7 +41,7 @@ module Dry
41
41
  # Yield the block with the handler installed
42
42
  #
43
43
  # @api private
44
- def call(stack, values = EMPTY_HASH, options = EMPTY_HASH)
44
+ def call(values = EMPTY_HASH, options = EMPTY_HASH)
45
45
  unless values.empty?
46
46
  @values = @values.merge(values)
47
47
  end
@@ -52,7 +52,7 @@ module Dry
52
52
  @parent = EMPTY_HASH
53
53
  end
54
54
 
55
- super(stack)
55
+ yield
56
56
  end
57
57
 
58
58
  # @param [Effect] effect
@@ -1,6 +1,7 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  require 'dry/effects/provider'
4
+ require 'dry/effects/frame'
4
5
 
5
6
  module Dry
6
7
  module Effects
@@ -13,8 +14,8 @@ module Dry
13
14
  -> &cont { Frame.spawn_fiber(stack.dup, &cont) }
14
15
  end
15
16
 
16
- def call(stack)
17
- @stack = stack
17
+ def call
18
+ @stack = Frame.stack
18
19
  super
19
20
  end
20
21
  end
@@ -6,7 +6,7 @@ module Dry
6
6
  module Effects
7
7
  module Providers
8
8
  class Implicit < Provider[:implicit]
9
- include Dry::Equalizer(:name, :static, :dictionary)
9
+ include ::Dry::Equalizer(:name, :static, :dictionary, inspect: false)
10
10
 
11
11
  param :dependency
12
12
 
@@ -21,14 +21,14 @@ module Dry
21
21
  # Yield the block with the handler installed
22
22
  #
23
23
  # @api private
24
- def call(stack, dynamic = EMPTY_HASH)
24
+ def call(dynamic = EMPTY_HASH)
25
25
  if dynamic.empty?
26
26
  @dictionary = static
27
27
  else
28
28
  @dictionary = static.merge(dynamic)
29
29
  end
30
30
 
31
- super(stack)
31
+ yield
32
32
  end
33
33
 
34
34
  # @param [Effect] effect
@@ -17,7 +17,7 @@ module Dry
17
17
  # Yield the block with the handler installed
18
18
  #
19
19
  # @api private
20
- def call(_stack)
20
+ def call
21
21
  [false, yield]
22
22
  rescue halt => e
23
23
  [true, e.payload[0]]
@@ -89,7 +89,7 @@ module Dry
89
89
  # Yield the block with the handler installed
90
90
  #
91
91
  # @api private
92
- def call(stack, backend = Undefined)
92
+ def call(backend = Undefined)
93
93
  backend_replace = Undefined.default(backend) do
94
94
  parent = ::Dry::Effects.yield(Locate) { Undefined }
95
95
  Undefined.map(parent, &:backend)
@@ -97,7 +97,7 @@ module Dry
97
97
 
98
98
  with_backend(backend_replace) do
99
99
  begin
100
- super(stack)
100
+ yield
101
101
  ensure
102
102
  owned.each { |handle| unlock(handle) }
103
103
  end
@@ -2,11 +2,14 @@
2
2
 
3
3
  require 'concurrent/promise'
4
4
  require 'dry/effects/provider'
5
+ require 'dry/effects/frame'
5
6
 
6
7
  module Dry
7
8
  module Effects
8
9
  module Providers
9
10
  class Parallel < Provider[:parallel]
11
+ include ::Dry::Equalizer(:executor, inspect: false)
12
+
10
13
  option :executor, default: -> { :io }
11
14
 
12
15
  attr_reader :stack
@@ -27,9 +30,9 @@ module Dry
27
30
  # Yield the block with the handler installed
28
31
  #
29
32
  # @api private
30
- def call(stack)
31
- @stack = stack
32
- super
33
+ def call
34
+ @stack = Frame.stack
35
+ yield
33
36
  end
34
37
  end
35
38
  end
@@ -10,13 +10,13 @@ module Dry
10
10
  Undefined.default(as) { :"with_#{scope}" }
11
11
  end
12
12
 
13
- Any = Object.new.tap { |any|
13
+ Any = ::Object.new.tap { |any|
14
14
  def any.===(_)
15
15
  true
16
16
  end
17
17
  }.freeze
18
18
 
19
- include Dry::Equalizer(:scope, :state)
19
+ include ::Dry::Equalizer(:scope, :state, inspect: false)
20
20
 
21
21
  attr_reader :state
22
22
 
@@ -24,7 +24,7 @@ module Dry
24
24
 
25
25
  option :type, as: :state_type, default: -> { Any }
26
26
 
27
- def initialize(*)
27
+ def initialize(*, **)
28
28
  super
29
29
 
30
30
  @state = Undefined
@@ -37,11 +37,11 @@ module Dry
37
37
  # Yield the block with the handler installed
38
38
  #
39
39
  # @api private
40
- def call(stack, state)
40
+ def call(state)
41
41
  case state
42
42
  when state_type
43
43
  @state = state
44
- super(stack)
44
+ yield
45
45
  else
46
46
  raise Errors::InvalidValueError.new(state, scope)
47
47
  end
@@ -11,7 +11,7 @@ module Dry
11
11
  Undefined.default(as, :provide)
12
12
  end
13
13
 
14
- include Dry::Equalizer(:static, :parent, :dynamic)
14
+ include Dry::Equalizer(:static, :parent, :dynamic, inspect: false)
15
15
 
16
16
  Locate = Effect.new(type: :resolve, name: :locate)
17
17
 
@@ -49,7 +49,7 @@ module Dry
49
49
  # Yield the block with the handler installed
50
50
  #
51
51
  # @api private
52
- def call(stack, dynamic = EMPTY_HASH, options = EMPTY_HASH)
52
+ def call(dynamic = EMPTY_HASH, options = EMPTY_HASH)
53
53
  @dynamic = dynamic
54
54
 
55
55
  if options.fetch(:overridable, false)
@@ -58,7 +58,7 @@ module Dry
58
58
  @parent = nil
59
59
  end
60
60
 
61
- super(stack)
61
+ yield
62
62
  ensure
63
63
  @dynamic = EMPTY_HASH
64
64
  end
@@ -7,7 +7,7 @@ module Dry
7
7
  module Effects
8
8
  module Providers
9
9
  class Retry < Provider[:retry]
10
- include Dry::Equalizer(:scope, :limit, :attempts)
10
+ include Dry::Equalizer(:scope, :limit, :attempts, inspect: false)
11
11
 
12
12
  param :scope
13
13
 
@@ -18,7 +18,7 @@ module Dry
18
18
  # Yield the block with the handler installed
19
19
  #
20
20
  # @api private
21
- def call(_, limit)
21
+ def call(limit)
22
22
  @limit = limit
23
23
  @attempts = 0
24
24
 
@@ -7,7 +7,7 @@ module Dry
7
7
  module Effects
8
8
  module Providers
9
9
  class State < Reader[:state]
10
- def write(value)
10
+ def write(value:)
11
11
  case value
12
12
  when state_type
13
13
  @state = value
@@ -19,7 +19,7 @@ module Dry
19
19
  # Yield the block with the handler installed
20
20
  #
21
21
  # @api private
22
- def call(stack, state = Undefined)
22
+ def call(state = Undefined)
23
23
  r = super
24
24
  [self.state, r]
25
25
  end
@@ -25,10 +25,10 @@ module Dry
25
25
  # Yield the block with the handler installed
26
26
  #
27
27
  # @api private
28
- def call(stack, timeout)
28
+ def call(timeout)
29
29
  @time_out_at = read_clock + timeout
30
30
 
31
- super(stack)
31
+ yield
32
32
  end
33
33
 
34
34
  # @param [Effect] effect
@@ -19,9 +19,10 @@ module Dry
19
19
  # Yield the block with the handler installed
20
20
  #
21
21
  # @api private
22
- def call(stack, generator = Undefined, **options)
23
- @generator = build_generator(generator, **options)
24
- super(stack)
22
+ def call(*args)
23
+ gen, options = value_with_options_from_args(args)
24
+ @generator = build_generator(gen, **options)
25
+ yield
25
26
  end
26
27
 
27
28
  def timestamp(round_to: Undefined, **options)
@@ -56,7 +57,7 @@ module Dry
56
57
  end
57
58
 
58
59
  if !parent.nil?
59
- -> options { parent.timestamp(options) }
60
+ -> **options { parent.timestamp(**options) }
60
61
  elsif !Undefined.equal?(generator)
61
62
  generator
62
63
  elsif !Undefined.equal?(step)
@@ -15,7 +15,11 @@ module Dry
15
15
 
16
16
  def call(effect)
17
17
  if effect.is_a?(Effect) && (provider = provider(effect))
18
- provider.public_send(effect.name, *effect.payload)
18
+ if effect.keywords.empty?
19
+ provider.public_send(effect.name, *effect.payload)
20
+ else
21
+ provider.public_send(effect.name, *effect.payload, **effect.keywords)
22
+ end
19
23
  else
20
24
  yield
21
25
  end
@@ -23,15 +27,11 @@ module Dry
23
27
  Instructions::Raise.new(e)
24
28
  end
25
29
 
26
- def push(provider, args)
27
- provider.(self, *args) do
28
- begin
29
- providers.unshift(provider)
30
- yield
31
- ensure
32
- providers.shift
33
- end
34
- end
30
+ def push(provider)
31
+ providers.unshift(provider)
32
+ yield
33
+ ensure
34
+ providers.shift
35
35
  end
36
36
 
37
37
  def provider(effect)
@@ -2,6 +2,6 @@
2
2
 
3
3
  module Dry
4
4
  module Effects
5
- VERSION = '0.1.1'
5
+ VERSION = '0.1.2'
6
6
  end
7
7
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: dry-effects
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.1
4
+ version: 0.1.2
5
5
  platform: ruby
6
6
  authors:
7
7
  - Nikita Shilnikov
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2019-11-30 00:00:00.000000000 Z
11
+ date: 2019-12-15 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: concurrent-ruby