Sha256: eac20a736f97780006bb0c3ec5418fcdfa1c5171aeeabb6675a3da6a8aff8ca7

Contents?: true

Size: 1.19 KB

Versions: 18

Compression:

Stored size: 1.19 KB

Contents

module Mutant
  class Matcher
    # A chain of matchers
    class Chain < self
      include Equalizer.new(:matchers)

      # Enumerate subjects
      #
      # @return [Enumerator<Subject]
      #   returns subject enumerator if no block given
      #
      # @return [self]
      #   returnns self otherwise
      #
      # @api private
      #
      def each(&block)
        return to_enum unless block_given?

        matchers.each do |matcher|
          matcher.each(&block)
        end

        self
      end

      # Return the chain of matchers
      #
      # @return [Enumerable<Chain>]
      #
      # @api private
      #
      attr_reader :matchers

      # Build matcher chain
      #
      # @param [Enumerable<Matcher>] matchers
      #
      # @return [Matcher]
      #
      # @api private
      #
      def self.build(matchers)
        if matchers.length == 1
          return matchers.first
        end

        new(matchers)
      end

    private

      # Initialize chain matcher
      #
      # @param [Enumerable<Matcher>] matchers
      #
      # @return [undefined]
      #
      # @api private
      #
      def initialize(matchers)
        @matchers = matchers
      end
    end
  end
end

Version data entries

18 entries across 18 versions & 1 rubygems

Version Path
mutant-0.2.20 lib/mutant/matcher/chain.rb
mutant-0.2.17 lib/mutant/matcher/chain.rb
mutant-0.2.16 lib/mutant/matcher/chain.rb
mutant-0.2.15 lib/mutant/matcher/chain.rb
mutant-0.2.14 lib/mutant/matcher/chain.rb
mutant-0.2.13 lib/mutant/matcher/chain.rb
mutant-0.2.12 lib/mutant/matcher/chain.rb
mutant-0.2.11 lib/mutant/matcher/chain.rb
mutant-0.2.9 lib/mutant/matcher/chain.rb
mutant-0.2.8 lib/mutant/matcher/chain.rb
mutant-0.2.7 lib/mutant/matcher/chain.rb
mutant-0.2.6 lib/mutant/matcher/chain.rb
mutant-0.2.5 lib/mutant/matcher/chain.rb
mutant-0.2.4 lib/mutant/matcher/chain.rb
mutant-0.2.3 lib/mutant/matcher/chain.rb
mutant-0.2.2 lib/mutant/matcher/chain.rb
mutant-0.2.1 lib/mutant/matcher/chain.rb
mutant-0.2.0 lib/mutant/matcher/chain.rb