be_valid 0.1.2 → 0.1.7
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/.github/workflows/ruby.yml +24 -0
- data/Gemfile.lock +17 -18
- data/be_valid.gemspec +2 -2
- data/lib/be_valid.rb +1 -1
- data/lib/be_valid/be_valid.rb +2 -2
- data/lib/be_valid/version.rb +1 -1
- data/lib/validators/date_validator.rb +3 -3
- data/lib/validators/must_be_validator.rb +12 -4
- metadata +8 -7
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 7edccd354585b1c23c1b623e936e48a442e63084ffdb50ec723c8e6c484d88dc
|
4
|
+
data.tar.gz: 8f1a9f325cf407a462749673476eedba4257df10d9a58520bfa686b31d9cadda
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: f870bf1181a47bef15e48054ca0276090a55a9340f93dccb538e6ea94a62e15949c1b47c0c688c3347fa8f51ea6c0cbccfba19c51c23480acdb440f2c15d53b7
|
7
|
+
data.tar.gz: 36de4519138b8e10897ac761b99c71fb3b7726808ff11e3ef2ad5bc94cff19852dea31b8d4dedf835b3c025598ed1a832b08941053ba7adf1ebf5a3587d899a1
|
@@ -0,0 +1,24 @@
|
|
1
|
+
name: Ruby
|
2
|
+
|
3
|
+
on:
|
4
|
+
push:
|
5
|
+
branches: [ main ]
|
6
|
+
pull_request:
|
7
|
+
branches: [ main ]
|
8
|
+
|
9
|
+
jobs:
|
10
|
+
test:
|
11
|
+
runs-on: ubuntu-latest
|
12
|
+
strategy:
|
13
|
+
matrix:
|
14
|
+
ruby-version: ['2.6', '2.7', '3.0']
|
15
|
+
|
16
|
+
steps:
|
17
|
+
- uses: actions/checkout@v2
|
18
|
+
- name: Set up Ruby
|
19
|
+
uses: ruby/setup-ruby@v1
|
20
|
+
with:
|
21
|
+
ruby-version: ${{ matrix.ruby-version }}
|
22
|
+
bundler-cache: true # runs 'bundle install' and caches installed gems automatically
|
23
|
+
- name: Run tests
|
24
|
+
run: bundle exec rake
|
data/Gemfile.lock
CHANGED
@@ -1,43 +1,42 @@
|
|
1
1
|
PATH
|
2
2
|
remote: .
|
3
3
|
specs:
|
4
|
-
be_valid (0.1.
|
4
|
+
be_valid (0.1.6)
|
5
5
|
|
6
6
|
GEM
|
7
7
|
remote: https://rubygems.org/
|
8
8
|
specs:
|
9
|
-
activemodel (
|
10
|
-
activesupport (=
|
11
|
-
activerecord (
|
12
|
-
activemodel (=
|
13
|
-
activesupport (=
|
14
|
-
|
15
|
-
activesupport (5.2.5)
|
9
|
+
activemodel (6.1.3.2)
|
10
|
+
activesupport (= 6.1.3.2)
|
11
|
+
activerecord (6.1.3.2)
|
12
|
+
activemodel (= 6.1.3.2)
|
13
|
+
activesupport (= 6.1.3.2)
|
14
|
+
activesupport (6.1.3.2)
|
16
15
|
concurrent-ruby (~> 1.0, >= 1.0.2)
|
17
|
-
i18n (>=
|
18
|
-
minitest (
|
19
|
-
tzinfo (~>
|
20
|
-
|
16
|
+
i18n (>= 1.6, < 2)
|
17
|
+
minitest (>= 5.1)
|
18
|
+
tzinfo (~> 2.0)
|
19
|
+
zeitwerk (~> 2.3)
|
21
20
|
concurrent-ruby (1.1.8)
|
22
21
|
i18n (1.8.10)
|
23
22
|
concurrent-ruby (~> 1.0)
|
24
23
|
minitest (5.14.4)
|
25
24
|
rake (10.5.0)
|
26
25
|
sqlite3 (1.4.2)
|
27
|
-
|
28
|
-
|
29
|
-
|
26
|
+
tzinfo (2.0.4)
|
27
|
+
concurrent-ruby (~> 1.0)
|
28
|
+
zeitwerk (2.4.2)
|
30
29
|
|
31
30
|
PLATFORMS
|
32
31
|
ruby
|
33
32
|
|
34
33
|
DEPENDENCIES
|
35
|
-
activerecord (~>
|
34
|
+
activerecord (~> 6)
|
36
35
|
be_valid!
|
37
|
-
bundler (~>
|
36
|
+
bundler (~> 2)
|
38
37
|
minitest (~> 5.0)
|
39
38
|
rake (~> 10.0)
|
40
39
|
sqlite3 (~> 1.4)
|
41
40
|
|
42
41
|
BUNDLED WITH
|
43
|
-
|
42
|
+
2.2.17
|
data/be_valid.gemspec
CHANGED
@@ -25,9 +25,9 @@ Gem::Specification.new do |spec|
|
|
25
25
|
|
26
26
|
spec.required_ruby_version = '>= 2.3'
|
27
27
|
|
28
|
-
spec.add_development_dependency "bundler", "~>
|
28
|
+
spec.add_development_dependency "bundler", "~> 2"
|
29
29
|
spec.add_development_dependency "rake", "~> 10.0"
|
30
30
|
spec.add_development_dependency "minitest", "~> 5.0"
|
31
|
-
spec.add_development_dependency "activerecord", "~>
|
31
|
+
spec.add_development_dependency "activerecord", "~> 6"
|
32
32
|
spec.add_development_dependency "sqlite3", "~> 1.4"
|
33
33
|
end
|
data/lib/be_valid.rb
CHANGED
data/lib/be_valid/be_valid.rb
CHANGED
data/lib/be_valid/version.rb
CHANGED
@@ -14,15 +14,15 @@ class DateValidator < ActiveModel::EachValidator
|
|
14
14
|
|
15
15
|
# display helpful date format validation message with original value
|
16
16
|
message = options[:time] ? ": #{original_value} is not a valid value. Value must be a date in YYYY-MM-DD or YYYY-MM-DD HH:MM:SS format." : ": #{original_value} is not a valid value. Value must be a date in YYYY-MM-DD."
|
17
|
-
@error_hash.add(attribute, (options[:message] || message))
|
17
|
+
@error_hash.add(attribute, (options[:message] || message), rule_name: options[:rule_name])
|
18
18
|
else
|
19
19
|
# handle validation options on valid date instances
|
20
20
|
return unless value.respond_to?(:strftime)
|
21
21
|
if(options[:after] && (after_message = validate_after_option(record, attribute, value, original_value)) != true)
|
22
|
-
@error_hash.add(attribute, (options[:after_message] || "#{after_message}."))
|
22
|
+
@error_hash.add(attribute, (options[:after_message] || "#{after_message}."), rule_name: options[:rule_name])
|
23
23
|
end
|
24
24
|
if(options[:before] && (before_message = validate_before_option(record, attribute, value, original_value)) != true)
|
25
|
-
@error_hash.add(attribute, (options[:before_message] || "#{before_message}."))
|
25
|
+
@error_hash.add(attribute, (options[:before_message] || "#{before_message}."), rule_name: options[:rule_name])
|
26
26
|
end
|
27
27
|
end
|
28
28
|
end
|
@@ -11,14 +11,16 @@ module ActiveModel
|
|
11
11
|
less_or_equal_to: :<=,
|
12
12
|
not_equal_to: :!=,
|
13
13
|
matching: :=~,
|
14
|
-
# one_of: :in?
|
15
14
|
}.freeze
|
15
|
+
|
16
|
+
REQD_OPTS = (MATCHERS.keys + [:blank, :present, :one_of, :not_any_of, :only_from, :before, :after])
|
16
17
|
|
17
18
|
MESSAGE_PREFIX = "must be"
|
18
19
|
ERRORS_METHOD = :errors
|
19
20
|
|
20
21
|
def validate_each(record, attribute, value)
|
21
|
-
raise "
|
22
|
+
raise "Requires at least one comparison operator for attribute." unless (options.keys & REQD_OPTS).length > 0
|
23
|
+
return if options[:rule_name] && BeValid.config.rules&.fetch(options[:rule_name], {})[:disabled]
|
22
24
|
|
23
25
|
original_value = record.read_attribute_before_type_cast( attribute )
|
24
26
|
|
@@ -30,7 +32,7 @@ module ActiveModel
|
|
30
32
|
return if options[:present] && value.present?
|
31
33
|
message << " present" if options[:present]
|
32
34
|
|
33
|
-
return if options[:one_of] && options[:one_of].include?(value)
|
35
|
+
return if options[:one_of] && Array(options[:one_of]).flatten.include?(value)
|
34
36
|
message = ": '#{value}' is not a valid value" if options[:one_of]
|
35
37
|
|
36
38
|
return if options[:not_any_of] && !(options[:not_any_of].include?(value))
|
@@ -73,8 +75,14 @@ module ActiveModel
|
|
73
75
|
return if !values.match?(record[field])
|
74
76
|
condition_errors << "#{field} = #{record[field]}"
|
75
77
|
when Array
|
76
|
-
return if !values.include?(record[field])
|
78
|
+
return if !values.flatten.include?(record[field])
|
77
79
|
condition_errors << "#{field} = #{record[field]}"
|
80
|
+
when :blank
|
81
|
+
return unless record.send(field).blank?
|
82
|
+
condition_errors << "#{field} is #{values.to_s.gsub('?', '')}"
|
83
|
+
when :present
|
84
|
+
return unless record.send(field).present?
|
85
|
+
condition_errors << "#{field} is #{values.to_s.gsub('?', '')}"
|
78
86
|
when Symbol
|
79
87
|
return if !record.send(field)&.send(values)
|
80
88
|
condition_errors << "#{field} is #{values.to_s.gsub('?', '')}"
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: be_valid
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.1.
|
4
|
+
version: 0.1.7
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- John Stewart (johnsinco)
|
8
8
|
autorequire:
|
9
9
|
bindir: exe
|
10
10
|
cert_chain: []
|
11
|
-
date: 2021-
|
11
|
+
date: 2021-08-18 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: bundler
|
@@ -16,14 +16,14 @@ dependencies:
|
|
16
16
|
requirements:
|
17
17
|
- - "~>"
|
18
18
|
- !ruby/object:Gem::Version
|
19
|
-
version: '
|
19
|
+
version: '2'
|
20
20
|
type: :development
|
21
21
|
prerelease: false
|
22
22
|
version_requirements: !ruby/object:Gem::Requirement
|
23
23
|
requirements:
|
24
24
|
- - "~>"
|
25
25
|
- !ruby/object:Gem::Version
|
26
|
-
version: '
|
26
|
+
version: '2'
|
27
27
|
- !ruby/object:Gem::Dependency
|
28
28
|
name: rake
|
29
29
|
requirement: !ruby/object:Gem::Requirement
|
@@ -58,14 +58,14 @@ dependencies:
|
|
58
58
|
requirements:
|
59
59
|
- - "~>"
|
60
60
|
- !ruby/object:Gem::Version
|
61
|
-
version: '
|
61
|
+
version: '6'
|
62
62
|
type: :development
|
63
63
|
prerelease: false
|
64
64
|
version_requirements: !ruby/object:Gem::Requirement
|
65
65
|
requirements:
|
66
66
|
- - "~>"
|
67
67
|
- !ruby/object:Gem::Version
|
68
|
-
version: '
|
68
|
+
version: '6'
|
69
69
|
- !ruby/object:Gem::Dependency
|
70
70
|
name: sqlite3
|
71
71
|
requirement: !ruby/object:Gem::Requirement
|
@@ -87,6 +87,7 @@ executables: []
|
|
87
87
|
extensions: []
|
88
88
|
extra_rdoc_files: []
|
89
89
|
files:
|
90
|
+
- ".github/workflows/ruby.yml"
|
90
91
|
- ".gitignore"
|
91
92
|
- Gemfile
|
92
93
|
- Gemfile.lock
|
@@ -120,7 +121,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
120
121
|
- !ruby/object:Gem::Version
|
121
122
|
version: '0'
|
122
123
|
requirements: []
|
123
|
-
rubygems_version: 3.
|
124
|
+
rubygems_version: 3.1.6
|
124
125
|
signing_key:
|
125
126
|
specification_version: 4
|
126
127
|
summary: Custom Ruby on Rails Validation library supporting 'conditional' validation
|