Sha256: b8adf9bbe718a52aca9d4716fe90a14f6ab3a5ebb76010dcd067c3c5820e91a6

Contents?: true

Size: 558 Bytes

Versions: 4

Compression:

Stored size: 558 Bytes

Contents

# frozen_string_literal: true

module Troy
  class ExtensionMatcher
    attr_reader :path

    attr_reader :performed

    attr_reader :matchers

    def initialize(path)
      @path = path
      @matchers = {}
    end

    def on(extension, &block)
      matchers[".#{extension}"] = block
      self
    end

    def default(&block)
      matchers["default"] = block
      self
    end

    def match
      matchers.each do |ext, handler|
        return handler.call if File.extname(path) == ext
      end

      matchers["default"]&.call
    end
  end
end

Version data entries

4 entries across 4 versions & 1 rubygems

Version Path
troy-0.0.39 lib/troy/extension_matcher.rb
troy-0.0.38 lib/troy/extension_matcher.rb
troy-0.0.37 lib/troy/extension_matcher.rb
troy-0.0.36 lib/troy/extension_matcher.rb