boolean_validator 0.1.1 → 0.1.3
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/README.md +11 -25
- data/lib/boolean_validator.rb +1 -4
- metadata +4 -5
- data/lib/extensions/active_model/type/boolean.rb +0 -12
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 02041fdc13701a69b69dc71e484aee448a445871dd367b0edea01f5f2f39108c
|
4
|
+
data.tar.gz: 58ff8c80cbc0a4373a4379d24ee49720a42e972954d6ccdb2d64d85a507af58a
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 8bd9c3a1473c9b50c3de3ffc9bfcc181e12e8770ff71345bac01c0cce3f2bb4c638401d2ba5e30e43c04053e5401bc1c12f71bf3e672bca241b302dba9ab14ce
|
7
|
+
data.tar.gz: e75f04a1caffff67fdd8709be8a348ebbfabd56652ca5e61b9f5ecf55d469d721f135e7a20c0c6cc5fd77ab0f34f8c5f0f47467cba8ea06cd3cbf60f64f12c8e
|
data/README.md
CHANGED
@@ -13,48 +13,34 @@ gem 'boolean_validator'
|
|
13
13
|
|
14
14
|
And then execute:
|
15
15
|
|
16
|
-
$ bundle
|
16
|
+
$ bundle install
|
17
17
|
|
18
18
|
|
19
19
|
## Usage
|
20
20
|
|
21
|
-
|
22
|
-
|
23
|
-
```ruby
|
24
|
-
class Post < ActiveRecord::Base
|
25
|
-
validates :is_public_before_type_cast, inclusion: { in: [true, false] }
|
26
|
-
end
|
27
|
-
```
|
28
|
-
|
29
|
-
or this (though this is wrong because this *validation* actually *validates nothing*):
|
30
|
-
|
31
|
-
```ruby
|
32
|
-
class Post < ActiveRecord::Base
|
33
|
-
validates :is_public, inclusion: { in: [true, false] }
|
34
|
-
end
|
35
|
-
```
|
36
|
-
|
37
|
-
|
38
|
-
To validate boolean value with this gem, try:
|
39
|
-
|
21
|
+
In your model:
|
40
22
|
```ruby
|
41
|
-
class Post
|
42
|
-
|
23
|
+
class Post
|
24
|
+
include ActiveModel::Model
|
25
|
+
validates :is_public, boolean: true
|
43
26
|
end
|
44
27
|
```
|
45
28
|
|
46
29
|
or you can pass an option like:
|
47
30
|
|
48
31
|
```ruby
|
49
|
-
class Post
|
50
|
-
|
32
|
+
class Post
|
33
|
+
include ActiveModel::Model
|
34
|
+
validate :is_public, boolean: { message: 'Customize your error message' }
|
51
35
|
end
|
52
36
|
```
|
53
37
|
|
54
38
|
|
55
39
|
## Contributing
|
56
40
|
|
57
|
-
|
41
|
+
- Note: With `ActiveRecord`, this validation does not work functionally and just work as column type declaration.
|
42
|
+
- Implementation for `ActiveRecord` is here: https://github.com/ayumitamai97/boolean_validator/pull/4
|
43
|
+
- Bug reports and your opinions are welcome.
|
58
44
|
|
59
45
|
## License
|
60
46
|
|
data/lib/boolean_validator.rb
CHANGED
@@ -1,11 +1,8 @@
|
|
1
1
|
require 'active_model/validator'
|
2
|
-
require 'extensions/active_model/type/boolean'
|
3
2
|
|
4
3
|
class BooleanValidator < ActiveModel::EachValidator
|
5
|
-
BOOLEAN_VALUES = ActiveModel::Type::Boolean::TRUE_VALUES + ActiveModel::Type::Boolean::FALSE_VALUES
|
6
|
-
|
7
4
|
def validate_each(record, attribute, value)
|
8
|
-
return if
|
5
|
+
return if [true, false].include?(value)
|
9
6
|
|
10
7
|
record.errors.add(attribute, :invalid, options.slice(:message).merge(value: value))
|
11
8
|
end
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: boolean_validator
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.1.
|
4
|
+
version: 0.1.3
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- ayumitamai97
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2019-
|
11
|
+
date: 2019-05-05 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: activemodel
|
@@ -24,7 +24,7 @@ dependencies:
|
|
24
24
|
- - ">="
|
25
25
|
- !ruby/object:Gem::Version
|
26
26
|
version: 5.0.0
|
27
|
-
description: Boolean validator for
|
27
|
+
description: Boolean validator for ActiveModel.
|
28
28
|
email:
|
29
29
|
- ayumitamai97@gmail.com
|
30
30
|
executables: []
|
@@ -34,7 +34,6 @@ files:
|
|
34
34
|
- README.md
|
35
35
|
- Rakefile
|
36
36
|
- lib/boolean_validator.rb
|
37
|
-
- lib/extensions/active_model/type/boolean.rb
|
38
37
|
homepage: https://github.com/ayumitamai97/boolean_validator
|
39
38
|
licenses:
|
40
39
|
- MIT
|
@@ -57,5 +56,5 @@ requirements: []
|
|
57
56
|
rubygems_version: 3.0.3
|
58
57
|
signing_key:
|
59
58
|
specification_version: 4
|
60
|
-
summary: Boolean validator for
|
59
|
+
summary: Boolean validator for ActiveModel.
|
61
60
|
test_files: []
|
@@ -1,12 +0,0 @@
|
|
1
|
-
require 'active_model/type'
|
2
|
-
|
3
|
-
module ActiveModelExtension
|
4
|
-
module Boolean
|
5
|
-
# FALSE_VALUES are defined in:
|
6
|
-
# https://github.com/rails/rails/blob/406d3a926cfcd3724f8002f70346aad95eed4a8c/activemodel/lib/active_model/type/boolean.rb
|
7
|
-
|
8
|
-
TRUE_VALUES = Set.new([true, 1, "1", "t", "T", "true", "TRUE", "on", "ON"])
|
9
|
-
end
|
10
|
-
end
|
11
|
-
|
12
|
-
ActiveModel::Type::Boolean.send(:include, ActiveModelExtension::Boolean)
|