Class: Shoulda::Matchers::ActiveModel::RequireAValidRfcMatcher

Inherits:
ValidationMatcher
  • Object
show all
Defined in:
lib/validates_rfc/require_a_valid_rfc_matcher.rb

Instance Method Summary collapse

Constructor Details

#initialize(attribute) ⇒ RequireAValidRfcMatcher

Returns a new instance of RequireAValidRfcMatcher.



13
14
15
16
# File 'lib/validates_rfc/require_a_valid_rfc_matcher.rb', line 13

def initialize(attribute)
  @type = :both
  super
end

Instance Method Details

#descriptionObject



28
29
30
31
32
33
34
# File 'lib/validates_rfc/require_a_valid_rfc_matcher.rb', line 28

def description
  case @type
  when :both then 'requires a valid RFC'
  when :company then 'requires a valid company RFC'
  when :person then 'requires a valid person RFC'
  end
end

#failure_messageObject



36
37
38
39
40
41
42
# File 'lib/validates_rfc/require_a_valid_rfc_matcher.rb', line 36

def failure_message
  case @type
  when :both then 'does not require a valid RFC'
  when :company then 'does not require a valid company RFC'
  when :person then 'does not require a valid person RFC'
  end
end

#for_companyObject



18
19
20
21
# File 'lib/validates_rfc/require_a_valid_rfc_matcher.rb', line 18

def for_company
  @type = :company
  self
end

#for_personObject



23
24
25
26
# File 'lib/validates_rfc/require_a_valid_rfc_matcher.rb', line 23

def for_person
  @type = :person
  self
end

#matches?(subject) ⇒ Boolean

Returns:

  • (Boolean)


44
45
46
47
48
49
50
51
52
# File 'lib/validates_rfc/require_a_valid_rfc_matcher.rb', line 44

def matches?(subject)
  super(subject)

  case @type
  when :both then check_for_both_types
  when :company then check_for_company_type
  when :person then check_for_person_type
  end
end