Class: Insights::API::Common::Routing

Inherits:
Object
  • Object
show all
Defined in:
lib/insights/api/common/routing.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(route_mapper) ⇒ Routing

Returns a new instance of Routing.



7
8
9
# File 'lib/insights/api/common/routing.rb', line 7

def initialize(route_mapper)
  @route_mapper = route_mapper
end

Instance Attribute Details

#route_mapperObject (readonly)

Returns the value of attribute route_mapper.



5
6
7
# File 'lib/insights/api/common/routing.rb', line 5

def route_mapper
  @route_mapper
end

Instance Method Details

#redirect_major_version(version, prefix, via: [:delete, :get, :options]) ⇒ Object



11
12
13
14
15
16
17
18
19
20
21
22
# File 'lib/insights/api/common/routing.rb', line 11

def redirect_major_version(version, prefix, via: [:delete, :get, :options])
  route_mapper.match(
    "/#{version.split('.').first}/*path(.:format)",
    :format => false,
    :via    => via,
    :to     => route_mapper.redirect(
      :path      => "/#{prefix}/#{version}/%{path}",
      :only_path => true,
      :status    => 302
    )
  )
end