type_validator 0.10.0 → 0.11.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/.tool-versions +1 -0
- data/README.md +11 -1
- data/lib/type_validator/version.rb +1 -1
- data/lib/type_validator.rb +0 -9
- metadata +2 -1
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 74eb421ea1f47501223d2373ffc493ada6b69a2707b5a958c5570dc6d554cb91
|
4
|
+
data.tar.gz: a1462cca7867b4110a34628c64a758ec6fc9966a7ffe81b84434cfe6a2134e53
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 5d11e5db37ba9ccdd7619ee093e3f973fb93ad8bfbddfbc53304608b3ec09efc3415b658b69cb8dfb49f9b6a328e2e9cd1f5f45250284ec7541c4b2eae73aa64
|
7
|
+
data.tar.gz: c67081c3c93240f2f49c4c74736405ffc364e0f069adaa1694ca2a6125110f94aa78c905d73108fefb9717a7e20ba35311a2c833084c1f091f98f6ffa69e03d9
|
data/.tool-versions
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
ruby 2.6.3
|
data/README.md
CHANGED
@@ -5,6 +5,9 @@
|
|
5
5
|
|
6
6
|
Adds type validation for classes with [`ActiveModel::Validations >= 3.2`](https://api.rubyonrails.org/classes/ActiveModel/Validations.html).
|
7
7
|
|
8
|
+
## Required Ruby version
|
9
|
+
> \>= 2.2.0
|
10
|
+
|
8
11
|
## Installation
|
9
12
|
|
10
13
|
Add this line to your application's Gemfile:
|
@@ -57,12 +60,16 @@ validates :status, type: { kind_of: [String, Symbol]}
|
|
57
60
|
validates :handler, type: { respond_to: :call }
|
58
61
|
```
|
59
62
|
|
63
|
+
**Class == Class || Class < Class**
|
64
|
+
|
60
65
|
```ruby
|
61
66
|
# Verifies if the attribute value is the class or a subclass.
|
62
67
|
|
63
68
|
validates :handler, type: { klass: Handler }
|
64
69
|
```
|
65
70
|
|
71
|
+
**Array.new.all? { |item| item.is_a?(Class) }**
|
72
|
+
|
66
73
|
```ruby
|
67
74
|
validates :account_types, type: { array_of: String }
|
68
75
|
|
@@ -72,6 +79,8 @@ validates :account_types, type: { array_of: String }
|
|
72
79
|
validates :account_types, type: { array_of: [String, Symbol] }
|
73
80
|
```
|
74
81
|
|
82
|
+
**Array.new.all? { |item| expected_values.include?(item) }**
|
83
|
+
|
75
84
|
```ruby
|
76
85
|
# Verifies if the attribute value
|
77
86
|
# is an array with some or all the expected values.
|
@@ -79,7 +88,8 @@ validates :account_types, type: { array_of: [String, Symbol] }
|
|
79
88
|
validates :account_types, type: { array_with: ['foo', 'bar'] }
|
80
89
|
```
|
81
90
|
|
82
|
-
|
91
|
+
### All the validations above accept:
|
92
|
+
|
83
93
|
- `allow_nil` option. e.g:. e.g:
|
84
94
|
```ruby
|
85
95
|
validates :name, type: { is_a: String }, allow_nil: true
|
data/lib/type_validator.rb
CHANGED
@@ -52,15 +52,6 @@ class TypeValidator < ActiveModel::EachValidator
|
|
52
52
|
"must be the or a subclass of `#{klass.name}`"
|
53
53
|
end
|
54
54
|
|
55
|
-
def validate_klass(value, klass)
|
56
|
-
require_a_class(value)
|
57
|
-
require_a_class(klass)
|
58
|
-
|
59
|
-
return if value == klass || value < klass
|
60
|
-
|
61
|
-
"must be the or a subclass of `#{klass.name}`"
|
62
|
-
end
|
63
|
-
|
64
55
|
def require_a_class(arg)
|
65
56
|
raise ArgumentError, "#{arg} must be a class" unless arg.is_a?(Class)
|
66
57
|
end
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: type_validator
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.11.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Rodrigo Serradura
|
@@ -75,6 +75,7 @@ extra_rdoc_files: []
|
|
75
75
|
files:
|
76
76
|
- ".coveralls.yml"
|
77
77
|
- ".gitignore"
|
78
|
+
- ".tool-versions"
|
78
79
|
- ".travis.sh"
|
79
80
|
- ".travis.yml"
|
80
81
|
- CODE_OF_CONDUCT.md
|