gourami 0.3.0 → 0.4.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 +4 -4
- data/lib/gourami/coercer.rb +3 -3
- data/lib/gourami/validations.rb +7 -0
- data/lib/gourami/version.rb +1 -1
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 603c7eab7f67f882417c3d2c3972b8632e50d420
|
4
|
+
data.tar.gz: d9ddbf73b7e29f40443d3f2ff421f434c66ee073
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 2e98badb6ec80ba426d32da18e915944c7461e9154348efdc5c401cac9053224e4a82ed16ca78d89d81c6506cce4d6c940cf53e84e253e4ea87d1a7008634d1b
|
7
|
+
data.tar.gz: dddd5426e7a1c497ccd0ff57c2536944d51077dd7317637fa3961943605afed939045047043017e2bdfe3bd2b8a8f22b93e11558a3f6e47206477b63cbceb57b
|
data/lib/gourami/coercer.rb
CHANGED
@@ -24,15 +24,15 @@ module Gourami
|
|
24
24
|
# @param value [Object]
|
25
25
|
# @option allow_nil [Boolean] (true)
|
26
26
|
# @option upcase [Boolean] (false)
|
27
|
-
# @option strip [Boolean] (
|
27
|
+
# @option strip [Boolean] (true)
|
28
28
|
#
|
29
29
|
# @return [String, nil]
|
30
30
|
def coerce_string(value, options = {})
|
31
31
|
return nil if value.nil? && options.fetch(:allow_nil, true)
|
32
32
|
|
33
33
|
value = value.to_s.dup.force_encoding(Encoding::UTF_8)
|
34
|
-
value.strip! if options
|
35
|
-
value.upcase! if options
|
34
|
+
value.strip! if options.fetch(:strip, true)
|
35
|
+
value.upcase! if options.fetch(:upcase, false)
|
36
36
|
|
37
37
|
value
|
38
38
|
end
|
data/lib/gourami/validations.rb
CHANGED
@@ -150,12 +150,18 @@ module Gourami
|
|
150
150
|
|
151
151
|
if value
|
152
152
|
length = value.size
|
153
|
+
did_append_error = false
|
154
|
+
|
153
155
|
if min && length < min
|
156
|
+
did_append_error = true
|
154
157
|
append_error(attribute_name, options.fetch(:min_message, nil) || :is_too_short)
|
155
158
|
end
|
156
159
|
if max && length > max
|
160
|
+
did_append_error = true
|
157
161
|
append_error(attribute_name, options.fetch(:max_message, nil) || :is_too_long)
|
158
162
|
end
|
163
|
+
|
164
|
+
errors[attribute_name] if did_append_error
|
159
165
|
end
|
160
166
|
end
|
161
167
|
|
@@ -207,6 +213,7 @@ module Gourami
|
|
207
213
|
end
|
208
214
|
end
|
209
215
|
|
216
|
+
# TODO: Spec return value in spec/validations_spec.rb
|
210
217
|
# Validate the range in which the attribute can be. If the value is less
|
211
218
|
# than the min a :less_than_min error will be appended. If the value is
|
212
219
|
# greater than the max a :greater_than_max error will be appended.
|
data/lib/gourami/version.rb
CHANGED
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: gourami
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.4.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- TSMMark
|
8
8
|
autorequire:
|
9
9
|
bindir: exe
|
10
10
|
cert_chain: []
|
11
|
-
date:
|
11
|
+
date: 2019-02-22 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: pry
|