Class: Utopia::Responder
- Inherits:
-
Object
- Object
- Utopia::Responder
- Defined in:
- lib/utopia/responder.rb
Direct Known Subclasses
Defined Under Namespace
Instance Attribute Summary collapse
-
#handlers ⇒ Object
readonly
Returns the value of attribute handlers.
Instance Method Summary collapse
- #call(context, request, *arguments, **options) ⇒ Object
- #freeze ⇒ Object
-
#handle(content_type, &block) ⇒ Object
Add a converter for the specified content type.
-
#initialize ⇒ Responder
constructor
A new instance of Responder.
- #respond_to(context, request) ⇒ Object
Constructor Details
Instance Attribute Details
#handlers ⇒ Object (readonly)
Returns the value of attribute handlers.
48 49 50 |
# File 'lib/utopia/responder.rb', line 48 def handlers @handlers end |
Instance Method Details
#call(context, request, *arguments, **options) ⇒ Object
56 57 58 59 60 61 62 63 64 65 |
# File 'lib/utopia/responder.rb', line 56 def call(context, request, *arguments, **) # Parse the list of browser preferred content types and return ordered by priority: media_types = HTTP::Accept::MediaTypes.browser_preferred_media_types(request.env) handler, media_range = @handlers.for(media_types) if handler handler.call(context, request, media_range, *arguments, **) end end |
#freeze ⇒ Object
50 51 52 53 54 |
# File 'lib/utopia/responder.rb', line 50 def freeze @handlers.freeze super end |
#handle(content_type, &block) ⇒ Object
Add a converter for the specified content type. Call the block with the response content if the request accepts the specified content_type.
68 69 70 |
# File 'lib/utopia/responder.rb', line 68 def handle(content_type, &block) @handlers << Handler.new(content_type, block) end |