Class: RocketShorts::RoutingConstraints

Inherits:
Object
  • Object
show all
Defined in:
lib/rocket_shorts/routing_constraints.rb

Instance Method Summary collapse

Constructor Details

#initialize(options) ⇒ RoutingConstraints

Returns a new instance of RoutingConstraints.



3
4
5
6
7
# File 'lib/rocket_shorts/routing_constraints.rb', line 3

def initialize(options)
  @version = options[:version]
  @versions = options[:versions]
  @default = options[:default]
end

Instance Method Details

#matches?(req) ⇒ Boolean

Returns:

  • (Boolean)


9
10
11
12
13
14
15
# File 'lib/rocket_shorts/routing_constraints.rb', line 9

def matches?(req)
  if @versions.present?
    @default || req.headers['Accept'].match(/#{RocketShorts.header_format}#{@versions}/)
  else
    @default || req.headers['Accept'].match(/#{RocketShorts.header_format}#{@version}/)
  end
end