Class: SiteHub::LocationRewriters

Inherits:
Array
  • Object
show all
Defined in:
lib/sitehub/location_rewriters.rb

Constant Summary collapse

DEFAULT =
NilLocationRewriter.new

Instance Method Summary collapse

Constructor Details

#initialize(map = {}) ⇒ LocationRewriters

Returns a new instance of LocationRewriters.



7
8
9
10
11
12
13
14
# File 'lib/sitehub/location_rewriters.rb', line 7

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

Instance Method Details

#find(url) ⇒ Object



16
17
18
19
20
21
# File 'lib/sitehub/location_rewriters.rb', line 16

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