Module: Grape::Middleware::VersionerHelpers
- Included in:
- Grape::Middleware::Versioner::AcceptVersionHeader, Grape::Middleware::Versioner::Header, Grape::Middleware::Versioner::Param, Grape::Middleware::Versioner::Path
- Defined in:
- lib/grape/middleware/versioner_helpers.rb
Constant Summary collapse
- DEFAULT_PATTERN =
/.*/i.freeze
- DEFAULT_PARAMETER =
'apiver'
Instance Method Summary collapse
-
#cascade? ⇒ Boolean
By default those errors contain an
X-Cascade
header set topass
, which allows nesting and stacking of routes (see Grape::Router) for more information). - #default_options ⇒ Object
- #error_headers ⇒ Object
- #mount_path ⇒ Object
- #parameter_key ⇒ Object
- #pattern ⇒ Object
- #potential_version_match?(potential_version) ⇒ Boolean
- #prefix ⇒ Object
- #strict? ⇒ Boolean
- #vendor ⇒ Object
- #version_not_found! ⇒ Object
- #version_options ⇒ Object
- #versions ⇒ Object
Instance Method Details
#cascade? ⇒ Boolean
By default those errors contain an X-Cascade
header set to pass
, which allows nesting and stacking
of routes (see Grape::Router) for more information). To prevent
this behavior, and not add the X-Cascade
header, one can set the :cascade
option to false
.
50 51 52 |
# File 'lib/grape/middleware/versioner_helpers.rb', line 50 def cascade? [:cascade] end |
#default_options ⇒ Object
9 10 11 12 13 14 15 16 17 18 19 20 21 |
# File 'lib/grape/middleware/versioner_helpers.rb', line 9 def { versions: nil, prefix: nil, mount_path: nil, pattern: DEFAULT_PATTERN, version_options: { strict: false, cascade: true, parameter: DEFAULT_PARAMETER } } end |
#error_headers ⇒ Object
62 63 64 |
# File 'lib/grape/middleware/versioner_helpers.rb', line 62 def error_headers cascade? ? { Grape::Http::Headers::X_CASCADE => 'pass' } : {} end |
#mount_path ⇒ Object
31 32 33 |
# File 'lib/grape/middleware/versioner_helpers.rb', line 31 def mount_path [:mount_path] end |
#parameter_key ⇒ Object
54 55 56 |
# File 'lib/grape/middleware/versioner_helpers.rb', line 54 def parameter_key [:parameter] end |
#pattern ⇒ Object
35 36 37 |
# File 'lib/grape/middleware/versioner_helpers.rb', line 35 def pattern [:pattern] end |
#potential_version_match?(potential_version) ⇒ Boolean
66 67 68 |
# File 'lib/grape/middleware/versioner_helpers.rb', line 66 def potential_version_match?(potential_version) versions.blank? || versions.any? { |v| v.to_s == potential_version } end |
#prefix ⇒ Object
27 28 29 |
# File 'lib/grape/middleware/versioner_helpers.rb', line 27 def prefix [:prefix] end |
#strict? ⇒ Boolean
43 44 45 |
# File 'lib/grape/middleware/versioner_helpers.rb', line 43 def strict? [:strict] end |
#vendor ⇒ Object
58 59 60 |
# File 'lib/grape/middleware/versioner_helpers.rb', line 58 def vendor [:vendor] end |
#version_not_found! ⇒ Object
70 71 72 |
# File 'lib/grape/middleware/versioner_helpers.rb', line 70 def version_not_found! throw :error, status: 404, message: '404 API Version Not Found', headers: { Grape::Http::Headers::X_CASCADE => 'pass' } end |
#version_options ⇒ Object
39 40 41 |
# File 'lib/grape/middleware/versioner_helpers.rb', line 39 def [:version_options] end |
#versions ⇒ Object
23 24 25 |
# File 'lib/grape/middleware/versioner_helpers.rb', line 23 def versions [:versions] end |