Class: Ward::Matchers::Matcher Abstract

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

Overview

This class is abstract.

A base class used for creating custom matchers.

Direct Known Subclasses

Acceptance, CloseTo, EqualTo, Has, Include, Match, Nil, Predicate, Present, Satisfy

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(expected = nil, *extra_args) ⇒ Matcher

Creates a new matcher instance.

Parameters:

  • expected (Object) (defaults to: nil)

    The expected value for the matcher.



26
27
28
29
# File 'lib/ward/matchers/matcher.rb', line 26

def initialize(expected = nil, *extra_args)
  @expected   = expected
  @extra_args = extra_args
end

Instance Attribute Details

#expectedObject (readonly)

Returns the expected value.

Returns:

  • (Object)


13
14
15
# File 'lib/ward/matchers/matcher.rb', line 13

def expected
  @expected
end

#extra_argsArray (readonly)

Returns any extra arguments given to the matcher.

Returns:

  • (Array)


19
20
21
# File 'lib/ward/matchers/matcher.rb', line 19

def extra_args
  @extra_args
end

Class Method Details

.error_idString

Determines the key to be used to find error messages in lang files.

Returns:

  • (String)


61
62
63
64
# File 'lib/ward/matchers/matcher.rb', line 61

def self.error_id
  @error_id ||= ActiveSupport::Inflector.underscore(
    ActiveSupport::Inflector.demodulize(to_s))
end

Instance Method Details

#customise_error_values(values) ⇒ Hash{Symbol => String}

Allows matcher subclasses to change – or add values to – the hash whose values are interpolated with the error string.

Parameters:

  • The (Hash)

    standard values which are interpolated with the error string; contains :context and :expected keys.

Returns:

  • (Hash{Symbol => String})


53
54
55
# File 'lib/ward/matchers/matcher.rb', line 53

def customise_error_values(values)
  values
end

#matches?(actual) ⇒ Boolean

This method is abstract.

Returns whether the given value matches the expected value.

Parameters:

  • actual (Object)

    The validation value.

Returns:

  • (Boolean)


40
41
42
# File 'lib/ward/matchers/matcher.rb', line 40

def matches?(actual)
  true
end