localized_each_validator 1.0.3 → 2.0.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 +5 -5
- data/.document +3 -0
- data/.rspec +3 -0
- data/.rubocop.yml +14 -0
- data/.ruby-gemset +1 -0
- data/.ruby-version +1 -0
- data/CHANGELOG.md +46 -0
- data/README.md +81 -0
- data/Rakefile +8 -0
- data/lib/localized_each_validator/version.rb +7 -0
- data/lib/localized_each_validator.rb +27 -25
- data/localized_each_validator.gemspec +40 -54
- metadata +46 -65
- data/README.textile +0 -39
checksums.yaml
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
---
|
|
2
|
-
|
|
3
|
-
metadata.gz:
|
|
4
|
-
data.tar.gz:
|
|
2
|
+
SHA256:
|
|
3
|
+
metadata.gz: c7c26092e8a8fb89fccd9ddccb1c625863774f7f2b616f4af7cac8f9d905b3ed
|
|
4
|
+
data.tar.gz: 12bd6cf9c5b59cdb66690add58f40f4ef5dd191963522cfcc6e33a7a591b186c
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: a40be635f83eae9a3772d07af24c11bac7f6d1006dab727d301ecc94beb566aca345bab283bfc79c808a854d86860edd59105c01e3ecf443b3192aa623fc3664
|
|
7
|
+
data.tar.gz: d287ab7b298c2b357083548779a09d80b1a9b5cc362b742968fd887555932e996c43bd4eb9cd2cb820152ffa51df1290641de56e30cb1e49b2b3b4cabeb460fa
|
data/.document
ADDED
data/.rspec
ADDED
data/.rubocop.yml
ADDED
data/.ruby-gemset
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
lev
|
data/.ruby-version
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
ruby-4.0.3
|
data/CHANGELOG.md
ADDED
|
@@ -0,0 +1,46 @@
|
|
|
1
|
+
# Changelog
|
|
2
|
+
|
|
3
|
+
All notable changes to this project will be documented in this file.
|
|
4
|
+
|
|
5
|
+
The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.1.0/),
|
|
6
|
+
and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).
|
|
7
|
+
|
|
8
|
+
## [2.0.0] - 2026-05-14
|
|
9
|
+
|
|
10
|
+
### Added
|
|
11
|
+
- `lib/localized_each_validator/version.rb` exposing
|
|
12
|
+
`LocalizedEachValidator::VERSION`.
|
|
13
|
+
- `CHANGELOG.md` (this file).
|
|
14
|
+
- `bin/console` and `bin/setup` scripts following the `bundle gem`
|
|
15
|
+
convention.
|
|
16
|
+
- GitHub Actions CI matrix (`.github/workflows/ci.yml`) running RSpec
|
|
17
|
+
against Ruby 3.1, 3.2, 3.3, 3.4 and ActiveModel 7.0, 7.1, 7.2, 8.0.
|
|
18
|
+
|
|
19
|
+
### Changed
|
|
20
|
+
- **BREAKING:** Minimum Ruby version is now 3.1 (was 2.5).
|
|
21
|
+
- **BREAKING:** Minimum ActiveModel version is now 6.1 (was 3.0).
|
|
22
|
+
- Replaced the jeweler-generated gemspec with a hand-written gemspec
|
|
23
|
+
following the `bundle gem` convention.
|
|
24
|
+
- The gem now depends on `activemodel` only; the explicit
|
|
25
|
+
`activesupport` dependency was dropped (it is pulled in transitively
|
|
26
|
+
by ActiveModel).
|
|
27
|
+
- `Gemfile` simplified to a single `gemspec` directive.
|
|
28
|
+
- `Rakefile` rewritten to default to `:spec` without jeweler/yard.
|
|
29
|
+
- `README.md` rewritten to drop Rails 3 framing, fix the incorrect
|
|
30
|
+
superclass in the example, and document `:allow_nil`, `:allow_blank`,
|
|
31
|
+
and `:message` options.
|
|
32
|
+
|
|
33
|
+
### Removed
|
|
34
|
+
- **BREAKING:** The `VERSION` plain-text file is gone. Read
|
|
35
|
+
`LocalizedEachValidator::VERSION` instead.
|
|
36
|
+
- Removed jeweler, RedCloth, yard and the related development tooling.
|
|
37
|
+
- Removed `.travis.yml`.
|
|
38
|
+
|
|
39
|
+
### Fixed
|
|
40
|
+
- Gemspec referenced a non-existent `README.textile` file in `s.files`
|
|
41
|
+
and `s.extra_rdoc_files`; the actual file is `README.md`.
|
|
42
|
+
- Gemspec contained a dead `if respond_to?(:specification_version)`
|
|
43
|
+
fallback branch with duplicate `yard` entries and a missing `rspec`
|
|
44
|
+
dependency. The whole branch is gone.
|
|
45
|
+
- `README.md` example showed `class FourValidator < ActiveRecord::EachValidator`;
|
|
46
|
+
it now correctly subclasses `LocalizedEachValidator`.
|
data/README.md
ADDED
|
@@ -0,0 +1,81 @@
|
|
|
1
|
+
# Localized `EachValidator`
|
|
2
|
+
|
|
3
|
+
[](https://github.com/RISCfuture/localized_each_validator/actions/workflows/ci.yml)
|
|
4
|
+
[](https://rubygems.org/gems/localized_each_validator)
|
|
5
|
+
[](LICENSE)
|
|
6
|
+
|
|
7
|
+
| | |
|
|
8
|
+
| :---------- | :------------------------------ |
|
|
9
|
+
| **Author** | Tim Morgan |
|
|
10
|
+
| **License** | Released under the MIT license. |
|
|
11
|
+
|
|
12
|
+
## About
|
|
13
|
+
|
|
14
|
+
`LocalizedEachValidator` is a small abstract subclass of
|
|
15
|
+
`ActiveModel::EachValidator` that makes it easy to write validators whose
|
|
16
|
+
error messages are looked up through Rails / ActiveModel's I18n
|
|
17
|
+
infrastructure.
|
|
18
|
+
|
|
19
|
+
Subclass `LocalizedEachValidator`, declare an `error_key`, and implement
|
|
20
|
+
`#valid?`. The validator adds the error key to the record's errors when a
|
|
21
|
+
value fails validation; ActiveModel will then resolve that key against the
|
|
22
|
+
standard I18n error message hierarchy.
|
|
23
|
+
|
|
24
|
+
## Installation
|
|
25
|
+
|
|
26
|
+
Add to your `Gemfile`:
|
|
27
|
+
|
|
28
|
+
```ruby
|
|
29
|
+
gem "localized_each_validator"
|
|
30
|
+
```
|
|
31
|
+
|
|
32
|
+
Or, if you're writing your own validator gem, add it to your gemspec:
|
|
33
|
+
|
|
34
|
+
```ruby
|
|
35
|
+
spec.add_dependency "localized_each_validator", "~> 2.0"
|
|
36
|
+
```
|
|
37
|
+
|
|
38
|
+
Then run `bundle install`.
|
|
39
|
+
|
|
40
|
+
## Usage
|
|
41
|
+
|
|
42
|
+
Subclass `LocalizedEachValidator`, set an `error_key`, and implement
|
|
43
|
+
`#valid?`:
|
|
44
|
+
|
|
45
|
+
```ruby
|
|
46
|
+
class FourValidator < LocalizedEachValidator
|
|
47
|
+
error_key :must_be_four
|
|
48
|
+
|
|
49
|
+
def valid?(record, attribute, value)
|
|
50
|
+
value == 4
|
|
51
|
+
end
|
|
52
|
+
end
|
|
53
|
+
```
|
|
54
|
+
|
|
55
|
+
Users of your validator can then add a translation:
|
|
56
|
+
|
|
57
|
+
```yaml
|
|
58
|
+
en:
|
|
59
|
+
activemodel:
|
|
60
|
+
errors:
|
|
61
|
+
messages:
|
|
62
|
+
must_be_four: "must be four"
|
|
63
|
+
```
|
|
64
|
+
|
|
65
|
+
### Options
|
|
66
|
+
|
|
67
|
+
`LocalizedEachValidator` honors the standard `EachValidator` options:
|
|
68
|
+
|
|
69
|
+
* `:allow_nil` — skip validation when the value is `nil`.
|
|
70
|
+
* `:allow_blank` — skip validation when the value is blank.
|
|
71
|
+
* `:message` — override the default `error_key`-based error message with
|
|
72
|
+
a literal string or another symbol.
|
|
73
|
+
|
|
74
|
+
### Default `error_key`
|
|
75
|
+
|
|
76
|
+
If you don't call `error_key`, the default is derived from the class
|
|
77
|
+
name: the trailing `Validator` is stripped, the result is demodulized,
|
|
78
|
+
and `underscore`d. For example, `Auth::EmailAddressValidator` defaults
|
|
79
|
+
to `:email_address`.
|
|
80
|
+
|
|
81
|
+
See the `LocalizedEachValidator` class documentation for more details.
|
data/Rakefile
ADDED
|
@@ -1,17 +1,20 @@
|
|
|
1
|
-
|
|
2
|
-
require 'active_model/validator'
|
|
1
|
+
# frozen_string_literal: true
|
|
3
2
|
|
|
4
|
-
|
|
3
|
+
require "active_support/core_ext/hash/except"
|
|
4
|
+
require "active_model/validator"
|
|
5
|
+
require "localized_each_validator/version"
|
|
6
|
+
|
|
7
|
+
# An `EachValidator` that uses the translation table to build its error
|
|
5
8
|
# messages. Override the {#valid?} method to describe your validation
|
|
6
9
|
# conditions of your subclasses.
|
|
7
10
|
#
|
|
8
11
|
# The error message translation lookups conform to the standard hierarchy of
|
|
9
12
|
# internationalization keys as described by the
|
|
10
|
-
#
|
|
13
|
+
# `ActiveRecord::Errors#generate_message` method. (See its documentation for
|
|
11
14
|
# more information.) The last portion of the translation key path is the error
|
|
12
15
|
# message key, and by default it is the name of the validator class (excepting
|
|
13
16
|
# "Validator"), underscored and demodulized. For example, an
|
|
14
|
-
#
|
|
17
|
+
# `EmailAddressValidator` subclass would use the `email_address` key within the
|
|
15
18
|
# normal ActiveRecord error key structure.
|
|
16
19
|
#
|
|
17
20
|
# @abstract Subclass this validator to perform your specific validations.
|
|
@@ -19,22 +22,10 @@ require 'active_model/validator'
|
|
|
19
22
|
class LocalizedEachValidator < ActiveModel::EachValidator
|
|
20
23
|
# @private
|
|
21
24
|
def validate_each(record, attribute, value)
|
|
22
|
-
return if options[:allow_nil]
|
|
23
|
-
return if options[:allow_blank]
|
|
24
|
-
record.errors.add(attribute, options[:message] || self.class.error_key) unless valid?(record, attribute, value)
|
|
25
|
-
end
|
|
25
|
+
return if options[:allow_nil] && value.nil?
|
|
26
|
+
return if options[:allow_blank] && value.blank?
|
|
26
27
|
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
# @abstract Override this method to return true or false depending on whether
|
|
30
|
-
# @value@ is a valid value for @record@'s @attribute@.
|
|
31
|
-
# @param [ActiveRecord::Base] record The record being validated.
|
|
32
|
-
# @param [Symbol] attribute The attribute with the given value.
|
|
33
|
-
# @param value The value of the attribute to be validated.
|
|
34
|
-
# @return [true, false] Whether the value is valid.
|
|
35
|
-
|
|
36
|
-
def valid?(record, attribute, value)
|
|
37
|
-
raise NotImplementedError, "Implement this method in your subclasses"
|
|
28
|
+
record.errors.add(attribute, options[:message] || self.class.error_key) unless valid?(record, attribute, value)
|
|
38
29
|
end
|
|
39
30
|
|
|
40
31
|
# @overload error_key
|
|
@@ -46,10 +37,21 @@ class LocalizedEachValidator < ActiveModel::EachValidator
|
|
|
46
37
|
# @param [Symbol] value The new error message key.
|
|
47
38
|
|
|
48
39
|
def self.error_key(value=nil)
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
40
|
+
return @error_key || to_s.demodulize.sub(/Validator$/, "").underscore.to_sym unless value
|
|
41
|
+
|
|
42
|
+
@error_key = value
|
|
43
|
+
end
|
|
44
|
+
|
|
45
|
+
protected
|
|
46
|
+
|
|
47
|
+
# @abstract Override this method to return true or false depending on whether
|
|
48
|
+
# `value` is a valid value for `record`'s `attribute`.
|
|
49
|
+
# @param [ActiveRecord::Base] record The record being validated.
|
|
50
|
+
# @param [Symbol] attribute The attribute with the given value.
|
|
51
|
+
# @param value The value of the attribute to be validated.
|
|
52
|
+
# @return [true, false] Whether the value is valid.
|
|
53
|
+
|
|
54
|
+
def valid?(_record, _attribute, _value)
|
|
55
|
+
raise NotImplementedError, "Implement this method in your subclasses"
|
|
54
56
|
end
|
|
55
57
|
end
|
|
@@ -1,57 +1,43 @@
|
|
|
1
|
-
#
|
|
2
|
-
|
|
3
|
-
#
|
|
4
|
-
#
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
"
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
"
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
s.add_runtime_dependency(%q<activemodel>, [">= 3.0"])
|
|
35
|
-
s.add_runtime_dependency(%q<activesupport>, [">= 3.0"])
|
|
36
|
-
s.add_development_dependency(%q<jeweler>, [">= 0"])
|
|
37
|
-
s.add_development_dependency(%q<yard>, [">= 0"])
|
|
38
|
-
s.add_development_dependency(%q<RedCloth>, [">= 0"])
|
|
39
|
-
s.add_development_dependency(%q<rspec>, [">= 0"])
|
|
40
|
-
else
|
|
41
|
-
s.add_dependency(%q<activemodel>, [">= 3.0"])
|
|
42
|
-
s.add_dependency(%q<activesupport>, [">= 3.0"])
|
|
43
|
-
s.add_dependency(%q<jeweler>, [">= 0"])
|
|
44
|
-
s.add_dependency(%q<yard>, [">= 0"])
|
|
45
|
-
s.add_dependency(%q<RedCloth>, [">= 0"])
|
|
46
|
-
s.add_dependency(%q<rspec>, [">= 0"])
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
# Read the version constant from lib/localized_each_validator/version.rb without
|
|
4
|
+
# requiring the file (which would force `active_model` to be loaded during
|
|
5
|
+
# gemspec evaluation, before dependencies are installed).
|
|
6
|
+
version = File.read(File.expand_path("lib/localized_each_validator/version.rb", __dir__))
|
|
7
|
+
.match(/VERSION\s*=\s*["']([^"']+)["']/)[1]
|
|
8
|
+
|
|
9
|
+
Gem::Specification.new do |spec|
|
|
10
|
+
spec.name = "localized_each_validator"
|
|
11
|
+
spec.version = version
|
|
12
|
+
spec.authors = ["Tim Morgan"]
|
|
13
|
+
spec.email = ["git@timothymorgan.info"]
|
|
14
|
+
|
|
15
|
+
spec.summary = "Simple EachValidator with localization support"
|
|
16
|
+
spec.description = "Adds an abstract EachValidator superclass that you can use to create localizable validations."
|
|
17
|
+
spec.homepage = "https://github.com/RISCfuture/localized_each_validator"
|
|
18
|
+
spec.license = "MIT"
|
|
19
|
+
|
|
20
|
+
spec.required_ruby_version = ">= 3.1"
|
|
21
|
+
|
|
22
|
+
spec.metadata = {
|
|
23
|
+
"homepage_uri" => spec.homepage,
|
|
24
|
+
"source_code_uri" => "https://github.com/RISCfuture/localized_each_validator/tree/master",
|
|
25
|
+
"changelog_uri" => "https://github.com/RISCfuture/localized_each_validator/blob/master/CHANGELOG.md",
|
|
26
|
+
"bug_tracker_uri" => "https://github.com/RISCfuture/localized_each_validator/issues",
|
|
27
|
+
"rubygems_mfa_required" => "true"
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
spec.files = Dir.chdir(__dir__) do
|
|
31
|
+
`git ls-files -z`.split("\x0").select { |f| File.exist?(f) }.reject do |f|
|
|
32
|
+
(File.expand_path(f) == __FILE__) ||
|
|
33
|
+
f.start_with?(*%w[bin/ test/ spec/ features/ .git .github .idea Gemfile])
|
|
47
34
|
end
|
|
48
|
-
else
|
|
49
|
-
s.add_dependency(%q<activemodel>, [">= 3.0"])
|
|
50
|
-
s.add_dependency(%q<activesupport>, [">= 3.0"])
|
|
51
|
-
s.add_dependency(%q<jeweler>, [">= 0"])
|
|
52
|
-
s.add_dependency(%q<yard>, [">= 0"])
|
|
53
|
-
s.add_dependency(%q<RedCloth>, [">= 0"])
|
|
54
|
-
s.add_dependency(%q<rspec>, [">= 0"])
|
|
55
35
|
end
|
|
56
|
-
|
|
36
|
+
spec.require_paths = ["lib"]
|
|
57
37
|
|
|
38
|
+
spec.add_dependency "activemodel", ">= 6.1"
|
|
39
|
+
|
|
40
|
+
spec.add_development_dependency "rake", "~> 13.0"
|
|
41
|
+
spec.add_development_dependency "rspec", "~> 3.0"
|
|
42
|
+
spec.add_development_dependency "standard", ">= 1.0"
|
|
43
|
+
end
|
metadata
CHANGED
|
@@ -1,133 +1,114 @@
|
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
|
2
2
|
name: localized_each_validator
|
|
3
3
|
version: !ruby/object:Gem::Version
|
|
4
|
-
version:
|
|
4
|
+
version: 2.0.0
|
|
5
5
|
platform: ruby
|
|
6
6
|
authors:
|
|
7
7
|
- Tim Morgan
|
|
8
|
-
autorequire:
|
|
9
8
|
bindir: bin
|
|
10
9
|
cert_chain: []
|
|
11
|
-
date:
|
|
10
|
+
date: 1980-01-02 00:00:00.000000000 Z
|
|
12
11
|
dependencies:
|
|
13
12
|
- !ruby/object:Gem::Dependency
|
|
14
13
|
name: activemodel
|
|
15
14
|
requirement: !ruby/object:Gem::Requirement
|
|
16
15
|
requirements:
|
|
17
|
-
- -
|
|
16
|
+
- - ">="
|
|
18
17
|
- !ruby/object:Gem::Version
|
|
19
|
-
version: '
|
|
20
|
-
type: :runtime
|
|
21
|
-
prerelease: false
|
|
22
|
-
version_requirements: !ruby/object:Gem::Requirement
|
|
23
|
-
requirements:
|
|
24
|
-
- - '>='
|
|
25
|
-
- !ruby/object:Gem::Version
|
|
26
|
-
version: '3.0'
|
|
27
|
-
- !ruby/object:Gem::Dependency
|
|
28
|
-
name: activesupport
|
|
29
|
-
requirement: !ruby/object:Gem::Requirement
|
|
30
|
-
requirements:
|
|
31
|
-
- - '>='
|
|
32
|
-
- !ruby/object:Gem::Version
|
|
33
|
-
version: '3.0'
|
|
18
|
+
version: '6.1'
|
|
34
19
|
type: :runtime
|
|
35
20
|
prerelease: false
|
|
36
21
|
version_requirements: !ruby/object:Gem::Requirement
|
|
37
22
|
requirements:
|
|
38
|
-
- -
|
|
39
|
-
- !ruby/object:Gem::Version
|
|
40
|
-
version: '3.0'
|
|
41
|
-
- !ruby/object:Gem::Dependency
|
|
42
|
-
name: jeweler
|
|
43
|
-
requirement: !ruby/object:Gem::Requirement
|
|
44
|
-
requirements:
|
|
45
|
-
- - '>='
|
|
46
|
-
- !ruby/object:Gem::Version
|
|
47
|
-
version: '0'
|
|
48
|
-
type: :development
|
|
49
|
-
prerelease: false
|
|
50
|
-
version_requirements: !ruby/object:Gem::Requirement
|
|
51
|
-
requirements:
|
|
52
|
-
- - '>='
|
|
23
|
+
- - ">="
|
|
53
24
|
- !ruby/object:Gem::Version
|
|
54
|
-
version: '
|
|
25
|
+
version: '6.1'
|
|
55
26
|
- !ruby/object:Gem::Dependency
|
|
56
|
-
name:
|
|
27
|
+
name: rake
|
|
57
28
|
requirement: !ruby/object:Gem::Requirement
|
|
58
29
|
requirements:
|
|
59
|
-
- -
|
|
30
|
+
- - "~>"
|
|
60
31
|
- !ruby/object:Gem::Version
|
|
61
|
-
version: '0'
|
|
32
|
+
version: '13.0'
|
|
62
33
|
type: :development
|
|
63
34
|
prerelease: false
|
|
64
35
|
version_requirements: !ruby/object:Gem::Requirement
|
|
65
36
|
requirements:
|
|
66
|
-
- -
|
|
37
|
+
- - "~>"
|
|
67
38
|
- !ruby/object:Gem::Version
|
|
68
|
-
version: '0'
|
|
39
|
+
version: '13.0'
|
|
69
40
|
- !ruby/object:Gem::Dependency
|
|
70
|
-
name:
|
|
41
|
+
name: rspec
|
|
71
42
|
requirement: !ruby/object:Gem::Requirement
|
|
72
43
|
requirements:
|
|
73
|
-
- -
|
|
44
|
+
- - "~>"
|
|
74
45
|
- !ruby/object:Gem::Version
|
|
75
|
-
version: '0'
|
|
46
|
+
version: '3.0'
|
|
76
47
|
type: :development
|
|
77
48
|
prerelease: false
|
|
78
49
|
version_requirements: !ruby/object:Gem::Requirement
|
|
79
50
|
requirements:
|
|
80
|
-
- -
|
|
51
|
+
- - "~>"
|
|
81
52
|
- !ruby/object:Gem::Version
|
|
82
|
-
version: '0'
|
|
53
|
+
version: '3.0'
|
|
83
54
|
- !ruby/object:Gem::Dependency
|
|
84
|
-
name:
|
|
55
|
+
name: standard
|
|
85
56
|
requirement: !ruby/object:Gem::Requirement
|
|
86
57
|
requirements:
|
|
87
|
-
- -
|
|
58
|
+
- - ">="
|
|
88
59
|
- !ruby/object:Gem::Version
|
|
89
|
-
version: '0'
|
|
60
|
+
version: '1.0'
|
|
90
61
|
type: :development
|
|
91
62
|
prerelease: false
|
|
92
63
|
version_requirements: !ruby/object:Gem::Requirement
|
|
93
64
|
requirements:
|
|
94
|
-
- -
|
|
65
|
+
- - ">="
|
|
95
66
|
- !ruby/object:Gem::Version
|
|
96
|
-
version: '0'
|
|
67
|
+
version: '1.0'
|
|
97
68
|
description: Adds an abstract EachValidator superclass that you can use to create
|
|
98
69
|
localizable validations.
|
|
99
|
-
email:
|
|
70
|
+
email:
|
|
71
|
+
- git@timothymorgan.info
|
|
100
72
|
executables: []
|
|
101
73
|
extensions: []
|
|
102
|
-
extra_rdoc_files:
|
|
103
|
-
- LICENSE
|
|
104
|
-
- README.textile
|
|
74
|
+
extra_rdoc_files: []
|
|
105
75
|
files:
|
|
76
|
+
- ".document"
|
|
77
|
+
- ".rspec"
|
|
78
|
+
- ".rubocop.yml"
|
|
79
|
+
- ".ruby-gemset"
|
|
80
|
+
- ".ruby-version"
|
|
81
|
+
- CHANGELOG.md
|
|
106
82
|
- LICENSE
|
|
107
|
-
- README.
|
|
83
|
+
- README.md
|
|
84
|
+
- Rakefile
|
|
108
85
|
- lib/localized_each_validator.rb
|
|
86
|
+
- lib/localized_each_validator/version.rb
|
|
109
87
|
- localized_each_validator.gemspec
|
|
110
|
-
homepage:
|
|
111
|
-
licenses:
|
|
112
|
-
|
|
113
|
-
|
|
88
|
+
homepage: https://github.com/RISCfuture/localized_each_validator
|
|
89
|
+
licenses:
|
|
90
|
+
- MIT
|
|
91
|
+
metadata:
|
|
92
|
+
homepage_uri: https://github.com/RISCfuture/localized_each_validator
|
|
93
|
+
source_code_uri: https://github.com/RISCfuture/localized_each_validator/tree/master
|
|
94
|
+
changelog_uri: https://github.com/RISCfuture/localized_each_validator/blob/master/CHANGELOG.md
|
|
95
|
+
bug_tracker_uri: https://github.com/RISCfuture/localized_each_validator/issues
|
|
96
|
+
rubygems_mfa_required: 'true'
|
|
114
97
|
rdoc_options: []
|
|
115
98
|
require_paths:
|
|
116
99
|
- lib
|
|
117
100
|
required_ruby_version: !ruby/object:Gem::Requirement
|
|
118
101
|
requirements:
|
|
119
|
-
- -
|
|
102
|
+
- - ">="
|
|
120
103
|
- !ruby/object:Gem::Version
|
|
121
|
-
version: '
|
|
104
|
+
version: '3.1'
|
|
122
105
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
|
123
106
|
requirements:
|
|
124
|
-
- -
|
|
107
|
+
- - ">="
|
|
125
108
|
- !ruby/object:Gem::Version
|
|
126
109
|
version: '0'
|
|
127
110
|
requirements: []
|
|
128
|
-
|
|
129
|
-
rubygems_version: 2.0.5
|
|
130
|
-
signing_key:
|
|
111
|
+
rubygems_version: 4.0.11
|
|
131
112
|
specification_version: 4
|
|
132
113
|
summary: Simple EachValidator with localization support
|
|
133
114
|
test_files: []
|
data/README.textile
DELETED
|
@@ -1,39 +0,0 @@
|
|
|
1
|
-
h1. Localized @EachValidator@
|
|
2
|
-
|
|
3
|
-
| *Author* | Tim Morgan |
|
|
4
|
-
| *Version* | 1.0.3 (Jul 23, 2013) |
|
|
5
|
-
| *License* | Released under the MIT license. |
|
|
6
|
-
|
|
7
|
-
h2. About
|
|
8
|
-
|
|
9
|
-
Localized @EachValidator@ is a subclass of ActiveRecord's @EachValidator@ that
|
|
10
|
-
makes it easier to write a localized validator with Rails 3's localization. It's
|
|
11
|
-
small and simple.
|
|
12
|
-
|
|
13
|
-
h2. Usage
|
|
14
|
-
|
|
15
|
-
Add this gem to your project's @Gemfile@, or to your own validator gem's
|
|
16
|
-
dependencies. Then, sublass @LocalizedEachValidator@ and provide the @error_key@
|
|
17
|
-
and override the @valid?@ method, like so:
|
|
18
|
-
|
|
19
|
-
<pre><code>
|
|
20
|
-
class FourValidator < ActiveRecord::EachValidator
|
|
21
|
-
error_key :must_be_four
|
|
22
|
-
|
|
23
|
-
def valid?(record, field, value)
|
|
24
|
-
value == 4
|
|
25
|
-
end
|
|
26
|
-
</code></pre>
|
|
27
|
-
|
|
28
|
-
Now, users of your validator can create a localization YAML file like so:
|
|
29
|
-
|
|
30
|
-
<pre><code>
|
|
31
|
-
en:
|
|
32
|
-
activerecord:
|
|
33
|
-
errors:
|
|
34
|
-
messages:
|
|
35
|
-
must_be_four: This number must be four.
|
|
36
|
-
</code></pre>
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
See the {LocalizedEachValidator} class documentation for more information.
|