Class: Shoulda::Matchers::ActiveModel::ValidateNumericalityOfMatcher

Inherits:
Object
  • Object
show all
Defined in:
lib/shoulda/matchers/active_model/validate_numericality_of_matcher.rb

Constant Summary

NON_NUMERIC_VALUE =
'abcd'

Instance Method Summary (collapse)

Constructor Details

- (ValidateNumericalityOfMatcher) initialize(attribute)

A new instance of ValidateNumericalityOfMatcher



27
28
29
30
31
32
# File 'lib/shoulda/matchers/active_model/validate_numericality_of_matcher.rb', line 27

def initialize(attribute)
  @attribute = attribute
  @submatchers = []

  add_disallow_value_matcher
end

Instance Method Details

- (Object) description



62
63
64
# File 'lib/shoulda/matchers/active_model/validate_numericality_of_matcher.rb', line 62

def description
  "only allow #{allowed_types} values for #{@attribute}"
end

- (Object) even



46
47
48
49
50
# File 'lib/shoulda/matchers/active_model/validate_numericality_of_matcher.rb', line 46

def even
  even_number_matcher = OddEvenNumberMatcher.new(@attribute, :even => true)
  add_submatcher(even_number_matcher)
  self
end

- (Object) failure_message_for_should



66
67
68
# File 'lib/shoulda/matchers/active_model/validate_numericality_of_matcher.rb', line 66

def failure_message_for_should
  submatcher_failure_messages_for_should.last
end

- (Object) failure_message_for_should_not



70
71
72
# File 'lib/shoulda/matchers/active_model/validate_numericality_of_matcher.rb', line 70

def failure_message_for_should_not
  submatcher_failure_messages_for_should_not.last
end

- (Boolean) matches?(subject)

Returns:

  • (Boolean)


57
58
59
60
# File 'lib/shoulda/matchers/active_model/validate_numericality_of_matcher.rb', line 57

def matches?(subject)
  @subject = subject
  submatchers_match?
end

- (Object) odd



40
41
42
43
44
# File 'lib/shoulda/matchers/active_model/validate_numericality_of_matcher.rb', line 40

def odd
  odd_number_matcher = OddEvenNumberMatcher.new(@attribute, :odd => true)
  add_submatcher(odd_number_matcher)
  self
end

- (Object) only_integer



34
35
36
37
38
# File 'lib/shoulda/matchers/active_model/validate_numericality_of_matcher.rb', line 34

def only_integer
  only_integer_matcher = OnlyIntegerMatcher.new(@attribute)
  add_submatcher(only_integer_matcher)
  self
end

- (Object) with_message(message)



52
53
54
55
# File 'lib/shoulda/matchers/active_model/validate_numericality_of_matcher.rb', line 52

def with_message(message)
  @submatchers.each { |matcher| matcher.with_message(message) }
  self
end