123456789_123456789_123456789_123456789_123456789_

Class: ActionDispatch::RequestEncoder

Do not use. This class is for internal use only.
Relationships & Source Files
Namespace Children
Classes:
Inherits: Object
Defined in: actionpack/lib/action_dispatch/testing/request_encoder.rb

Class Method Summary

Instance Attribute Summary

Instance Method Summary

Constructor Details

.new(mime_name, param_encoder, response_parser) ⇒ RequestEncoder

[ GitHub ]

  
# File 'actionpack/lib/action_dispatch/testing/request_encoder.rb', line 20

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

Class Method Details

.encoder(name)

[ GitHub ]

  
# File 'actionpack/lib/action_dispatch/testing/request_encoder.rb', line 49

def self.encoder(name)
  @encoders[name] || @encoders[:identity]
end

.parser(content_type)

[ GitHub ]

  
# File 'actionpack/lib/action_dispatch/testing/request_encoder.rb', line 44

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)

[ GitHub ]

  
# File 'actionpack/lib/action_dispatch/testing/request_encoder.rb', line 53

def self.register_encoder(mime_name, param_encoder: nil, response_parser: nil)
  @encoders[mime_name] = new(mime_name, param_encoder, response_parser)
end

Instance Attribute Details

#response_parser (readonly)

[ GitHub ]

  
# File 'actionpack/lib/action_dispatch/testing/request_encoder.rb', line 18

attr_reader :response_parser

Instance Method Details

#accept_header

[ GitHub ]

  
# File 'actionpack/lib/action_dispatch/testing/request_encoder.rb', line 36

def accept_header
  @mime.to_s
end

#content_type

[ GitHub ]

  
# File 'actionpack/lib/action_dispatch/testing/request_encoder.rb', line 32

def content_type
  @mime.to_s
end

#encode_params(params)

[ GitHub ]

  
# File 'actionpack/lib/action_dispatch/testing/request_encoder.rb', line 40

def encode_params(params)
  @param_encoder.call(params) if params
end