params_ready 0.0.1 → 0.0.2
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/lib/params_ready.rb +2 -2
- data/lib/params_ready/ordering/ordering.rb +2 -2
- data/lib/params_ready/pagination/abstract_pagination.rb +2 -2
- data/lib/params_ready/parameter/value_parameter.rb +1 -1
- data/lib/params_ready/value/coder.rb +15 -12
- data/lib/params_ready/value/validator.rb +19 -6
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 6e0db6411b802c544350d14eb54c921ae019ac7b2365fc2639b4f2f1b77ee40a
|
4
|
+
data.tar.gz: 3811299181627e888b1ac97970a4264f850db87f0475be355a138a30aa825eb1
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: f2f339b6dd2a649244d53c94168ad3e3b238a42268632175c08c3928e01861d75c5c19d7fc3c29b8e0482e8658ed6e5f3a17d9ccda34d0b63808b5e1538b4870
|
7
|
+
data.tar.gz: 355252607fd9c47d58acf4cf1176bc5d35677390bbfeecfe1e24d881f9303be23d20dbcc8611b9c4cff25ff277944e0a2ad9e85aef7ccf0e7174a0a02856f1c3
|
data/lib/params_ready.rb
CHANGED
@@ -27,8 +27,8 @@ module ParamsReady
|
|
27
27
|
end
|
28
28
|
|
29
29
|
def by_columns
|
30
|
-
bare_value.each_with_object(Hash.new(:none)) do |tuple, hash|
|
31
|
-
hash[tuple[0].unwrap] = tuple[1].unwrap
|
30
|
+
bare_value.each_with_index.each_with_object(Hash.new([:none, nil])) do |(tuple, index), hash|
|
31
|
+
hash[tuple[0].unwrap] = [tuple[1].unwrap, index]
|
32
32
|
end
|
33
33
|
end
|
34
34
|
|
@@ -113,7 +113,7 @@ module ParamsReady
|
|
113
113
|
name_for_formatter :value
|
114
114
|
|
115
115
|
def name_for_formatter
|
116
|
-
coder_name = @coder.type_identifier
|
116
|
+
coder_name = @coder.type_identifier if @coder.respond_to? :type_identifier
|
117
117
|
return coder_name unless coder_name.nil?
|
118
118
|
|
119
119
|
super
|
@@ -6,26 +6,29 @@ require_relative '../extensions/class_reader_writer'
|
|
6
6
|
|
7
7
|
module ParamsReady
|
8
8
|
module Value
|
9
|
+
module Coercion
|
10
|
+
def try_coerce(input, context)
|
11
|
+
coerce input, context
|
12
|
+
rescue => _error
|
13
|
+
raise CoercionError.new(input, value_class_name)
|
14
|
+
end
|
15
|
+
|
16
|
+
def strict_default?
|
17
|
+
true
|
18
|
+
end
|
19
|
+
end
|
20
|
+
|
9
21
|
class Coder
|
10
22
|
extend Extensions::ClassReaderWriter
|
11
|
-
|
12
|
-
class_reader_writer :type_identifier
|
13
|
-
type_identifier :value
|
23
|
+
extend Coercion
|
14
24
|
|
15
25
|
def self.value_class_name
|
16
26
|
last = self.name.split("::").last
|
17
27
|
last.remove('Coder')
|
18
28
|
end
|
19
29
|
|
20
|
-
|
21
|
-
|
22
|
-
rescue => _error
|
23
|
-
raise CoercionError.new(input, value_class_name)
|
24
|
-
end
|
25
|
-
|
26
|
-
def self.strict_default?
|
27
|
-
true
|
28
|
-
end
|
30
|
+
class_reader_writer :type_identifier
|
31
|
+
type_identifier :value
|
29
32
|
end
|
30
33
|
|
31
34
|
class GenericCoder
|
@@ -13,15 +13,26 @@ module ParamsReady
|
|
13
13
|
type = Value::Constraint.constraint_type(name_or_constraint)
|
14
14
|
type.build(*args, **opts, &block)
|
15
15
|
else
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
raise ParamsReadyError, "Not a constraint: #{name_or_constraint.class.name}"
|
20
|
-
end
|
16
|
+
valid, missing_method = valid_constraint?(name_or_constraint, strategy)
|
17
|
+
on_constraint_invalid(missing_method) unless valid
|
18
|
+
name_or_constraint
|
21
19
|
end
|
22
20
|
new(constraint, strategy: strategy)
|
23
21
|
end
|
24
22
|
|
23
|
+
def self.on_constraint_invalid(missing_method)
|
24
|
+
raise ParamsReadyError, "Not a valid constraint, '#{missing_method}' unimplemented"
|
25
|
+
end
|
26
|
+
|
27
|
+
def self.valid_constraint?(constraint, strategy)
|
28
|
+
return [false, 'valid?'] unless constraint.respond_to?(:valid?)
|
29
|
+
return [false, 'error_message'] unless constraint.respond_to?(:error_message)
|
30
|
+
return [true, nil] unless strategy == :clamp
|
31
|
+
return [false, 'clamp'] unless constraint.respond_to? :clamp
|
32
|
+
|
33
|
+
[true, nil]
|
34
|
+
end
|
35
|
+
|
25
36
|
def initialize(constraint, strategy: :raise)
|
26
37
|
@constraint = constraint
|
27
38
|
@strategy = check_strategy(constraint, strategy)
|
@@ -33,7 +44,9 @@ module ParamsReady
|
|
33
44
|
when :raise, :undefine
|
34
45
|
strategy.to_sym
|
35
46
|
when :clamp
|
36
|
-
|
47
|
+
if constraint.respond_to? :clamp?
|
48
|
+
raise ParamsReadyError, 'Clamping not applicable' unless constraint.clamp?
|
49
|
+
end
|
37
50
|
strategy.to_sym
|
38
51
|
else
|
39
52
|
raise ParamsReadyError, "Unexpected constraint strategy #{strategy}"
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: params_ready
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0.
|
4
|
+
version: 0.0.2
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Tomas Milsimer
|
@@ -174,7 +174,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
174
174
|
- !ruby/object:Gem::Version
|
175
175
|
version: '0'
|
176
176
|
requirements: []
|
177
|
-
rubygems_version: 3.1.
|
177
|
+
rubygems_version: 3.1.2
|
178
178
|
signing_key:
|
179
179
|
specification_version: 4
|
180
180
|
summary: Define controller interfaces in Rails
|