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
-
#clone ⇒ ValidAttribute::Matcher
Force the matcher to clone the subject in between testing each value.
- #clone? ⇒ Boolean
- #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 (also: #failure_message_when_negated)
-
#when(*values) ⇒ ValidAttribute::Matcher
The collection of values to test against for the given attribute.
Constructor Details
#initialize(attr) ⇒ Matcher
Returns a new instance of Matcher.
6 7 8 9 |
# File 'lib/valid_attribute/matcher.rb', line 6 def initialize(attr) self.attr = attr @clone = nil 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
4 5 6 |
# File 'lib/valid_attribute/matcher.rb', line 4 def values=(value) @values = value end |
Instance Method Details
#clone ⇒ ValidAttribute::Matcher
Force the matcher to clone the subject in between testing each value.
Warning This could lead to unintended results. The clone is not a deep copy
56 57 58 |
# File 'lib/valid_attribute/matcher.rb', line 56 def clone @clone = true end |
#clone? ⇒ Boolean
45 46 47 |
# File 'lib/valid_attribute/matcher.rb', line 45 def clone? !!@clone end |
#description ⇒ Object
31 32 33 |
# File 'lib/valid_attribute/matcher.rb', line 31 def description "be valid when #{attr} is: #{quote_values(values)}" end |
#does_not_match?(subject) ⇒ Boolean
40 41 42 43 |
# File 'lib/valid_attribute/matcher.rb', line 40 def does_not_match?(subject) check_values(subject) !failed_values.empty? && passed_values.empty? end |
#failure_message ⇒ Object
22 23 24 |
# File 'lib/valid_attribute/matcher.rb', line 22 def (failed_values, 'accept') end |
#matches?(subject) ⇒ Boolean
35 36 37 38 |
# File 'lib/valid_attribute/matcher.rb', line 35 def matches?(subject) check_values(subject) failed_values.empty? end |
#negative_failure_message ⇒ Object Also known as: failure_message_when_negated
26 27 28 |
# File 'lib/valid_attribute/matcher.rb', line 26 def (passed_values, 'reject') end |
#when(*values) ⇒ ValidAttribute::Matcher
The collection of values to test against for the given attribute
17 18 19 20 |
# File 'lib/valid_attribute/matcher.rb', line 17 def when(*values) self.values = values self end |