Class: Grape::Middleware::Versioner::Base
- Extended by:
- Forwardable
- Includes:
- PrecomputedContentTypes
- Defined in:
- lib/grape/middleware/versioner/base.rb
Direct Known Subclasses
Defined Under Namespace
Classes: Options
Constant Summary collapse
- DEFAULT_OPTIONS =
Deprecated.
Kept as a frozen Hash representation of the Options defaults for back-compat. Will be removed in a future release.
Options.new.to_h.freeze
- CASCADE_PASS_HEADER =
{ 'X-Cascade' => 'pass' }.freeze
Instance Attribute Summary collapse
-
#available_media_types ⇒ Object
readonly
Returns the value of attribute available_media_types.
-
#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 included from PrecomputedContentTypes
#content_type, #content_type_for, #content_types, #mime_types
Methods inherited from Base
#after, #before, #call, #call!, #context, #query_params, #rack_request, #response
Methods included from DSL::Headers
Constructor Details
#initialize(app, **options) ⇒ Base
Returns a new instance of Base.
39 40 41 42 43 44 |
# File 'lib/grape/middleware/versioner/base.rb', line 39 def initialize(app, **) super @versions = config.versions&.map(&:to_s) # making sure versions are strings to ease potential match @error_headers = cascade ? CASCADE_PASS_HEADER : {} @available_media_types = build_available_media_types end |
Instance Attribute Details
#available_media_types ⇒ Object (readonly)
Returns the value of attribute available_media_types.
34 35 36 |
# File 'lib/grape/middleware/versioner/base.rb', line 34 def available_media_types @available_media_types end |
#error_headers ⇒ Object (readonly)
Returns the value of attribute error_headers.
34 35 36 |
# File 'lib/grape/middleware/versioner/base.rb', line 34 def error_headers @error_headers end |
#versions ⇒ Object (readonly)
Returns the value of attribute versions.
34 35 36 |
# File 'lib/grape/middleware/versioner/base.rb', line 34 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, Grape::Exceptions::ErrorResponse.new(status: 404, message: '404 API Version Not Found', headers: CASCADE_PASS_HEADER) end |