Class: ValidAttribute::Matcher

Inherits:
Object
  • Object
show all
Defined in:
lib/valid_attribute/matcher.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(attr) ⇒ Matcher

Returns a new instance of Matcher.



5
6
7
# File 'lib/valid_attribute/matcher.rb', line 5

def initialize(attr)
  self.attr = attr
end

Instance Attribute Details

#attrObject

Returns the value of attribute attr.



3
4
5
# File 'lib/valid_attribute/matcher.rb', line 3

def attr
  @attr
end

#failed_valuesObject

Returns the value of attribute failed_values.



3
4
5
# File 'lib/valid_attribute/matcher.rb', line 3

def failed_values
  @failed_values
end

#passed_valuesObject

Returns the value of attribute passed_values.



3
4
5
# File 'lib/valid_attribute/matcher.rb', line 3

def passed_values
  @passed_values
end

#subjectObject

Returns the value of attribute subject.



3
4
5
# File 'lib/valid_attribute/matcher.rb', line 3

def subject
  @subject
end

#values=(value) ⇒ Object

Sets the attribute values

Parameters:

  • value

    the value to set the attribute values to.



3
4
5
# File 'lib/valid_attribute/matcher.rb', line 3

def values=(value)
  @values = value
end

Instance Method Details

#descriptionObject



30
31
32
# File 'lib/valid_attribute/matcher.rb', line 30

def description
  "be valid when #{attr} is: #{quote_values(values)}"
end

#does_not_match?(subject) ⇒ Boolean

Returns:

  • (Boolean)


39
40
41
42
# File 'lib/valid_attribute/matcher.rb', line 39

def does_not_match?(subject)
  check_values(subject)
  !failed_values.empty? && passed_values.empty?
end

#failure_messageObject



14
15
16
17
18
19
20
# File 'lib/valid_attribute/matcher.rb', line 14

def failure_message
  if failed_values.size == 1
    " expected #{subject.class}##{attr} to accept the value: #{quote_values(failed_values)}"
  else
    " expected #{subject.class}##{attr} to accept the values: #{quote_values(failed_values)}"
  end
end

#matches?(subject) ⇒ Boolean

Returns:

  • (Boolean)


34
35
36
37
# File 'lib/valid_attribute/matcher.rb', line 34

def matches?(subject)
  check_values(subject)
  failed_values.empty?
end

#negative_failure_messageObject



22
23
24
25
26
27
28
# File 'lib/valid_attribute/matcher.rb', line 22

def negative_failure_message
  if passed_values.size == 1
    " expected #{subject.class}##{attr} to reject the value: #{quote_values(passed_values)}"
  else
    " expected #{subject.class}##{attr} to reject the values: #{quote_values(passed_values)}"
  end
end

#when(*values) ⇒ Object



9
10
11
12
# File 'lib/valid_attribute/matcher.rb', line 9

def when(*values)
  self.values = values
  self
end