lite-validators 1.0.5 → 1.0.6

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 7f204fb7b34f2071f2ceb2ff58776eb169c134c6e59de1388232475a6635c8f5
4
- data.tar.gz: c6dd398a13a3a743e9e298e6a17d8e0eb6db253a5f45c02b44490df1fbb2086b
3
+ metadata.gz: a4ab573f6333ac1eef65062bd05ae783281cd2da6f70d1a6e146ba5befe6a29d
4
+ data.tar.gz: 5b69cad7d3d9021016b78753f6dc028e9f353e88f53177b992a0bef1ea6b279a
5
5
  SHA512:
6
- metadata.gz: 7849297d55cee50fc889a2a3c3e15d24dc05ebd0a00e17bfa2436c2446fcf2eb6aae390a00a40bdea863cc02290c88cb16b7c4157da99931b1852bf6e796df0b
7
- data.tar.gz: 877d01ccb4519144292784c9038b84a2ecbbf48ca16fddbcd872bc237ecd0361d6c6178723a396f96ea4156ca3deda39e4bfe4d311fbffa7ebdca4f8b9a40523
6
+ metadata.gz: 2818016f0d2f7411102d45ba354e1e5edd21d25b4a4e935f1d1e98bc7778caf451d5101061a6b33e4114e9d6b663f117711c69ecf9169b1bca38b70105b75660
7
+ data.tar.gz: ad7fec82c975771f716c0239c7bfb66abdf6781423986021397a56676f12c8911178dc773f7630310fb1abdd82688c8c45bd4558e8631c06b77522258c7a39cd
data/CHANGELOG.md CHANGED
@@ -6,6 +6,10 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
6
6
 
7
7
  ## [Unreleased]
8
8
 
9
+ ## [1.0.6] - 2019-09-18
10
+ ### Added
11
+ - Added true and false only checks to boolean validator
12
+
9
13
  ## [1.0.5] - 2019-08-09
10
14
  ### Added
11
15
  - Added length check to Url validator
data/Gemfile.lock CHANGED
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- lite-validators (1.0.5)
4
+ lite-validators (1.0.6)
5
5
  activemodel
6
6
 
7
7
  GEM
@@ -50,7 +50,7 @@ GEM
50
50
  nokogiri (1.10.4)
51
51
  mini_portile2 (~> 2.4.0)
52
52
  parallel (1.17.0)
53
- parser (2.6.4.0)
53
+ parser (2.6.4.1)
54
54
  ast (~> 2.4.0)
55
55
  rack (2.0.7)
56
56
  rack-test (1.1.0)
@@ -1,6 +1,10 @@
1
1
  en:
2
2
  errors:
3
3
  messages:
4
+ boolean:
5
+ all: "must be a true or false value"
6
+ false_only: "must be a false value"
7
+ true_only: "must be a true value"
4
8
  csv:
5
9
  in: "csv %{dimension} is not between %{min} and %{max}"
6
10
  greater_than: "csv %{dimension} is not greater than %{count}"
data/docs/BOOLEAN.md CHANGED
@@ -8,12 +8,19 @@
8
8
  'false values' => [false, 0, '0', 'f', 'F', 'false', 'FALSE']
9
9
  ```
10
10
 
11
+ #### Options
12
+
13
+ Option | Type | Available | Default
14
+ --- | --- | --- | ---
15
+ check | symbol | all, false_only, true_only | all
16
+
11
17
  #### Usage
12
18
 
13
19
  ```ruby
14
20
  class User < ActiveRecord::Base
15
21
 
16
22
  validates :input_0, boolean: true
23
+ validates :input_1, boolean: { check: :true_only }
17
24
 
18
25
  end
19
26
  ```
@@ -2,14 +2,34 @@
2
2
 
3
3
  class BooleanValidator < BaseValidator
4
4
 
5
- VALUES ||= %w[
6
- 1 0 t f true false y n yes no on off
7
- ].freeze
5
+ CHECKS ||= {
6
+ all: nil,
7
+ false_only: %w[0 f false n no off],
8
+ true_only: %w[1 t true y yes on]
9
+ }.freeze
10
+
11
+ def validate_each(record, attribute, value)
12
+ assert_valid_check!
13
+ super
14
+ end
8
15
 
9
16
  private
10
17
 
18
+ def assert_valid_check!
19
+ assert_valid_option!(:check, CHECKS.keys)
20
+ end
21
+
22
+ def check
23
+ options[:check] || :all
24
+ end
25
+
26
+ def error_message
27
+ [options[:message] || I18n.t("errors.messages.boolean.#{check}")]
28
+ end
29
+
11
30
  def valid_attr?
12
- VALUES.include?(value.to_s.downcase)
31
+ checks = CHECKS[check] || [].concat(CHECKS[:false_only], CHECKS[:true_only])
32
+ checks.include?(value.to_s.downcase)
13
33
  end
14
34
 
15
35
  end
@@ -3,7 +3,7 @@
3
3
  module Lite
4
4
  module Validators
5
5
 
6
- VERSION ||= '1.0.5'
6
+ VERSION ||= '1.0.6'
7
7
 
8
8
  end
9
9
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: lite-validators
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.0.5
4
+ version: 1.0.6
5
5
  platform: ruby
6
6
  authors:
7
7
  - Juan Gomez
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2019-09-06 00:00:00.000000000 Z
11
+ date: 2019-09-18 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: activemodel