data_validator 0.0.8 → 0.1.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.
@@ -1,3 +1,3 @@
1
1
  module DataValidator
2
- VERSION = "0.0.8"
2
+ VERSION = "0.1.0"
3
3
  end
@@ -45,7 +45,8 @@ module DataValidator
45
45
  end
46
46
  end
47
47
 
48
- I18n.load_path += Dir[File.join(File.dirname(__FILE__), '..', 'locale', '*.{rb,yml}')]
48
+ I18n.load_path += Dir[File.join(File.dirname(__FILE__), '..', 'locales', '*.{rb,yml}')]
49
+
49
50
  Dir[File.dirname(__FILE__) + "/validations/*.rb"].sort.each do |path|
50
51
  filename = File.basename(path)
51
52
  require "validations/#{filename}"
@@ -3,7 +3,7 @@
3
3
  module DataValidator
4
4
  class AcceptanceValidator < BaseValidator
5
5
  def initialize(name, value, options, errors)
6
- raise ArgumentError, "options must define" unless options
6
+ raise ArgumentError, 'Options must define' unless options
7
7
  case options
8
8
  when Hash
9
9
  options_base = options
@@ -7,7 +7,7 @@ module DataValidator
7
7
  attr_accessor :name, :value, :options, :errors
8
8
 
9
9
  def initialize(name, value, options, errors)
10
- raise ArgumentError, "Options must define" if options.blank?
10
+ raise ArgumentError, 'Options must define' if options.blank?
11
11
 
12
12
  case options
13
13
  when Hash
@@ -25,14 +25,14 @@ module DataValidator
25
25
  end
26
26
 
27
27
  def validate
28
- raise ArgumentError, "Validate method is necessary"
28
+ raise ArgumentError, 'Validate method is necessary'
29
29
  end
30
30
 
31
31
  def add_error(error_message_key, message_args = {})
32
- error_subject_key = "datavalidator.attribute.#{name}"
32
+ error_subject_key = "datavalidator.errors.subjects.#{name}"
33
33
  error_subject = ''
34
34
  begin
35
- error_subject = I18n.t! "datavalidator.attribute.#{name}"
35
+ error_subject = I18n.t! "datavalidator.errors.subjects.#{name}"
36
36
  rescue
37
37
  error_subject = name.to_s
38
38
  end
@@ -4,7 +4,7 @@ module DataValidator
4
4
  class FormatValidator < BaseValidator
5
5
  def check_validity!
6
6
  unless options.include?(:with) ^ options.include?(:without) # ^ == xor, or "exclusive or"
7
- raise ArgumentError, "Either :with or :without must be supplied (but not both)"
7
+ raise ArgumentError, 'Either :with or :without must be supplied (but not both)'
8
8
  end
9
9
  check_options_validity(options, :with)
10
10
  check_options_validity(options, :without)
@@ -2,8 +2,8 @@
2
2
 
3
3
  module DataValidator
4
4
  class InclusionValidator < BaseValidator
5
- ERROR_MESSAGE = "An object with the method #include? or a proc or lambda is required, " <<
6
- "and must be supplied as the :in option of the configuration hash"
5
+ ERROR_MESSAGE = 'An object with the method #include? or a proc or lambda is required, ' <<
6
+ 'and must be supplied as the :in option of the configuration hash'
7
7
 
8
8
  def check_validity!
9
9
  unless [:include?, :call].any?{ |method| options[:in].respond_to?(method) }
@@ -22,4 +22,4 @@ en:
22
22
  less_than_or_equal_to: "must be less than or equal to %{count}"
23
23
  odd: "must be odd"
24
24
  even: "must be even"
25
-
25
+ subjects:
@@ -0,0 +1,8 @@
1
+ jp:
2
+ datavalidator:
3
+ errors:
4
+ messages:
5
+ blank: "は必須項目です"
6
+ subjects:
7
+ name: "名前"
8
+
data/spec/spec_helper.rb CHANGED
@@ -11,4 +11,5 @@ $TESTING=true
11
11
  $:.unshift File.join(File.dirname(__FILE__), '..', 'lib')
12
12
  require 'data_validator'
13
13
 
14
+ I18n.load_path += Dir[File.join(File.dirname(__FILE__), 'locales', '*.{rb,yml}')]
14
15
 
@@ -39,6 +39,14 @@ describe DataValidator::BaseValidator do
39
39
  @obj.errors.should eql({name: ["name can't be blank", "name is invalid"]})
40
40
  end
41
41
  end
42
+ context 'non default locale error message' do
43
+ it do
44
+ I18n.locale = :jp
45
+ @obj.add_error(:blank)
46
+ @obj.errors.should eql({name: ["名前 は必須項目です"]})
47
+ end
48
+ after { I18n.locale = :en }
49
+ end
42
50
  end
43
51
  end
44
52
 
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: data_validator
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.8
4
+ version: 0.1.0
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -9,7 +9,7 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2013-01-14 00:00:00.000000000 Z
12
+ date: 2013-01-18 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: activesupport
@@ -69,8 +69,9 @@ files:
69
69
  - lib/validations/length.rb
70
70
  - lib/validations/numericality.rb
71
71
  - lib/validations/presence.rb
72
- - locale/en.yml
72
+ - locales/en.yml
73
73
  - spec/data_validator_spec.rb
74
+ - spec/locales/jp.yml
74
75
  - spec/spec_helper.rb
75
76
  - spec/validations/acceptance_spec.rb
76
77
  - spec/validations/base_spec.rb
@@ -106,6 +107,7 @@ specification_version: 3
106
107
  summary: DataValidator is validation anywhere
107
108
  test_files:
108
109
  - spec/data_validator_spec.rb
110
+ - spec/locales/jp.yml
109
111
  - spec/spec_helper.rb
110
112
  - spec/validations/acceptance_spec.rb
111
113
  - spec/validations/base_spec.rb