localized_each_validator 1.0.1 → 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 ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA256:
3
+ metadata.gz: c7c26092e8a8fb89fccd9ddccb1c625863774f7f2b616f4af7cac8f9d905b3ed
4
+ data.tar.gz: 12bd6cf9c5b59cdb66690add58f40f4ef5dd191963522cfcc6e33a7a591b186c
5
+ SHA512:
6
+ metadata.gz: a40be635f83eae9a3772d07af24c11bac7f6d1006dab727d301ecc94beb566aca345bab283bfc79c808a854d86860edd59105c01e3ecf443b3192aa623fc3664
7
+ data.tar.gz: d287ab7b298c2b357083548779a09d80b1a9b5cc362b742968fd887555932e996c43bd4eb9cd2cb820152ffa51df1290641de56e30cb1e49b2b3b4cabeb460fa
data/.document CHANGED
@@ -1,5 +1,3 @@
1
- README.rdoc
1
+ README.md
2
2
  lib/**/*.rb
3
- bin/*
4
- features/**/*.feature
5
3
  LICENSE
data/.rspec CHANGED
@@ -1 +1,3 @@
1
- -cfs
1
+ --format documentation
2
+ --color
3
+ --require spec_helper
data/.rubocop.yml ADDED
@@ -0,0 +1,14 @@
1
+ inherit_from:
2
+ - ~/.rubocop.yml
3
+ - ~/.rubocop-rspec.yml
4
+
5
+ inherit_mode:
6
+ merge:
7
+ - Include
8
+ - Exclude
9
+ - Environments
10
+
11
+ AllCops:
12
+ Exclude:
13
+ - "*.gemspec" # temporarily until we move off of juweiler
14
+ TargetRubyVersion: 3.4
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
+ [![CI](https://github.com/RISCfuture/localized_each_validator/actions/workflows/ci.yml/badge.svg)](https://github.com/RISCfuture/localized_each_validator/actions/workflows/ci.yml)
4
+ [![Gem Version](https://img.shields.io/gem/v/localized_each_validator.svg)](https://rubygems.org/gems/localized_each_validator)
5
+ [![License: MIT](https://img.shields.io/badge/license-MIT-blue.svg)](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 CHANGED
@@ -1,36 +1,8 @@
1
- require 'rake'
2
- begin
3
- require 'bundler'
4
- rescue LoadError
5
- puts "Bundler is not installed; install with `gem install bundler`."
6
- exit 1
7
- end
1
+ # frozen_string_literal: true
8
2
 
9
- Bundler.require :default
3
+ require "bundler/gem_tasks"
4
+ require "rspec/core/rake_task"
10
5
 
11
- Jeweler::Tasks.new do |gem|
12
- gem.name = "localized_each_validator"
13
- gem.summary = %Q{Simple EachValidator with localization support}
14
- gem.description = %Q{Adds an abstract EachValidator superclass that you can use to create localizable validations.}
15
- gem.email = "git@timothymorgan.info"
16
- gem.homepage = "http://github.com/riscfuture/localized_each_validator"
17
- gem.authors = [ "Tim Morgan" ]
18
- gem.add_dependency 'activerecord', '>= 3.0'
19
- gem.add_dependency 'activesupport', '>= 3.0'
20
- end
21
- Jeweler::GemcutterTasks.new
6
+ RSpec::Core::RakeTask.new(:spec)
22
7
 
23
- require 'rspec/core/rake_task'
24
- RSpec::Core::RakeTask.new
25
-
26
- YARD::Rake::YardocTask.new('doc') do |doc|
27
- doc.options << "-m" << "textile"
28
- doc.options << "--protected"
29
- doc.options << "-r" << "README.textile"
30
- doc.options << "-o" << "doc"
31
- doc.options << "--title" << "Localized EachValidator Documentation".inspect
32
-
33
- doc.files = [ 'lib/**/*', 'README.textile' ]
34
- end
35
-
36
- task(default: :spec)
8
+ task default: :spec
@@ -0,0 +1,7 @@
1
+ # frozen_string_literal: true
2
+
3
+ require "active_model/validator"
4
+
5
+ class LocalizedEachValidator < ActiveModel::EachValidator
6
+ VERSION = "2.0.0"
7
+ end
@@ -1,42 +1,31 @@
1
- require 'active_support/core_ext/hash/except'
2
- require 'active_record'
1
+ # frozen_string_literal: true
3
2
 
4
- # An @EachValidator@ that uses the translation table to build its error
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
- # @ActiveRecord::Errors#generate_message@ method. (See its documentation for
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
- # @EmailAddressValidator@ subclass would use the @email_address@ key within the
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.
18
21
 
19
22
  class LocalizedEachValidator < ActiveModel::EachValidator
20
- extend ActiveSupport::Memoizable
21
-
22
23
  # @private
23
24
  def validate_each(record, attribute, value)
24
- return if options[:allow_nil] and value.nil?
25
- return if options[:allow_blank] and value.blank?
26
- record.errors.add(attribute, options[:message] || self.class.error_key) unless valid?(record, attribute, value)
27
- end
25
+ return if options[:allow_nil] && value.nil?
26
+ return if options[:allow_blank] && value.blank?
28
27
 
29
- protected
30
-
31
- # @abstract Override this method to return true or false depending on whether
32
- # @value@ is a valid value for @record@'s @attribute@.
33
- # @param [ActiveRecord::Base] record The record being validated.
34
- # @param [Symbol] attribute The attribute with the given value.
35
- # @param value The value of the attribute to be validated.
36
- # @return [true, false] Whether the value is valid.
37
-
38
- def valid?(record, attribute, value)
39
- raise NotImplementedError, "Implement this method in your subclasses"
28
+ record.errors.add(attribute, options[:message] || self.class.error_key) unless valid?(record, attribute, value)
40
29
  end
41
30
 
42
31
  # @overload error_key
@@ -48,10 +37,21 @@ class LocalizedEachValidator < ActiveModel::EachValidator
48
37
  # @param [Symbol] value The new error message key.
49
38
 
50
39
  def self.error_key(value=nil)
51
- if value then
52
- @error_key = value
53
- else
54
- return @error_key || to_s.demodulize.sub(/Validator$/, '').underscore.to_sym
55
- end
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"
56
56
  end
57
57
  end
@@ -1,60 +1,43 @@
1
- # Generated by jeweler
2
- # DO NOT EDIT THIS FILE DIRECTLY
3
- # Instead, edit Jeweler::Tasks in Rakefile, and run the gemspec command
4
- # -*- encoding: utf-8 -*-
5
-
6
- Gem::Specification.new do |s|
7
- s.name = %q{localized_each_validator}
8
- s.version = "1.0.1"
9
-
10
- s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
11
- s.authors = ["Tim Morgan"]
12
- s.date = %q{2010-10-31}
13
- s.description = %q{Adds an abstract EachValidator superclass that you can use to create localizable validations.}
14
- s.email = %q{git@timothymorgan.info}
15
- s.extra_rdoc_files = [
16
- "LICENSE",
17
- "README.textile"
18
- ]
19
- s.files = [
20
- ".document",
21
- ".gitignore",
22
- ".rspec",
23
- "Gemfile",
24
- "Gemfile.lock",
25
- "LICENSE",
26
- "README.textile",
27
- "Rakefile",
28
- "VERSION",
29
- "lib/localized_each_validator.rb",
30
- "localized_each_validator.gemspec",
31
- "spec/localized_each_validator_spec.rb",
32
- "spec/spec_helper.rb"
33
- ]
34
- s.homepage = %q{http://github.com/riscfuture/localized_each_validator}
35
- s.rdoc_options = ["--charset=UTF-8"]
36
- s.require_paths = ["lib"]
37
- s.rubygems_version = %q{1.3.7}
38
- s.summary = %q{Simple EachValidator with localization support}
39
- s.test_files = [
40
- "spec/localized_each_validator_spec.rb",
41
- "spec/spec_helper.rb"
42
- ]
43
-
44
- if s.respond_to? :specification_version then
45
- current_version = Gem::Specification::CURRENT_SPECIFICATION_VERSION
46
- s.specification_version = 3
47
-
48
- if Gem::Version.new(Gem::VERSION) >= Gem::Version.new('1.2.0') then
49
- s.add_runtime_dependency(%q<activerecord>, [">= 3.0"])
50
- s.add_runtime_dependency(%q<activesupport>, [">= 3.0"])
51
- else
52
- s.add_dependency(%q<activerecord>, [">= 3.0"])
53
- s.add_dependency(%q<activesupport>, [">= 3.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])
54
34
  end
55
- else
56
- s.add_dependency(%q<activerecord>, [">= 3.0"])
57
- s.add_dependency(%q<activesupport>, [">= 3.0"])
58
35
  end
59
- end
36
+ spec.require_paths = ["lib"]
60
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,106 +1,114 @@
1
- --- !ruby/object:Gem::Specification
1
+ --- !ruby/object:Gem::Specification
2
2
  name: localized_each_validator
3
- version: !ruby/object:Gem::Version
4
- prerelease: false
5
- segments:
6
- - 1
7
- - 0
8
- - 1
9
- version: 1.0.1
3
+ version: !ruby/object:Gem::Version
4
+ version: 2.0.0
10
5
  platform: ruby
11
- authors:
6
+ authors:
12
7
  - Tim Morgan
13
- autorequire:
14
8
  bindir: bin
15
9
  cert_chain: []
16
-
17
- date: 2010-10-31 00:00:00 -07:00
18
- default_executable:
19
- dependencies:
20
- - !ruby/object:Gem::Dependency
21
- name: activerecord
22
- requirement: &id001 !ruby/object:Gem::Requirement
23
- none: false
24
- requirements:
10
+ date: 1980-01-02 00:00:00.000000000 Z
11
+ dependencies:
12
+ - !ruby/object:Gem::Dependency
13
+ name: activemodel
14
+ requirement: !ruby/object:Gem::Requirement
15
+ requirements:
25
16
  - - ">="
26
- - !ruby/object:Gem::Version
27
- segments:
28
- - 3
29
- - 0
30
- version: "3.0"
17
+ - !ruby/object:Gem::Version
18
+ version: '6.1'
31
19
  type: :runtime
32
20
  prerelease: false
33
- version_requirements: *id001
34
- - !ruby/object:Gem::Dependency
35
- name: activesupport
36
- requirement: &id002 !ruby/object:Gem::Requirement
37
- none: false
38
- requirements:
21
+ version_requirements: !ruby/object:Gem::Requirement
22
+ requirements:
39
23
  - - ">="
40
- - !ruby/object:Gem::Version
41
- segments:
42
- - 3
43
- - 0
44
- version: "3.0"
45
- type: :runtime
24
+ - !ruby/object:Gem::Version
25
+ version: '6.1'
26
+ - !ruby/object:Gem::Dependency
27
+ name: rake
28
+ requirement: !ruby/object:Gem::Requirement
29
+ requirements:
30
+ - - "~>"
31
+ - !ruby/object:Gem::Version
32
+ version: '13.0'
33
+ type: :development
46
34
  prerelease: false
47
- version_requirements: *id002
48
- description: Adds an abstract EachValidator superclass that you can use to create localizable validations.
49
- email: git@timothymorgan.info
35
+ version_requirements: !ruby/object:Gem::Requirement
36
+ requirements:
37
+ - - "~>"
38
+ - !ruby/object:Gem::Version
39
+ version: '13.0'
40
+ - !ruby/object:Gem::Dependency
41
+ name: rspec
42
+ requirement: !ruby/object:Gem::Requirement
43
+ requirements:
44
+ - - "~>"
45
+ - !ruby/object:Gem::Version
46
+ version: '3.0'
47
+ type: :development
48
+ prerelease: false
49
+ version_requirements: !ruby/object:Gem::Requirement
50
+ requirements:
51
+ - - "~>"
52
+ - !ruby/object:Gem::Version
53
+ version: '3.0'
54
+ - !ruby/object:Gem::Dependency
55
+ name: standard
56
+ requirement: !ruby/object:Gem::Requirement
57
+ requirements:
58
+ - - ">="
59
+ - !ruby/object:Gem::Version
60
+ version: '1.0'
61
+ type: :development
62
+ prerelease: false
63
+ version_requirements: !ruby/object:Gem::Requirement
64
+ requirements:
65
+ - - ">="
66
+ - !ruby/object:Gem::Version
67
+ version: '1.0'
68
+ description: Adds an abstract EachValidator superclass that you can use to create
69
+ localizable validations.
70
+ email:
71
+ - git@timothymorgan.info
50
72
  executables: []
51
-
52
73
  extensions: []
53
-
54
- extra_rdoc_files:
55
- - LICENSE
56
- - README.textile
57
- files:
58
- - .document
59
- - .gitignore
60
- - .rspec
61
- - Gemfile
62
- - Gemfile.lock
74
+ extra_rdoc_files: []
75
+ files:
76
+ - ".document"
77
+ - ".rspec"
78
+ - ".rubocop.yml"
79
+ - ".ruby-gemset"
80
+ - ".ruby-version"
81
+ - CHANGELOG.md
63
82
  - LICENSE
64
- - README.textile
83
+ - README.md
65
84
  - Rakefile
66
- - VERSION
67
85
  - lib/localized_each_validator.rb
86
+ - lib/localized_each_validator/version.rb
68
87
  - localized_each_validator.gemspec
69
- - spec/localized_each_validator_spec.rb
70
- - spec/spec_helper.rb
71
- has_rdoc: true
72
- homepage: http://github.com/riscfuture/localized_each_validator
73
- licenses: []
74
-
75
- post_install_message:
76
- rdoc_options:
77
- - --charset=UTF-8
78
- require_paths:
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'
97
+ rdoc_options: []
98
+ require_paths:
79
99
  - lib
80
- required_ruby_version: !ruby/object:Gem::Requirement
81
- none: false
82
- requirements:
100
+ required_ruby_version: !ruby/object:Gem::Requirement
101
+ requirements:
83
102
  - - ">="
84
- - !ruby/object:Gem::Version
85
- hash: 2150682735534993403
86
- segments:
87
- - 0
88
- version: "0"
89
- required_rubygems_version: !ruby/object:Gem::Requirement
90
- none: false
91
- requirements:
103
+ - !ruby/object:Gem::Version
104
+ version: '3.1'
105
+ required_rubygems_version: !ruby/object:Gem::Requirement
106
+ requirements:
92
107
  - - ">="
93
- - !ruby/object:Gem::Version
94
- segments:
95
- - 0
96
- version: "0"
108
+ - !ruby/object:Gem::Version
109
+ version: '0'
97
110
  requirements: []
98
-
99
- rubyforge_project:
100
- rubygems_version: 1.3.7
101
- signing_key:
102
- specification_version: 3
111
+ rubygems_version: 4.0.11
112
+ specification_version: 4
103
113
  summary: Simple EachValidator with localization support
104
- test_files:
105
- - spec/localized_each_validator_spec.rb
106
- - spec/spec_helper.rb
114
+ test_files: []
data/.gitignore DELETED
@@ -1,25 +0,0 @@
1
- ## MAC OS
2
- .DS_Store
3
-
4
- ## TEXTMATE
5
- *.tmproj
6
- tmtags
7
-
8
- ## EMACS
9
- *~
10
- \#*
11
- .\#*
12
-
13
- ## VIM
14
- *.swp
15
-
16
- ## PROJECT::GENERAL
17
- coverage
18
- rdoc
19
- pkg
20
- .bundle
21
- .rvmrc
22
-
23
- ## PROJECT::DOCUMENTATION
24
- .yardoc
25
- doc
data/Gemfile DELETED
@@ -1,13 +0,0 @@
1
- source :rubygems
2
-
3
- # DEPENDENCIES
4
- gem 'activerecord', require: 'active_record'
5
- gem 'activesupport', require: 'active_record'
6
-
7
- # DEVELOPMENT
8
- gem 'jeweler'
9
- gem 'yard'
10
- gem 'RedCloth', require: 'redcloth'
11
-
12
- # TEST
13
- gem 'rspec'
data/Gemfile.lock DELETED
@@ -1,51 +0,0 @@
1
- GEM
2
- remote: http://rubygems.org/
3
- specs:
4
- RedCloth (4.2.3)
5
- activemodel (3.0.1)
6
- activesupport (= 3.0.1)
7
- builder (~> 2.1.2)
8
- i18n (~> 0.4.1)
9
- activerecord (3.0.1)
10
- activemodel (= 3.0.1)
11
- activesupport (= 3.0.1)
12
- arel (~> 1.0.0)
13
- tzinfo (~> 0.3.23)
14
- activesupport (3.0.1)
15
- arel (1.0.1)
16
- activesupport (~> 3.0.0)
17
- builder (2.1.2)
18
- diff-lcs (1.1.2)
19
- gemcutter (0.6.1)
20
- git (1.2.5)
21
- i18n (0.4.2)
22
- jeweler (1.4.0)
23
- gemcutter (>= 0.1.0)
24
- git (>= 1.2.5)
25
- rubyforge (>= 2.0.0)
26
- json_pure (1.4.6)
27
- rspec (2.0.1)
28
- rspec-core (~> 2.0.1)
29
- rspec-expectations (~> 2.0.1)
30
- rspec-mocks (~> 2.0.1)
31
- rspec-core (2.0.1)
32
- rspec-expectations (2.0.1)
33
- diff-lcs (>= 1.1.2)
34
- rspec-mocks (2.0.1)
35
- rspec-core (~> 2.0.1)
36
- rspec-expectations (~> 2.0.1)
37
- rubyforge (2.0.4)
38
- json_pure (>= 1.1.7)
39
- tzinfo (0.3.23)
40
- yard (0.6.1)
41
-
42
- PLATFORMS
43
- ruby
44
-
45
- DEPENDENCIES
46
- RedCloth
47
- activerecord
48
- activesupport
49
- jeweler
50
- rspec
51
- yard
data/README.textile DELETED
@@ -1,39 +0,0 @@
1
- h1. Localized @EachValidator@
2
-
3
- | *Author* | Tim Morgan |
4
- | *Version* | 1.0.1 (Oct 31, 2010) |
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.
data/VERSION DELETED
@@ -1 +0,0 @@
1
- 1.0.1
@@ -1,54 +0,0 @@
1
- require 'spec_helper'
2
-
3
- module SpecSupport
4
- class TestLocalizedEachValidator < LocalizedEachValidator
5
- def valid?(_,_, v) v == 'foo' end
6
- end
7
- class FakeModel
8
- extend ActiveModel::Translation
9
- def errors() @errors ||= ActiveModel::Errors.new(self) end
10
- def self.lookup_ancestors() [ self ] end
11
- def read_attribute_for_validation(_) "mock" end
12
- end
13
- end
14
-
15
- describe LocalizedEachValidator do
16
- before :each do
17
- @model = SpecSupport::FakeModel.new
18
- end
19
-
20
- describe ".error_key_prefix" do
21
- it "should be the downcased name of the validator by default" do
22
- SpecSupport::TestLocalizedEachValidator.error_key.should eql(:test_localized_each)
23
- end
24
-
25
- it "should be able to be set" do
26
- SpecSupport::TestLocalizedEachValidator.error_key(:foo)
27
- SpecSupport::TestLocalizedEachValidator.error_key.should eql(:foo)
28
- SpecSupport::TestLocalizedEachValidator.instance_variable_set :@error_key, nil
29
- end
30
- end
31
-
32
- describe ".validate_each" do
33
- it "should do nothing if given nil and :allow_nil is set" do
34
- SpecSupport::TestLocalizedEachValidator.new(attributes: :field, allow_nil: true).validate_each(@model, :field, nil)
35
- @model.errors.should be_empty
36
- end
37
-
38
- it "should do nothing if given a blank value and :allow_blank is set" do
39
- SpecSupport::TestLocalizedEachValidator.new(attributes: :field, allow_blank: true).validate_each(@model, :field, "")
40
- @model.errors.should be_empty
41
- end
42
-
43
- it "should validate according to the #valid? method" do
44
- SpecSupport::TestLocalizedEachValidator.new(attributes: :field).validate_each(@model, :field, "foo")
45
- @model.errors.should be_empty
46
- end
47
-
48
- it "should add an error if the validation fails" do
49
- SpecSupport::TestLocalizedEachValidator.new(attributes: :field).validate_each(@model, :field, "bar")
50
- @model.errors[:field].should_not be_empty
51
- @model.errors[:field].first.should include('test_localized_each')
52
- end
53
- end
54
- end
data/spec/spec_helper.rb DELETED
@@ -1,10 +0,0 @@
1
- Bundler.require :default, :test
2
-
3
- $LOAD_PATH.unshift(File.dirname(__FILE__))
4
- $LOAD_PATH.unshift(File.join(File.dirname(__FILE__), '..', 'lib'))
5
-
6
- require 'localized_each_validator'
7
-
8
- RSpec.configure do |config|
9
-
10
- end