boolean_validator 0.1.1 → 0.1.3

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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 211c6e902816bcf08e1ca63ef7b7c6b4749147a324b5c6269b5ce1957082d440
4
- data.tar.gz: d25fd380c3863e8eaadc1c0ee00b42635d482a82a475e5bc06093f57519fd8ed
3
+ metadata.gz: 02041fdc13701a69b69dc71e484aee448a445871dd367b0edea01f5f2f39108c
4
+ data.tar.gz: 58ff8c80cbc0a4373a4379d24ee49720a42e972954d6ccdb2d64d85a507af58a
5
5
  SHA512:
6
- metadata.gz: fce0aab9b8ad438fce116f9ea1365d42322ee20e6332f044c566c6df9a48340f11b26078fa4d9570ada51b43d52628e345b36e238af8ac25efc2008e5b09b3fa
7
- data.tar.gz: 72253cfd635c94da5ebea3956b2ca093b8fa72593b2740f108003329947d1519a5068ce43167d41146aa3c9e596f701b74bce8e8e6397d8458e4546c2652f38d
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
- You would have implemented a `Post` model like this:
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 < ActiveRecord::Base
42
- validates :is_public_before_type_cast, boolean: true
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 < ActiveRecord::Base
50
- validate :is_public_before_type_cast, boolean: { message: 'Customize your error message' }
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
- Bug reports and pull requests are welcome on GitHub at https://github.com/spice-inc/boolean_validator.
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
 
@@ -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 BOOLEAN_VALUES.include?(value)
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.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-04-28 00:00:00.000000000 Z
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 Rails and ActiveModel.
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 Rails and ActiveModel.
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)