dry-mutations 0.8.10 → 0.8.11

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: ac8d9e2e1039e49362a9812bbe1a6341d62fc75d
4
- data.tar.gz: 5bbdaaba082b21092fd525b47931c94354741011
3
+ metadata.gz: 38e022b61eedee83ed6710525c92bb37aeda3313
4
+ data.tar.gz: 4fa39a230fc3f8929247c425b2d29aba7e5675d0
5
5
  SHA512:
6
- metadata.gz: 5364df900229aa7808a68ab065b28b7c61e49931cd4409d8fea8a228ed7243e1055bc17ba69c6b8708958291a4d951e61d044923e315646bb2325446a26f4942
7
- data.tar.gz: 224f1d74769d2c21163643809f9e3f46d85c5a7aee6998a368a828d2b019ab096ccf6a78ba9c31076405bc8ef21c3638223a13806426fc523ad0b2add38885de
6
+ metadata.gz: e15388ad39dbd46471f98658fd44f3e0f7724f5436c3c6abd9bf427c4eeec79e1ba35cb9befaf010e4650660d57fc633f6d223398504950ef22d06a1ee669d04
7
+ data.tar.gz: 13f8351a663571f345892db471fe73acae4e1a4895a5b5cf3b0408409dc78728754401d5b52a3f82af8b5ab91ff22dfa1d47ea3b4e7f8fbf8e4428a730c390de
@@ -48,23 +48,33 @@ module Dry
48
48
  ########################################################################
49
49
 
50
50
  def duck name, **params
51
- current = @current # closure scope
51
+ # <<- CLOSURE_SCOPE
52
+ current = @current
53
+ params = @environs.merge params if @environs
52
54
  filled_or_maybe = optionality(params)
55
+ # CLOSURE_SCOPE
53
56
 
54
57
  schema do
55
58
  __send__(current, name).__send__(filled_or_maybe, duck?: [*params[:methods]])
56
59
  end
60
+
61
+ define_helper_methods name
57
62
  end
58
63
 
59
64
  # possible params: `class: nil, builder: nil, new_records: false`
60
65
  def model name, **params
66
+ # <<- CLOSURE_SCOPE
61
67
  current = @current # closure scope
68
+ params = @environs.merge params if @environs
62
69
  filled_or_maybe = optionality(params)
63
70
  params[:class] ||= name.to_s.gsub(/(?:\A|_)./) { |m| m[-1].upcase }
71
+ # CLOSURE_SCOPE
64
72
 
65
73
  schema do
66
74
  __send__(current, name).__send__(filled_or_maybe, model?: params[:class])
67
75
  end
76
+
77
+ define_helper_methods name
68
78
  end
69
79
 
70
80
  ########################################################################
@@ -74,24 +84,18 @@ module Dry
74
84
  def generic_type name = nil, **params
75
85
  fail Errors::AnonymousTypeDetected.new(__callee__) if name.nil?
76
86
 
77
- params = @environs.merge params if @environs
78
-
79
- # FIXME: :strip => true and siblings should be handled with procs?
87
+ # <<- CLOSURE_SCOPE
80
88
  current = @current # closure scope
81
-
82
- opts = Utils.Guards(params)
83
-
89
+ params = @environs.merge params if @environs
84
90
  type = [optionality(params), Utils.Type(__callee__)]
91
+ opts = Utils.Guards(params)
92
+ # CLOSURE_SCOPE
85
93
 
86
94
  schema do
87
95
  Utils.smart_send(__send__(current, name), *type, **opts)
88
96
  end
89
97
 
90
- unless Nested === self
91
- define_method(name) { @inputs[name] }
92
- define_method(:"#{name}_present?") { @inputs.key?(name) }
93
- define_method(:"#{name}=") { |value| @inputs[name] = value }
94
- end
98
+ define_helper_methods name
95
99
  end
96
100
 
97
101
  %i(string integer float date time boolean).each do |m|
@@ -102,10 +106,18 @@ module Dry
102
106
 
103
107
  private
104
108
 
105
- def optionality nils
106
- # rubocop:disable Style/NestedTernaryOperator
107
- (nils.is_a?(Hash) ? nils[:nils] || nils[:empty] : nils) ? :maybe : :filled
108
- # rubocop:enable Style/NestedTernaryOperator
109
+ def optionality params
110
+ nils, empty = params.delete(:nils), params.delete(:empty)
111
+ # FIXME: Should we treat `empty?` in some specific way?
112
+ nils || empty ? :maybe : :filled
113
+ end
114
+
115
+ def define_helper_methods name
116
+ unless Nested === self
117
+ define_method(name) { @inputs[name] }
118
+ define_method(:"#{name}_present?") { @inputs.key?(name) }
119
+ define_method(:"#{name}=") { |value| @inputs[name] = value }
120
+ end
109
121
  end
110
122
  end
111
123
  end
@@ -1,5 +1,5 @@
1
1
  module Dry
2
2
  module Mutations
3
- VERSION = '0.8.10'.freeze
3
+ VERSION = '0.8.11'.freeze
4
4
  end
5
5
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: dry-mutations
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.8.10
4
+ version: 0.8.11
5
5
  platform: ruby
6
6
  authors:
7
7
  - Aleksei Matiushkin