data_validator 0.0.7 → 0.0.8

Sign up to get free protection for your applications and to get access to all the features.
@@ -1,3 +1,3 @@
1
1
  module DataValidator
2
- VERSION = "0.0.7"
2
+ VERSION = "0.0.8"
3
3
  end
@@ -15,7 +15,7 @@ module DataValidator
15
15
 
16
16
  def validate
17
17
  unless value == options[:accept]
18
- error_add :accepted
18
+ add_error :accepted
19
19
  end
20
20
  end
21
21
 
@@ -28,7 +28,7 @@ module DataValidator
28
28
  raise ArgumentError, "Validate method is necessary"
29
29
  end
30
30
 
31
- def error_add(error_message_key, message_args = {})
31
+ def add_error(error_message_key, message_args = {})
32
32
  error_subject_key = "datavalidator.attribute.#{name}"
33
33
  error_subject = ''
34
34
  begin
@@ -4,7 +4,7 @@ module DataValidator
4
4
  class ConfirmationValidator < BaseValidator
5
5
  def validate
6
6
  if value != options[:criterion]
7
- error_add :confirmation
7
+ add_error :confirmation
8
8
  end
9
9
  end
10
10
  end
@@ -12,9 +12,9 @@ module DataValidator
12
12
 
13
13
  def validate
14
14
  if regexp = options[:with]
15
- error_add :invalid if value.to_s !~ regexp
15
+ add_error :invalid if value.to_s !~ regexp
16
16
  elsif regexp = options[:without]
17
- error_add :invalid if value.to_s =~ regexp
17
+ add_error :invalid if value.to_s =~ regexp
18
18
  end
19
19
  end
20
20
 
@@ -14,7 +14,7 @@ module DataValidator
14
14
  def validate
15
15
  delimiter = options[:in]
16
16
  unless delimiter.send(inclusion_method(delimiter), value)
17
- error_add :inclusion, value: value
17
+ add_error :inclusion, value: value
18
18
  end
19
19
  end
20
20
 
@@ -32,7 +32,7 @@ module DataValidator
32
32
  CHECKS.each do |key, validity_check|
33
33
  next unless check_value = options[key]
34
34
  next if value_length.send(validity_check, check_value)
35
- error_add MESSAGES[key], count: check_value
35
+ add_error MESSAGES[key], count: check_value
36
36
  end
37
37
  end
38
38
 
@@ -16,13 +16,13 @@ module DataValidator
16
16
 
17
17
  def validate
18
18
  unless checked_value = parse_raw_value_as_a_number(value)
19
- error_add :not_a_number
19
+ add_error :not_a_number
20
20
  return
21
21
  end
22
22
 
23
23
  if options[:only_integer]
24
24
  unless checked_value = parse_raw_value_as_an_integer(value)
25
- error_add :not_an_integer
25
+ add_error :not_an_integer
26
26
  return
27
27
  end
28
28
  end
@@ -31,12 +31,12 @@ module DataValidator
31
31
  case option
32
32
  when :odd, :even
33
33
  unless checked_value.to_i.send(CHECKS[option])
34
- error_add option
34
+ add_error option
35
35
  end
36
36
  else
37
37
  option_value = option_value.call(record) if option_value.is_a?(Proc)
38
38
  unless checked_value.send(CHECKS[option], option_value)
39
- error_add option, count: option_value
39
+ add_error option, count: option_value
40
40
  end
41
41
  end
42
42
  end
@@ -4,7 +4,7 @@ module DataValidator
4
4
  class PresenceValidator < BaseValidator
5
5
  def validate
6
6
  if options && (value.nil? || value.blank?)
7
- error_add :blank
7
+ add_error :blank
8
8
  end
9
9
  end
10
10
  end
@@ -24,18 +24,18 @@ describe DataValidator::BaseValidator do
24
24
  end
25
25
  end
26
26
 
27
- describe :error_add do
27
+ describe :add_error do
28
28
  before { @obj = DataValidator::BaseValidator.new(:name, 'value', true, {}) }
29
29
  context 'add an error first' do
30
30
  it do
31
- @obj.error_add(:blank)
31
+ @obj.add_error(:blank)
32
32
  @obj.errors.should eql({name: ["name can't be blank"]})
33
33
  end
34
34
  end
35
35
  context 'add an errors secondly' do
36
36
  it do
37
- @obj.error_add(:blank)
38
- @obj.error_add(:invalid)
37
+ @obj.add_error(:blank)
38
+ @obj.add_error(:invalid)
39
39
  @obj.errors.should eql({name: ["name can't be blank", "name is invalid"]})
40
40
  end
41
41
  end
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.7
4
+ version: 0.0.8
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors: