Sha256: 5cd0bbb10232d1a2fa0000d545872f4d21e2b71a56093778ad8a255ec401169e

Contents?: true

Size: 839 Bytes

Versions: 23

Compression:

Stored size: 839 Bytes

Contents

# frozen_string_literal: true

module SlimLint::Matcher
  # Wraps a matcher, taking on the behavior of the wrapped matcher but storing
  # the value that matched so it can be referred to later.
  class Capture < Base
    # @return [SlimLint::Matcher::Base] matcher that this capture wraps
    attr_accessor :matcher

    # @return [Object] value that was captured
    attr_accessor :value

    # Creates a capture that wraps that given matcher.
    #
    # @param matcher [SlimLint::Matcher::Base]
    # @return [SlimLint::Matcher::Capture]
    def self.from_matcher(matcher)
      new.tap do |cap_matcher|
        cap_matcher.matcher = matcher
      end
    end

    # @see {SlimLint::Matcher::Base#match?}
    def match?(object)
      if result = @matcher.match?(object)
        @value = object
      end

      result
    end
  end
end

Version data entries

23 entries across 23 versions & 1 rubygems

Version Path
slim_lint-0.31.1 lib/slim_lint/matcher/capture.rb
slim_lint-0.31.0 lib/slim_lint/matcher/capture.rb
slim_lint-0.30.0 lib/slim_lint/matcher/capture.rb
slim_lint-0.29.0 lib/slim_lint/matcher/capture.rb
slim_lint-0.28.0 lib/slim_lint/matcher/capture.rb
slim_lint-0.27.0 lib/slim_lint/matcher/capture.rb
slim_lint-0.26.0 lib/slim_lint/matcher/capture.rb
slim_lint-0.25.0 lib/slim_lint/matcher/capture.rb
slim_lint-0.24.0 lib/slim_lint/matcher/capture.rb
slim_lint-0.23.0 lib/slim_lint/matcher/capture.rb
slim_lint-0.22.1 lib/slim_lint/matcher/capture.rb
slim_lint-0.22.0 lib/slim_lint/matcher/capture.rb
slim_lint-0.21.1 lib/slim_lint/matcher/capture.rb
slim_lint-0.21.0 lib/slim_lint/matcher/capture.rb
slim_lint-0.20.2 lib/slim_lint/matcher/capture.rb
slim_lint-0.20.1 lib/slim_lint/matcher/capture.rb
slim_lint-0.20.0 lib/slim_lint/matcher/capture.rb
slim_lint-0.19.0 lib/slim_lint/matcher/capture.rb
slim_lint-0.18.0 lib/slim_lint/matcher/capture.rb
slim_lint-0.17.1 lib/slim_lint/matcher/capture.rb