paramore 3.1.1 → 3.5.0

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
  SHA256:
3
- metadata.gz: fb73686fb48a297c559c211476f565f8aba18a2e93a10936b75cacd4eab2bcb2
4
- data.tar.gz: df12fd5715e1c4e3851a1ed2f9748f24cccec9d9ccc817c7b6ba74960370f426
3
+ metadata.gz: 6340acf8c31895cbe076513a9523e161e9017f2941fd69740000c274233273fc
4
+ data.tar.gz: 2c0cc6707f1876fb01cf75bcc2f5ce9f1e9e8480148523bcf5a45ebb3a4e64c3
5
5
  SHA512:
6
- metadata.gz: 5d7f2e6f52065f18ebb5b7d51577950ceb234db5f5a21fd3a20fdb987066c451da22beda1bc86a4101ad9bfaf4ccf195a38b1281b02c92c4d8cc2d1fa6602958
7
- data.tar.gz: b5dd8ae054488a628c580924cfdfb0355ef063a43eb7e46fe249ae9ecad62a4a80d5603b4eed182d1b69c1d691926c97165c605b11d05eec4b5ed66efbc3cac3
6
+ metadata.gz: 8d310cb628671876e4dc707f57e24aa79e11dd08da615ae1f8205aac3fd80de1c77243f7fa765ec4168464b9710bc97110c3835775de9ed5b42a09b10bcf6191
7
+ data.tar.gz: cbfd5ffa27d01ad661f48d4bc8bf0d23288426ae14a73cd565c99ee8c8d0b9b2f64a4b57cbdadcabda0848ab227da951927fe75126200e347aa11abed7c55e5b
@@ -9,7 +9,7 @@ module Paramore
9
9
 
10
10
  def cast(field, value, name = nil)
11
11
  if value.nil?
12
- if field.nullable? || field.default
12
+ if field.nullable? || field.default?
13
13
  return field.default
14
14
  else
15
15
  raise Paramore::NilParameter, name
@@ -18,16 +18,24 @@ module Paramore
18
18
 
19
19
  case field.type
20
20
  when Hash
21
- typecast_hash(field.type, value || {})
21
+ typecast_hash(field, value || {})
22
22
  when Array
23
23
  typecast_array(field, value)
24
24
  else
25
- typecast_value(field.type, value)
25
+ if value == '' && !field.allow_empty? && field.nullable?
26
+ nil
27
+ else
28
+ typecast_value(field.type, value)
29
+ end
26
30
  end
27
31
  end
28
32
 
29
33
  def typecast_hash(field, hash)
30
- field.to_h { |name, field| [name, cast(field, hash[name], name)] }
34
+ result = field
35
+ .type
36
+ .reject { |name, inner_field| !hash.key?(name) && !inner_field.required? }
37
+ .to_h { |name, inner_field| [name, cast(inner_field, hash[name], name)] }
38
+ field.compact? ? result.compact : result
31
39
  end
32
40
 
33
41
  def typecast_array(field, array)
@@ -8,6 +8,10 @@ module Paramore
8
8
  default
9
9
  ].freeze
10
10
 
11
+ def field(*args)
12
+ Paramore.field(*args)
13
+ end
14
+
11
15
  def param_schema(accessor_name, parameter_configuration)
12
16
  unless parameter_configuration.keys.size == 1
13
17
  raise ArgumentError,
@@ -4,17 +4,33 @@ module Paramore
4
4
  null: false,
5
5
  compact: false,
6
6
  default: nil,
7
+ empty: true,
8
+ required: true,
7
9
  }.freeze
8
10
 
9
- def initialize(given_type, null:, compact:, default:)
11
+ def initialize(given_type, null:, compact:, default:, empty:, required:)
10
12
  @given_type = given_type
11
13
  @nullable = null
12
14
  @compact = compact
15
+ @allow_empty = empty
13
16
  @default = default
17
+ @required = required
18
+ end
19
+
20
+ def required?
21
+ @required
22
+ end
23
+
24
+ def allow_empty?
25
+ @allow_empty
26
+ end
27
+
28
+ def default?
29
+ !@default.nil?
14
30
  end
15
31
 
16
32
  def default
17
- @default
33
+ @default.is_a?(Proc) ? @default.call : @default
18
34
  end
19
35
 
20
36
  def compact?
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.1.1
4
+ version: 3.5.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-09-16 00:00:00.000000000 Z
11
+ date: 2021-09-27 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: rspec-rails
@@ -101,7 +101,7 @@ licenses:
101
101
  - MIT
102
102
  metadata: {}
103
103
  post_install_message: |
104
- Thank you for installing Paramore 3.1.1 !
104
+ Thank you for installing Paramore 3.5.0 !
105
105
  From the command line you can run `paramore` to generate a configuration file
106
106
 
107
107
  More details here : https://github.com/lumzdas/paramore/blob/master/README.md