Class: Gitlab::RouteMap

Inherits:
Object
  • Object
show all
Defined in:
lib/gitlab/route_map.rb

Constant Summary collapse

FormatError =
Class.new(StandardError)

Instance Method Summary collapse

Constructor Details

#initialize(data) ⇒ RouteMap

Returns a new instance of RouteMap.

Raises:



7
8
9
10
11
12
13
14
15
16
17
# File 'lib/gitlab/route_map.rb', line 7

def initialize(data)
  begin
    entries = YAML.safe_load(data)
  rescue StandardError
    raise FormatError, 'Route map is not valid YAML'
  end

  raise FormatError, 'Route map is not an array' unless entries.is_a?(Array)

  @map = entries.map { |entry| parse_entry(entry) }
end

Instance Method Details

#public_path_for_source_path(path) ⇒ Object



19
20
21
22
23
24
25
26
27
28
# File 'lib/gitlab/route_map.rb', line 19

def public_path_for_source_path(path)
  mapping = @map.find { |mapping| mapping[:source] === path }
  return unless mapping

  if mapping[:source].is_a?(String)
    path.sub(mapping[:source], mapping[:public])
  else
    mapping[:source].replace(path, mapping[:public])
  end
end