Module: ArgumentSpecification::DSL::Matchers

Included in:
Argument
Defined in:
lib/argspec/dsl/matchers.rb

Class Method Summary collapse

Class Method Details

.register(klass, name) ⇒ Object

Register a matcher

Arguments:

klass: (ArgumentSpecification::Matchers::BaseMatcher)
name: (Symbol)

Example:

>> Matchers.register(TestMatcher, :test_matcher)
=> true


15
16
17
18
19
20
21
22
23
24
25
26
27
# File 'lib/argspec/dsl/matchers.rb', line 15

def register(klass, name)
  return unless klass.ancestors.include?(ArgumentSpecification::Matchers::BaseMatcher)
  return unless name.is_a?(Symbol)

  module_eval <<-EOS
    def #{name}(*args, &block)
      instance = #{klass}.new(*args)
      instance.send(:setup, '#{name}'.to_sym, args)
      instance.send(:block=, block) if block_given?
      instance
    end
  EOS
end