Class: ValidAttribute::Matcher
- Inherits:
-
Object
- Object
- ValidAttribute::Matcher
- Defined in:
- lib/valid_attribute/matcher.rb
Instance Attribute Summary collapse
-
#attr ⇒ Object
Returns the value of attribute attr.
-
#failed_values ⇒ Object
Returns the value of attribute failed_values.
-
#passed_values ⇒ Object
Returns the value of attribute passed_values.
-
#subject ⇒ Object
Returns the value of attribute subject.
-
#values ⇒ Object
writeonly
Sets the attribute values.
Instance Method Summary collapse
- #description ⇒ Object
- #does_not_match?(subject) ⇒ Boolean
- #failure_message ⇒ Object
-
#initialize(attr) ⇒ Matcher
constructor
A new instance of Matcher.
- #matches?(subject) ⇒ Boolean
- #negative_failure_message ⇒ Object
- #when(*values) ⇒ Object
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
#attr ⇒ Object
Returns the value of attribute attr.
3 4 5 |
# File 'lib/valid_attribute/matcher.rb', line 3 def attr @attr end |
#failed_values ⇒ Object
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_values ⇒ Object
Returns the value of attribute passed_values.
3 4 5 |
# File 'lib/valid_attribute/matcher.rb', line 3 def passed_values @passed_values end |
#subject ⇒ Object
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
3 4 5 |
# File 'lib/valid_attribute/matcher.rb', line 3 def values=(value) @values = value end |
Instance Method Details
#description ⇒ Object
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
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_message ⇒ Object
14 15 16 17 18 19 20 |
# File 'lib/valid_attribute/matcher.rb', line 14 def 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
34 35 36 37 |
# File 'lib/valid_attribute/matcher.rb', line 34 def matches?(subject) check_values(subject) failed_values.empty? end |
#negative_failure_message ⇒ Object
22 23 24 25 26 27 28 |
# File 'lib/valid_attribute/matcher.rb', line 22 def 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 |