sinatra-wanted 0.8 → 0.8.1

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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 2bb6e4a003636fbb934a4b36e249ac757ba1cd450e4d632ea2016b61095d3752
4
- data.tar.gz: 6493f6270ae54b97c3df03df9b02146b3a40f43c9e8ca667cdd242033da8232a
3
+ metadata.gz: 36dd224a2e9a878f60e34b32192e512a5359fe0e8dce37654b43fc8693932004
4
+ data.tar.gz: '08e02cfe3f691cf1bac73947c6cc007c18b604ea0658595320d783b86021b805'
5
5
  SHA512:
6
- metadata.gz: f9d6e85a50bd7ac41da1160142ddb6932a00527dea08f57204683506a586792e30ac246c08f64e399e6201678a9e035202c7abaff6a1e1153253923bef6403fb
7
- data.tar.gz: 5453e53c9250895bdf081bca06864a06c2fc06771a28a0a05fcf7457ab8eaaeedad933450d5586790246108050684ad6281febe9b498094bda3162c470a4de27
6
+ metadata.gz: 419d1b4c42c2c7c3ac3f4e35a797c25eee14c2c67a7488f8c5e9f80891e5ab425a2e106a893a84368cbe15358d98a5b7a7d09d998008ea1e509f597003577596
7
+ data.tar.gz: c4678ed4ada73ee0fbd4735db716e879f69be8a44f6009925bff132bb0d66d7af91a002c42a31db152097a93cedcbf04b13ea324ea4f83bbcbfbeae0214e31bf
@@ -19,18 +19,29 @@ module Sinatra::Helpers::Wanted
19
19
  @value = value
20
20
  @id = id
21
21
  end
22
+ attr_reader :id
23
+ attr_reader :value
22
24
  end
23
25
 
24
26
  # Exception to notify of syntax error
25
27
  class WantedSyntaxError < WantedError
28
+ def initialize(msg=nil, id: nil, value: nil)
29
+ super(msg || "syntax error", id: id, value: value)
30
+ end
26
31
  end
27
32
 
28
33
  # Exception to notify of missing parameter
29
34
  class WantedMissing < WantedError
35
+ def initialize(msg=nil, id: nil)
36
+ super(msg || "missing parameter", id: id)
37
+ end
30
38
  end
31
39
 
32
40
  # Exception to notify of object not found
33
41
  class WantedNotFound < WantedError
42
+ def initialize(msg=nil, id: nil, value: nil)
43
+ super(msg || "object not found", id: id, value: value)
44
+ end
34
45
  end
35
46
 
36
47
 
@@ -59,18 +70,16 @@ module Sinatra::Helpers::Wanted
59
70
  def want(param, type=nil, getter=nil, id: nil,
60
71
  default: nil, no_value: NO_VALUE,
61
72
  missing: :ignore, not_found: :ignore, &block)
62
- error_handler do
63
73
  _want(param, type, getter, id: id,
64
74
  default: default, no_value: no_value,
65
75
  missing: missing, not_found: not_found, &block)
66
- end
67
76
  end
68
77
 
69
78
  # (see #want)
70
79
  def want!(param, type=nil, getter=nil, id: nil,
71
80
  default: nil, no_value: NO_VALUE,
72
81
  missing: :raise, not_found: :raise, &block)
73
- want(param, type, getter, id: id,
82
+ _want(param, type, getter, id: id,
74
83
  default: default, no_value: no_value,
75
84
  missing: missing, not_found: not_found, &block)
76
85
  end
@@ -79,7 +88,7 @@ module Sinatra::Helpers::Wanted
79
88
  def want?(param, type=nil, getter=nil, id: nil,
80
89
  default: nil, no_value: NO_VALUE,
81
90
  missing: :return, not_found: :ignore, &block)
82
- want(param, type, getter,
91
+ _want(param, type, getter,
83
92
  default: default, id: id, no_value: no_value,
84
93
  missing: missing, not_found: not_found, &block)
85
94
  end
@@ -138,11 +147,12 @@ module Sinatra::Helpers::Wanted
138
147
  value = type.public_send(type_method, value)
139
148
  end
140
149
  if !value.nil? && get_method
141
- value = getter.public_send(get_method, value)
150
+ val = value
151
+ value = getter.public_send(get_method, value)
142
152
  # Check if we consider it as not found
143
153
  if value.nil?
144
154
  case not_found
145
- when :raise then raise WantedNotFound, id: id
155
+ when :raise then raise WantedNotFound, id: id, value: val
146
156
  when :not_found then self.not_found
147
157
  when :pass then self.pass
148
158
  when :ignore
@@ -156,20 +166,16 @@ module Sinatra::Helpers::Wanted
156
166
 
157
167
  # Return value
158
168
  value
159
- rescue Dry::Types::CoercionError, Dry::Types::ConstraintError
160
- raise WantedSyntaxError, value: value, id: id
161
- end
162
169
 
163
- def error_handler
170
+ rescue StandardError => e
164
171
  if defined?(Dry::Types)
165
- begin
166
- yield
167
- rescue Dry::Types::CoercionError, Dry::Types::ConstraintError
172
+ case e
173
+ when Dry::Types::CoercionError, Dry::Types::ConstraintError
168
174
  raise WantedSyntaxError, value: value, id: id
169
175
  end
170
- else
171
- yield
172
176
  end
177
+
178
+ raise
173
179
  end
174
180
 
175
181
  end
@@ -2,7 +2,7 @@ module Sinatra
2
2
  module Helpers
3
3
  module Wanted
4
4
  # Version
5
- VERSION = 0.8
5
+ VERSION = "0.8.1"
6
6
  end
7
7
  end
8
8
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: sinatra-wanted
3
3
  version: !ruby/object:Gem::Version
4
- version: '0.8'
4
+ version: 0.8.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Stéphane D'Alu
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2021-05-26 00:00:00.000000000 Z
11
+ date: 2021-06-26 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: sinatra