Class: ValidAttribute::Matcher
- Inherits:
-
Object
- Object
- ValidAttribute::Matcher
- Defined in:
- lib/valid_attribute/matcher.rb
Instance Attribute Summary (collapse)
-
- (Object) attr
Returns the value of attribute attr.
-
- (Object) failed_values
Returns the value of attribute failed_values.
-
- (Object) passed_values
Returns the value of attribute passed_values.
-
- (Object) subject
Returns the value of attribute subject.
-
- (Object) values
writeonly
Sets the attribute values.
Instance Method Summary (collapse)
-
- (ValidAttribute::Matcher) clone
Force the matcher to clone the subject in between testing each value.
- - (Boolean) clone?
- - (Object) description
- - (Boolean) does_not_match?(subject)
- - (Object) failure_message
-
- (Matcher) initialize(attr)
constructor
A new instance of Matcher.
- - (Boolean) matches?(subject)
- - (Object) negative_failure_message
-
- (ValidAttribute::Matcher) when(*values)
The collection of values to test against for the given attribute.
Constructor Details
- (Matcher) initialize(attr)
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
- (Object) attr
Returns the value of attribute attr
3 4 5 |
# File 'lib/valid_attribute/matcher.rb', line 3 def attr @attr end |
- (Object) failed_values
Returns the value of attribute failed_values
3 4 5 |
# File 'lib/valid_attribute/matcher.rb', line 3 def failed_values @failed_values end |
- (Object) passed_values
Returns the value of attribute passed_values
3 4 5 |
# File 'lib/valid_attribute/matcher.rb', line 3 def passed_values @passed_values end |
- (Object) subject
Returns the value of attribute subject
3 4 5 |
# File 'lib/valid_attribute/matcher.rb', line 3 def subject @subject end |
- (Object) values=(value)
Sets the attribute values
3 4 5 |
# File 'lib/valid_attribute/matcher.rb', line 3 def values=(value) @values = value end |
Instance Method Details
- (ValidAttribute::Matcher) clone
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
53 54 55 |
# File 'lib/valid_attribute/matcher.rb', line 53 def clone @clone = true end |
- (Boolean) clone?
42 43 44 |
# File 'lib/valid_attribute/matcher.rb', line 42 def clone? !!@clone end |
- (Object) description
28 29 30 |
# File 'lib/valid_attribute/matcher.rb', line 28 def description "be valid when #{attr} is: #{quote_values(values)}" end |
- (Boolean) does_not_match?(subject)
37 38 39 40 |
# File 'lib/valid_attribute/matcher.rb', line 37 def does_not_match?(subject) check_values(subject) !failed_values.empty? && passed_values.empty? end |
- (Object) failure_message
20 21 22 |
# File 'lib/valid_attribute/matcher.rb', line 20 def (failed_values, 'accept') end |
- (Boolean) matches?(subject)
32 33 34 35 |
# File 'lib/valid_attribute/matcher.rb', line 32 def matches?(subject) check_values(subject) failed_values.empty? end |
- (Object) negative_failure_message
24 25 26 |
# File 'lib/valid_attribute/matcher.rb', line 24 def (passed_values, 'reject') end |
- (ValidAttribute::Matcher) when(*values)
The collection of values to test against for the given attribute
15 16 17 18 |
# File 'lib/valid_attribute/matcher.rb', line 15 def when(*values) self.values = values self end |