gourami 1.2.0 → 1.3.0
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 +5 -5
- data/gourami.gemspec +1 -1
- data/lib/gourami/coercer.rb +23 -7
- data/lib/gourami/version.rb +1 -1
- metadata +8 -9
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
|
-
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
2
|
+
SHA256:
|
3
|
+
metadata.gz: 9aeeb89759c11dd7f9559824ccfd42bc6ab7755aa2d60f11b8a38e5b0db08902
|
4
|
+
data.tar.gz: 80c1968c495c2cff9277b4bd51c0340bd8381874dc864d53dab711091f61443a
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 97af9a59317e79d499c95b7b05f31a5089e9f56c7b7970818c22b36482de075f646f212b12e41ad4b53d9be1e967c34b08b34e55c46a90e033151f46416208dc
|
7
|
+
data.tar.gz: 48979f3194878e519431c3a46deb3da5eea9dc624731483f89e8006370d84c30027445b4ac6b31f0ca91b1d669539ad79edf988c51a2d8b2f56f7877b1659cdd
|
data/gourami.gemspec
CHANGED
@@ -21,7 +21,7 @@ Gem::Specification.new do |spec|
|
|
21
21
|
spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
|
22
22
|
spec.require_paths = ["lib"]
|
23
23
|
|
24
|
-
spec.add_development_dependency "
|
24
|
+
spec.add_development_dependency "activesupport", ">= 5.1.7"
|
25
25
|
spec.add_development_dependency "filewatcher", "~> 1.1.0"
|
26
26
|
spec.add_development_dependency "minitest", "~> 5.0"
|
27
27
|
spec.add_development_dependency "pry", "~>0.10"
|
data/lib/gourami/coercer.rb
CHANGED
@@ -11,8 +11,7 @@ module Gourami
|
|
11
11
|
# @return [*]
|
12
12
|
def setter_filter(attribute_name, value, options)
|
13
13
|
type = options[:type]
|
14
|
-
|
15
|
-
value = send(coercer_method_name, value, options) if type
|
14
|
+
value = send(:"coerce_#{type}", value, options) if type
|
16
15
|
|
17
16
|
super(attribute_name, value, options)
|
18
17
|
end
|
@@ -120,21 +119,38 @@ module Gourami
|
|
120
119
|
# The type of the hash keys to coerce, no coersion if value is nil.
|
121
120
|
# @option options :value_type [Symbol, Callable] (nil)
|
122
121
|
# The type of the hash values to coerce, no coersion if value is nil.
|
122
|
+
# @option options :indifferent_access [Boolean] (false)
|
123
|
+
# When true, the resulting Hash will be an ActiveSupport::HashWithIndifferentAccess
|
123
124
|
#
|
124
|
-
# @return [Hash]
|
125
|
+
# @return [Hash, ActiveSupport::HashWithIndifferentAccess]
|
125
126
|
# The coerced Hash.
|
126
127
|
def coerce_hash(value, options = {})
|
128
|
+
return if options[:allow_nil] && value.nil?
|
129
|
+
|
127
130
|
hash_key_type = options[:key_type]
|
128
131
|
hash_value_type = options[:value_type]
|
129
132
|
|
130
|
-
|
133
|
+
hash_class = options[:indifferent_access] ? ActiveSupport::HashWithIndifferentAccess : Hash
|
134
|
+
hash = hash_class.new
|
135
|
+
|
136
|
+
return hash unless value.is_a?(Hash) || (defined?(Sequel::Postgres::JSONHash) && value.is_a?(Sequel::Postgres::JSONHash))
|
131
137
|
|
132
|
-
value.each_with_object(
|
138
|
+
value.each_with_object(hash) do |(key, value), coerced_hash|
|
133
139
|
key_type = hash_key_type.respond_to?(:call) ? hash_key_type.call(key, value) : hash_key_type
|
134
|
-
key = send("coerce_#{key_type}", key) if key_type
|
140
|
+
key = send(:"coerce_#{key_type}", key) if key_type
|
135
141
|
|
136
142
|
value_type = hash_value_type.respond_to?(:call) ? hash_value_type.call(key, value) : hash_value_type
|
137
|
-
|
143
|
+
|
144
|
+
# TODO: Refactor shared logic here and coerce_array to a method like `type, options = resolve_coercer_type_and_options`
|
145
|
+
if value_type.is_a?(Hash)
|
146
|
+
value_type_options = value_type
|
147
|
+
value_type = value_type[:type]
|
148
|
+
else
|
149
|
+
value_type_options = {}
|
150
|
+
end
|
151
|
+
|
152
|
+
value = send(:"coerce_#{value_type}", value, value_type_options) if value_type
|
153
|
+
|
138
154
|
coerced_hash[key] = value
|
139
155
|
end
|
140
156
|
end
|
data/lib/gourami/version.rb
CHANGED
metadata
CHANGED
@@ -1,29 +1,29 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: gourami
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 1.
|
4
|
+
version: 1.3.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- TSMMark
|
8
8
|
autorequire:
|
9
9
|
bindir: exe
|
10
10
|
cert_chain: []
|
11
|
-
date: 2020-
|
11
|
+
date: 2020-06-09 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
|
-
name:
|
14
|
+
name: activesupport
|
15
15
|
requirement: !ruby/object:Gem::Requirement
|
16
16
|
requirements:
|
17
|
-
- - "
|
17
|
+
- - ">="
|
18
18
|
- !ruby/object:Gem::Version
|
19
|
-
version:
|
19
|
+
version: 5.1.7
|
20
20
|
type: :development
|
21
21
|
prerelease: false
|
22
22
|
version_requirements: !ruby/object:Gem::Requirement
|
23
23
|
requirements:
|
24
|
-
- - "
|
24
|
+
- - ">="
|
25
25
|
- !ruby/object:Gem::Version
|
26
|
-
version:
|
26
|
+
version: 5.1.7
|
27
27
|
- !ruby/object:Gem::Dependency
|
28
28
|
name: filewatcher
|
29
29
|
requirement: !ruby/object:Gem::Requirement
|
@@ -133,8 +133,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
133
133
|
- !ruby/object:Gem::Version
|
134
134
|
version: '0'
|
135
135
|
requirements: []
|
136
|
-
|
137
|
-
rubygems_version: 2.4.6
|
136
|
+
rubygems_version: 3.0.4
|
138
137
|
signing_key:
|
139
138
|
specification_version: 4
|
140
139
|
summary: Keep your Routes, Controllers and Models thin.
|