Class: Easy::Matchers::Validations::ValidateNumericalityOfMatcher

Inherits:
BaseValidationMatcher show all
Defined in:
lib/matchers/validations/numericality_of.rb

Instance Attribute Summary

Attributes inherited from BaseValidationMatcher

#attributes, #failure_message, #failure_message_when_negated, #options, #subject, #type

Instance Method Summary collapse

Methods inherited from BaseValidationMatcher

#class_name

Constructor Details

#initialize(attributes) ⇒ ValidateNumericalityOfMatcher

Returns a new instance of ValidateNumericalityOfMatcher.



9
10
11
# File 'lib/matchers/validations/numericality_of.rb', line 9

def initialize(attributes)
  super(attributes, :numericality)
end

Instance Method Details

#allow_blank(value = true) ⇒ Object



54
55
56
57
# File 'lib/matchers/validations/numericality_of.rb', line 54

def allow_blank(value = true)
  options[:allow_blank] = value
  self
end

#allow_nil(value = true) ⇒ Object



49
50
51
52
# File 'lib/matchers/validations/numericality_of.rb', line 49

def allow_nil(value = true)
  options[:allow_nil] = value
  self
end

#descriptionObject



25
26
27
# File 'lib/matchers/validations/numericality_of.rb', line 25

def description
  "require #{ attributes.join(', ') } to be numeric"
end

#even(value = true) ⇒ Object



99
100
101
102
# File 'lib/matchers/validations/numericality_of.rb', line 99

def even(value = true)
  options[:even] = value
  self
end

#if(symbol_name) ⇒ Object



34
35
36
37
# File 'lib/matchers/validations/numericality_of.rb', line 34

def if(symbol_name)
  options[:if] = symbol_name
  self
end

#is_equal_to(value) ⇒ Object



79
80
81
82
# File 'lib/matchers/validations/numericality_of.rb', line 79

def is_equal_to(value)
  options[:equal_to] = value
  self
end

#is_greater_than(value) ⇒ Object



69
70
71
72
# File 'lib/matchers/validations/numericality_of.rb', line 69

def is_greater_than(value)
  options[:greater_than] = value
  self
end

#is_greater_than_or_equal_to(value) ⇒ Object



74
75
76
77
# File 'lib/matchers/validations/numericality_of.rb', line 74

def is_greater_than_or_equal_to(value)
  options[:greater_than_or_equal_to] = value
  self
end

#is_less_than(value) ⇒ Object



84
85
86
87
# File 'lib/matchers/validations/numericality_of.rb', line 84

def is_less_than(value)
  options[:less_than] = value
  self
end

#is_less_than_or_equal_to(value) ⇒ Object



89
90
91
92
# File 'lib/matchers/validations/numericality_of.rb', line 89

def is_less_than_or_equal_to(value)
  options[:less_than_or_equal_to] = value
  self
end

#is_other_than(value) ⇒ Object



94
95
96
97
# File 'lib/matchers/validations/numericality_of.rb', line 94

def is_other_than(value)
  options[:other_than] = value
  self
end

#matches?(subject) ⇒ Boolean

Returns:

  • (Boolean)


13
14
15
16
17
18
19
20
21
22
23
# File 'lib/matchers/validations/numericality_of.rb', line 13

def matches?(subject)
  super(subject)

  matched_validator = class_name.validators.detect do |validator|
    validator.kind == type &&
      validator.attributes.sort == attributes.sort &&
      validator.options.sort == options.sort
  end

  true if matched_validator
end

#odd(value = true) ⇒ Object



104
105
106
107
# File 'lib/matchers/validations/numericality_of.rb', line 104

def odd(value = true)
  options[:odd] = value
  self
end

#on(context) ⇒ Object



44
45
46
47
# File 'lib/matchers/validations/numericality_of.rb', line 44

def on(context)
  options[:on] = context
  self
end

#only_integer(value = true) ⇒ Object



64
65
66
67
# File 'lib/matchers/validations/numericality_of.rb', line 64

def only_integer(value = true)
  options[:only_integer] = value
  self
end

#strict(value) ⇒ Object



59
60
61
62
# File 'lib/matchers/validations/numericality_of.rb', line 59

def strict(value)
  options[:strict] = value
  self
end

#unless(symbol_name) ⇒ Object



39
40
41
42
# File 'lib/matchers/validations/numericality_of.rb', line 39

def unless(symbol_name)
  options[:unless] = symbol_name
  self
end

#with_message(message) ⇒ Object



29
30
31
32
# File 'lib/matchers/validations/numericality_of.rb', line 29

def with_message(message)
  options[:message] = message
  self
end