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

- (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

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

- (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?

Returns:

  • (Boolean)


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)

Returns:

  • (Boolean)


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 failure_message
  message(failed_values, 'accept')
end

- (Boolean) matches?(subject)

Returns:

  • (Boolean)


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 negative_failure_message
  message(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