paramore 3.8.4 → 3.9.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/lib/paramore/cast_parameters.rb +22 -5
- data/lib/paramore/types.rb +4 -0
- metadata +3 -3
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 851431003d956d84bd81e2906e91bf7214dec4e545837ecb993da871b7b3d2db
|
4
|
+
data.tar.gz: f58885155ee86529b7e6fe70e3e02b930a4a20c2e47f3c33a46ca82a3809a781
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: ff41680f998907900897575c33276aa6c11e1027124b7844851996f6969edcac24904b0bc641a55379d47a66ccbab36b0319461b5cd408d570dafe31ae445007
|
7
|
+
data.tar.gz: 1184372ed73019ab06d2ad0c27937e42bfcc9c474d7c54abb784a2cd1f7630fc957eb052810d557f7c62699f03cbd49a12be3a21a7ff2ebe25e35df35c49172b
|
@@ -1,10 +1,21 @@
|
|
1
1
|
require_relative 'errors'
|
2
2
|
|
3
3
|
module Paramore
|
4
|
-
|
5
|
-
|
6
|
-
|
7
|
-
|
4
|
+
class CastParameters
|
5
|
+
attr_accessor :root_field, :data, :options
|
6
|
+
|
7
|
+
def initialize(field, data, options)
|
8
|
+
@root_field = field
|
9
|
+
@data = data
|
10
|
+
@options = options
|
11
|
+
end
|
12
|
+
|
13
|
+
def self.run(field, data, options = {})
|
14
|
+
new(field, data, options).run
|
15
|
+
end
|
16
|
+
|
17
|
+
def run
|
18
|
+
cast(root_field, data, 'data')
|
8
19
|
end
|
9
20
|
|
10
21
|
def cast(field, value, name = nil)
|
@@ -47,13 +58,17 @@ module Paramore
|
|
47
58
|
[typecast_value(key_type, name, nil), cast(value_field, value, name)]
|
48
59
|
end
|
49
60
|
else
|
61
|
+
if options[:no_extra_keys]
|
62
|
+
extra = hash.keys - field.type.keys
|
63
|
+
raise "Found extra keys in `name`: #{extra}!"
|
64
|
+
end
|
65
|
+
|
50
66
|
field
|
51
67
|
.type
|
52
68
|
.reject { |name, value_field| missing_and_optional?(hash, name, value_field) }
|
53
69
|
.to_h { |name, value_field| [name, cast(value_field, hash[name], name)] }
|
54
70
|
end
|
55
71
|
|
56
|
-
|
57
72
|
field.compact? ? result.compact : result
|
58
73
|
end
|
59
74
|
|
@@ -69,6 +84,8 @@ module Paramore
|
|
69
84
|
|
70
85
|
def typecast_value(type, value, name)
|
71
86
|
type.send(Paramore.configuration.type_method_name, value)
|
87
|
+
rescue StandardError => e
|
88
|
+
raise "The field `#{name}` raised \"#{e}\"!"
|
72
89
|
end
|
73
90
|
|
74
91
|
def missing_and_optional?(hash, name, field)
|
data/lib/paramore/types.rb
CHANGED
@@ -18,6 +18,8 @@ module Paramore
|
|
18
18
|
module Float
|
19
19
|
module_function
|
20
20
|
def [](input)
|
21
|
+
raise ArgumentError "#{input} is not a float!" unless input.to_s.match?(/-{0,1}\d*(\.\d*){0,1}/)
|
22
|
+
|
21
23
|
input.to_f
|
22
24
|
end
|
23
25
|
end
|
@@ -25,6 +27,8 @@ module Paramore
|
|
25
27
|
module Int
|
26
28
|
module_function
|
27
29
|
def [](input)
|
30
|
+
raise ArgumentError "#{input} is not an integer!" unless input.to_s.match?(/^-{0,1}\d*$/)
|
31
|
+
|
28
32
|
input.to_i
|
29
33
|
end
|
30
34
|
end
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: paramore
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 3.
|
4
|
+
version: 3.9.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Lukas Kairevičius
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2021-
|
11
|
+
date: 2021-12-07 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: rspec-rails
|
@@ -115,7 +115,7 @@ licenses:
|
|
115
115
|
- MIT
|
116
116
|
metadata: {}
|
117
117
|
post_install_message: |
|
118
|
-
Thank you for installing Paramore 3.
|
118
|
+
Thank you for installing Paramore 3.9.0 !
|
119
119
|
From the command line you can run `paramore` to generate a configuration file
|
120
120
|
|
121
121
|
More details here : https://github.com/lumzdas/paramore/blob/master/README.md
|