Sha256: ecc3ac0716f2ce75db37ca28631e69f2a4d759a56b45809e17a533bec3fbbf63

Contents?: true

Size: 585 Bytes

Versions: 35

Compression:

Stored size: 585 Bytes

Contents

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 if matchers["default"]
    end
  end
end

Version data entries

35 entries across 35 versions & 1 rubygems

Version Path
troy-0.0.35 lib/troy/extension_matcher.rb
troy-0.0.34 lib/troy/extension_matcher.rb
troy-0.0.33 lib/troy/extension_matcher.rb
troy-0.0.32 lib/troy/extension_matcher.rb
troy-0.0.31 lib/troy/extension_matcher.rb
troy-0.0.30 lib/troy/extension_matcher.rb
troy-0.0.29 lib/troy/extension_matcher.rb
troy-0.0.28 lib/troy/extension_matcher.rb
troy-0.0.27 lib/troy/extension_matcher.rb
troy-0.0.26 lib/troy/extension_matcher.rb
troy-0.0.25 lib/troy/extension_matcher.rb
troy-0.0.24 lib/troy/extension_matcher.rb
troy-0.0.23 lib/troy/extension_matcher.rb
troy-0.0.22 lib/troy/extension_matcher.rb
troy-0.0.21 lib/troy/extension_matcher.rb
troy-0.0.20 lib/troy/extension_matcher.rb
troy-0.0.19 lib/troy/extension_matcher.rb
troy-0.0.18 lib/troy/extension_matcher.rb
troy-0.0.17 lib/troy/extension_matcher.rb
troy-0.0.16 lib/troy/extension_matcher.rb