Class: Grape::Util::AcceptHeaderHandler
- Inherits:
-
Object
- Object
- Grape::Util::AcceptHeaderHandler
- Defined in:
- lib/grape/util/accept_header_handler.rb
Instance Attribute Summary collapse
-
#accept_header ⇒ Object
readonly
Returns the value of attribute accept_header.
-
#cascade ⇒ Object
readonly
Returns the value of attribute cascade.
-
#strict ⇒ Object
readonly
Returns the value of attribute strict.
-
#vendor ⇒ Object
readonly
Returns the value of attribute vendor.
-
#versions ⇒ Object
readonly
Returns the value of attribute versions.
Instance Method Summary collapse
-
#initialize(accept_header:, versions:, **options) ⇒ AcceptHeaderHandler
constructor
A new instance of AcceptHeaderHandler.
- #match_best_quality_media_type!(content_types: Grape::ContentTypes::CONTENT_TYPES, allowed_methods: nil) ⇒ Object
Constructor Details
#initialize(accept_header:, versions:, **options) ⇒ AcceptHeaderHandler
Returns a new instance of AcceptHeaderHandler.
8 9 10 11 12 13 14 |
# File 'lib/grape/util/accept_header_handler.rb', line 8 def initialize(accept_header:, versions:, **) @accept_header = accept_header @versions = versions @vendor = .fetch(:vendor, nil) @strict = .fetch(:strict, false) @cascade = .fetch(:cascade, true) end |
Instance Attribute Details
#accept_header ⇒ Object (readonly)
Returns the value of attribute accept_header.
6 7 8 |
# File 'lib/grape/util/accept_header_handler.rb', line 6 def accept_header @accept_header end |
#cascade ⇒ Object (readonly)
Returns the value of attribute cascade.
6 7 8 |
# File 'lib/grape/util/accept_header_handler.rb', line 6 def cascade @cascade end |
#strict ⇒ Object (readonly)
Returns the value of attribute strict.
6 7 8 |
# File 'lib/grape/util/accept_header_handler.rb', line 6 def strict @strict end |
#vendor ⇒ Object (readonly)
Returns the value of attribute vendor.
6 7 8 |
# File 'lib/grape/util/accept_header_handler.rb', line 6 def vendor @vendor end |
#versions ⇒ Object (readonly)
Returns the value of attribute versions.
6 7 8 |
# File 'lib/grape/util/accept_header_handler.rb', line 6 def versions @versions end |
Instance Method Details
#match_best_quality_media_type!(content_types: Grape::ContentTypes::CONTENT_TYPES, allowed_methods: nil) ⇒ Object
16 17 18 19 20 21 22 23 24 25 26 |
# File 'lib/grape/util/accept_header_handler.rb', line 16 def match_best_quality_media_type!(content_types: Grape::ContentTypes::CONTENT_TYPES, allowed_methods: nil) return unless vendor strict_header_checks! media_type = Grape::Util::MediaType.best_quality(accept_header, available_media_types(content_types)) if media_type yield media_type else fail!(allowed_methods) end end |