Sha256: d509db85fb447dd11acfae6cc19ed766c9300d44cd791774562246d7309d2f71

Contents?: true

Size: 1.31 KB

Versions: 17

Compression:

Stored size: 1.31 KB

Contents

# frozen_string_literal: true

class Sinclair
  module Matchers
    # @api private
    #
    # Common methods for matchers
    class AddMethod < Base
      class << self
        private

        # @api private
        # @private
        #
        # Add a method to generate the final matcher
        #
        # @param name [String,Symbol] the name of the method
        # @param matcher_class [Class<AddMethodTo>] The matcher class to be returned
        #
        # @return (see Sinclair#build)
        #
        # @!macro with_final_matcher
        #   @!method $1(target = nil)
        #   @api public
        #
        #   Builds final matcher
        #
        #   The matcher checks if a method was added
        #   to a class or instance
        #
        #   @param [Class,Object] target where the method will be added
        #
        #   @return [$2]
        def with_final_matcher(name, matcher_class)
          matcher = matcher_class
          Sinclair.new(self).tap do |builder|
            builder.add_method(name) { |target| matcher.new(target, method_name) }
          end.build
        end
      end

      # @abstract
      #
      # Raise a warning on the usage as this is only a builder
      #
      # @raise SyntaxError
      def matches?(_actual)
        raise SyntaxError, matcher_error
      end
    end
  end
end

Version data entries

17 entries across 17 versions & 1 rubygems

Version Path
sinclair-2.1.1 lib/sinclair/matchers/add_method.rb
sinclair-2.1.0 lib/sinclair/matchers/add_method.rb
sinclair-2.0.1 lib/sinclair/matchers/add_method.rb
sinclair-2.0.0 lib/sinclair/matchers/add_method.rb
sinclair-1.16.3 lib/sinclair/matchers/add_method.rb
sinclair-1.16.2 lib/sinclair/matchers/add_method.rb
sinclair-1.16.1 lib/sinclair/matchers/add_method.rb
sinclair-1.16.0 lib/sinclair/matchers/add_method.rb
sinclair-1.15.0 lib/sinclair/matchers/add_method.rb
sinclair-1.14.2 lib/sinclair/matchers/add_method.rb
sinclair-1.14.1 lib/sinclair/matchers/add_method.rb
sinclair-1.14.0 lib/sinclair/matchers/add_method.rb
sinclair-1.13.0 lib/sinclair/matchers/add_method.rb
sinclair-1.12.1 lib/sinclair/matchers/add_method.rb
sinclair-1.12.0 lib/sinclair/matchers/add_method.rb
sinclair-1.11.0 lib/sinclair/matchers/add_method.rb
sinclair-1.10.0 lib/sinclair/matchers/add_method.rb