Class: Grape::Middleware::Versioner::Base
- Defined in:
- lib/grape/middleware/versioner/base.rb
Direct Known Subclasses
Constant Summary collapse
- DEFAULT_OPTIONS =
{ pattern: /.*/i, prefix: nil, mount_path: nil, version_options: { strict: false, cascade: true, parameter: 'apiver', vendor: nil }.freeze }.freeze
- CASCADE_PASS_HEADER =
{ 'X-Cascade' => 'pass' }.freeze
Instance Attribute Summary collapse
-
#error_headers ⇒ Object
readonly
Returns the value of attribute error_headers.
-
#versions ⇒ Object
readonly
Returns the value of attribute versions.
Attributes inherited from Base
Class Method Summary collapse
Instance Method Summary collapse
-
#initialize(app, **options) ⇒ Base
constructor
A new instance of Base.
- #potential_version_match?(potential_version) ⇒ Boolean
- #version_not_found! ⇒ Object
Methods inherited from Base
#after, #before, #call, #call!, #content_type, #content_type_for, #content_types, #context, #mime_types, #query_params, #rack_request, #response
Methods included from DSL::Headers
Constructor Details
#initialize(app, **options) ⇒ Base
Returns a new instance of Base.
40 41 42 43 44 |
# File 'lib/grape/middleware/versioner/base.rb', line 40 def initialize(app, **) super @error_headers = cascade ? CASCADE_PASS_HEADER : {} @versions = [:versions]&.map(&:to_s) # making sure versions are strings to ease potential match end |
Instance Attribute Details
#error_headers ⇒ Object (readonly)
Returns the value of attribute error_headers.
38 39 40 |
# File 'lib/grape/middleware/versioner/base.rb', line 38 def error_headers @error_headers end |
#versions ⇒ Object (readonly)
Returns the value of attribute versions.
38 39 40 |
# File 'lib/grape/middleware/versioner/base.rb', line 38 def versions @versions end |
Class Method Details
Instance Method Details
#potential_version_match?(potential_version) ⇒ Boolean
46 47 48 |
# File 'lib/grape/middleware/versioner/base.rb', line 46 def potential_version_match?(potential_version) versions.blank? || versions.include?(potential_version) end |
#version_not_found! ⇒ Object
50 51 52 |
# File 'lib/grape/middleware/versioner/base.rb', line 50 def version_not_found! throw :error, status: 404, message: '404 API Version Not Found', headers: CASCADE_PASS_HEADER end |