Class: RailsVersionedRouting::VersionConstraint
- Inherits:
-
Object
- Object
- RailsVersionedRouting::VersionConstraint
- Defined in:
- lib/rails_versioned_routing.rb
Instance Attribute Summary collapse
-
#version ⇒ Object
readonly
Returns the value of attribute version.
Instance Method Summary collapse
-
#initialize(options) ⇒ VersionConstraint
constructor
A new instance of VersionConstraint.
- #matches?(request) ⇒ Boolean
Constructor Details
#initialize(options) ⇒ VersionConstraint
9 10 11 |
# File 'lib/rails_versioned_routing.rb', line 9 def initialize() @version = .fetch(:version) end |
Instance Attribute Details
#version ⇒ Object (readonly)
Returns the value of attribute version.
7 8 9 |
# File 'lib/rails_versioned_routing.rb', line 7 def version @version end |
Instance Method Details
#matches?(request) ⇒ Boolean
13 14 15 16 17 18 19 20 21 22 23 |
# File 'lib/rails_versioned_routing.rb', line 13 def matches?(request) accept = request.headers.fetch(:accept, '*/*') has_version = accept.match(/version=([\d+])/) if has_version version = has_version.captures.last.to_i return @version <= version else return @version == 1 end end |