Class: ActionDispatch::RequestEncoder
- Inherits:
-
Object
- Object
- ActionDispatch::RequestEncoder
- Defined in:
- lib/action_dispatch/testing/request_encoder.rb
Overview
:nodoc:
Defined Under Namespace
Classes: IdentityEncoder
Instance Attribute Summary collapse
-
#response_parser ⇒ Object
readonly
Returns the value of attribute response_parser.
Class Method Summary collapse
- .encoder(name) ⇒ Object
- .parser(content_type) ⇒ Object
- .register_encoder(mime_name, param_encoder: nil, response_parser: nil) ⇒ Object
Instance Method Summary collapse
- #accept_header ⇒ Object
- #content_type ⇒ Object
- #encode_params(params) ⇒ Object
-
#initialize(mime_name, param_encoder, response_parser) ⇒ RequestEncoder
constructor
A new instance of RequestEncoder.
Constructor Details
#initialize(mime_name, param_encoder, response_parser) ⇒ RequestEncoder
Returns a new instance of RequestEncoder.
16 17 18 19 20 21 22 23 24 25 26 |
# File 'lib/action_dispatch/testing/request_encoder.rb', line 16 def initialize(mime_name, param_encoder, response_parser) @mime = Mime[mime_name] unless @mime raise ArgumentError, "Can't register a request encoder for " \ "unregistered MIME Type: #{mime_name}. See `Mime::Type.register`." end @response_parser = response_parser || -> body { body } @param_encoder = param_encoder || :"to_#{@mime.symbol}".to_proc end |
Instance Attribute Details
#response_parser ⇒ Object (readonly)
Returns the value of attribute response_parser.
14 15 16 |
# File 'lib/action_dispatch/testing/request_encoder.rb', line 14 def response_parser @response_parser end |
Class Method Details
.encoder(name) ⇒ Object
45 46 47 |
# File 'lib/action_dispatch/testing/request_encoder.rb', line 45 def self.encoder(name) @encoders[name] || @encoders[:identity] end |
.parser(content_type) ⇒ Object
40 41 42 43 |
# File 'lib/action_dispatch/testing/request_encoder.rb', line 40 def self.parser(content_type) mime = Mime::Type.lookup(content_type) encoder(mime ? mime.ref : nil).response_parser end |
.register_encoder(mime_name, param_encoder: nil, response_parser: nil) ⇒ Object
49 50 51 |
# File 'lib/action_dispatch/testing/request_encoder.rb', line 49 def self.register_encoder(mime_name, param_encoder: nil, response_parser: nil) @encoders[mime_name] = new(mime_name, param_encoder, response_parser) end |
Instance Method Details
#accept_header ⇒ Object
32 33 34 |
# File 'lib/action_dispatch/testing/request_encoder.rb', line 32 def accept_header @mime.to_s end |
#content_type ⇒ Object
28 29 30 |
# File 'lib/action_dispatch/testing/request_encoder.rb', line 28 def content_type @mime.to_s end |
#encode_params(params) ⇒ Object
36 37 38 |
# File 'lib/action_dispatch/testing/request_encoder.rb', line 36 def encode_params(params) @param_encoder.call(params) if params end |