Class: ApiConstraints

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

Instance Method Summary collapse

Constructor Details

#initialize(options) ⇒ ApiConstraints

Returns a new instance of ApiConstraints.


2
3
4
5
# File 'lib/api_constraints.rb', line 2

def initialize(options)
  @version = options[:version]
  @default = options.has_key?(:default) ? options[:default] : false
end

Instance Method Details

#matches?(req) ⇒ Boolean

Returns:

  • (Boolean)

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

def matches?(req)
  req.accept =~ /version=([\d\.]+)/
  if (version = $1) # version is specified in header
    version == @version.to_s # are the versions same
  else
    @default # version is not specified, match if it's default version of api
  end
end