simple_validate 2.0.2 → 2.1.2
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.rspec_status +4 -4
- data/README.md +2 -2
- data/lib/simple_validate/validates_type_of.rb +7 -4
- data/lib/simple_validate/version.rb +1 -1
- 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: 1ac8df574ea6749497a31f423b343ddbb5e7f444a3d5d8ab60d57a3faaa594cf
|
4
|
+
data.tar.gz: 0122ded6d697df547de47dc9a47556f8ecffacfe79369675558ad9714c1565fc
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 8391463f35b4ae5e04c7025941d8a85d0533b69eac371c3b85c8e5e437dd6cdcf7d8c7d7203cc54a8acf00bba2da126a3218fe4eb65642529c2c069fe21254a6
|
7
|
+
data.tar.gz: 405ea7f377be0e0f561f8c597dd7c5dc6ac1712663421999014f810a521e85b21224458386154e7e8e9529dc97ba198cd2a463105553ad5e335561bce0a52e35
|
data/.rspec_status
CHANGED
@@ -1,8 +1,8 @@
|
|
1
1
|
example_id | status | run_time |
|
2
2
|
------------------------------------- | ------ | --------------- |
|
3
|
-
./spec/simple_validate_spec.rb[1:1:1] | passed | 0.
|
3
|
+
./spec/simple_validate_spec.rb[1:1:1] | passed | 0.00132 seconds |
|
4
4
|
./spec/simple_validate_spec.rb[1:2:1] | passed | 0.00012 seconds |
|
5
|
-
./spec/simple_validate_spec.rb[1:3:1] | passed | 0.
|
6
|
-
./spec/simple_validate_spec.rb[1:4:1] | passed | 0.
|
5
|
+
./spec/simple_validate_spec.rb[1:3:1] | passed | 0.00108 seconds |
|
6
|
+
./spec/simple_validate_spec.rb[1:4:1] | passed | 0.00007 seconds |
|
7
7
|
./spec/simple_validate_spec.rb[1:5:1] | passed | 0.00006 seconds |
|
8
|
-
./spec/simple_validate_spec.rb[1:6:1] | passed | 0.
|
8
|
+
./spec/simple_validate_spec.rb[1:6:1] | passed | 0.00007 seconds |
|
data/README.md
CHANGED
@@ -18,7 +18,7 @@ class Person
|
|
18
18
|
attr_accessor :name, :age
|
19
19
|
|
20
20
|
validates_presence_of :name, :age
|
21
|
-
|
21
|
+
validates_type_of :age, as: :integer
|
22
22
|
end
|
23
23
|
```
|
24
24
|
|
@@ -30,7 +30,7 @@ end
|
|
30
30
|
=> p.errors
|
31
31
|
=> #<SimpleValidate::Errors:0x007f94318b4df0
|
32
32
|
@messages=
|
33
|
-
{:age=>["can't be empty", "must be
|
33
|
+
{:age=>["can't be empty", "must be an integer"],
|
34
34
|
:name=>["can't be empty"]}>
|
35
35
|
```
|
36
36
|
|
@@ -2,21 +2,24 @@
|
|
2
2
|
|
3
3
|
module SimpleValidate
|
4
4
|
class ValidatesTypeOf < ValidatesBase
|
5
|
-
SUPPORTED_TYPES = %i[string integer float].freeze
|
5
|
+
SUPPORTED_TYPES = %i[string integer float boolean].freeze
|
6
6
|
|
7
7
|
def initialize(attribute, options)
|
8
8
|
@type = options[:as]
|
9
9
|
|
10
10
|
raise ArgumentError unless @type && SUPPORTED_TYPES.include?(@type)
|
11
11
|
|
12
|
-
@klass = Utils.classify(options[:as])
|
13
|
-
|
14
12
|
super(attribute, options[:message] ||
|
15
13
|
"must be #{Utils.article(@type)} #{@type}", options[:if] || proc { true })
|
16
14
|
end
|
17
15
|
|
18
16
|
def valid?(instance)
|
19
|
-
|
17
|
+
if @type == :boolean
|
18
|
+
[true, false].include? instance.send(attribute)
|
19
|
+
else
|
20
|
+
klass = Utils.classify(@type)
|
21
|
+
instance.send(attribute).is_a?(klass)
|
22
|
+
end
|
20
23
|
end
|
21
24
|
end
|
22
25
|
end
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: simple_validate
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 2.
|
4
|
+
version: 2.1.2
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Nick Palaniuk
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2023-08-
|
11
|
+
date: 2023-08-30 00:00:00.000000000 Z
|
12
12
|
dependencies: []
|
13
13
|
description: PORO validation mixin with no deps
|
14
14
|
email:
|