Sha256: fee7fa6a133af7ce751eb3ef8b9bf724125a929aece0c4175a8834aadd23917a

Contents?: true

Size: 568 Bytes

Versions: 10

Compression:

Stored size: 568 Bytes

Contents

require 'sitehub/location_rewriter'
require 'sitehub/nil_location_rewriter'
class SiteHub
  class LocationRewriters < Array
    DEFAULT = NilLocationRewriter.new

    include Equality

    def initialize(map = {})
      enriched = map.collect do |pattern, path_template|
        matcher = pattern.is_a?(Regexp) ? pattern : /#{pattern}/
        LocationRewriter.new(matcher, path_template)
      end

      super enriched
    end

    def find(url)
      result = super() do |directive|
        directive.match?(url)
      end
      result || DEFAULT
    end
  end
end

Version data entries

10 entries across 10 versions & 1 rubygems

Version Path
sitehub-0.5.0.alpha12 lib/sitehub/location_rewriters.rb
sitehub-0.5.0.alpha11 lib/sitehub/location_rewriters.rb
sitehub-0.5.0.alpha10 lib/sitehub/location_rewriters.rb
sitehub-0.5.0.alpha8 lib/sitehub/location_rewriters.rb
sitehub-0.5.0.alpha7 lib/sitehub/location_rewriters.rb
sitehub-0.5.0.alpha6 lib/sitehub/location_rewriters.rb
sitehub-0.5.0.alpha5 lib/sitehub/location_rewriters.rb
sitehub-0.5.0.alpha4 lib/sitehub/location_rewriters.rb
sitehub-0.5.0.alpha3 lib/sitehub/location_rewriters.rb
sitehub-0.5.0.alpha2 lib/sitehub/location_rewriters.rb