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.
18 19 20 21 22 23 24 25 26 27 28 |
# File 'lib/action_dispatch/testing/request_encoder.rb', line 18 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.
16 17 18 |
# File 'lib/action_dispatch/testing/request_encoder.rb', line 16 def response_parser @response_parser end |
Class Method Details
.encoder(name) ⇒ Object
47 48 49 |
# File 'lib/action_dispatch/testing/request_encoder.rb', line 47 def self.encoder(name) @encoders[name] || @encoders[:identity] end |
.parser(content_type) ⇒ Object
42 43 44 45 |
# File 'lib/action_dispatch/testing/request_encoder.rb', line 42 def self.parser(content_type) type = Mime::Type.lookup(content_type).ref if content_type encoder(type).response_parser end |
.register_encoder(mime_name, param_encoder: nil, response_parser: nil) ⇒ Object
51 52 53 |
# File 'lib/action_dispatch/testing/request_encoder.rb', line 51 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
34 35 36 |
# File 'lib/action_dispatch/testing/request_encoder.rb', line 34 def accept_header @mime.to_s end |
#content_type ⇒ Object
30 31 32 |
# File 'lib/action_dispatch/testing/request_encoder.rb', line 30 def content_type @mime.to_s end |
#encode_params(params) ⇒ Object
38 39 40 |
# File 'lib/action_dispatch/testing/request_encoder.rb', line 38 def encode_params(params) @param_encoder.call(params) if params end |