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.
31 32 33 |
# File 'lib/utopia/responder.rb', line 31 def handlers @handlers end |
Instance Method Details
#call(context, request, *arguments, **options) ⇒ Object
39 40 41 42 43 44 45 46 47 48 |
# File 'lib/utopia/responder.rb', line 39 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
33 34 35 36 37 |
# File 'lib/utopia/responder.rb', line 33 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.
51 52 53 |
# File 'lib/utopia/responder.rb', line 51 def handle(content_type, &block) @handlers << Handler.new(content_type, block) end |