Module: Hanami::Middleware::BodyParser::ClassInterface Private
- Included in:
- Hanami::Middleware::BodyParser
- Defined in:
- lib/hanami/middleware/body_parser/class_interface.rb
Overview
This module is part of a private API. You should avoid using this module if possible, as it may be removed or be changed in the future.
Instance Method Summary collapse
- #build(parser, **config) ⇒ Object private
- #build_parsers(parser_specs, registry = {}) ⇒ Object private
-
#new(app, parser_specs) ⇒ Object
private
Instantiate a new body parser instance and load its parsers.
Instance Method Details
#build(parser, **config) ⇒ Object
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 |
# File 'lib/hanami/middleware/body_parser/class_interface.rb', line 37 def build(parser, **config) parser = case parser when String, Symbol build(parser_class(parser), **config) when Class parser.new(**config) else parser end ensure_parser parser parser end |
#build_parsers(parser_specs, registry = {}) ⇒ Object
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 |
# File 'lib/hanami/middleware/body_parser/class_interface.rb', line 55 def build_parsers(parser_specs, registry = {}) return DEFAULT_BODY_PARSERS if parser_specs.empty? parsers = Array(parser_specs).flatten(0) parsers.each_with_object(registry) do |spec, memo| if spec.is_a?(Hash) && spec.size > 1 spec.each do |key, value| build_parsers([key => [value]], memo) end else name, *mime_types = Array(*spec).flatten(0) parser = build(name, mime_types: mime_types.flatten) parser.mime_types.each do |mime| memo[mime] = parser end end end end |
#new(app, parser_specs) ⇒ Object
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
Instantiate a new body parser instance and load its parsers
31 32 33 |
# File 'lib/hanami/middleware/body_parser/class_interface.rb', line 31 def new(app, parser_specs) super(app, build_parsers(parser_specs)) end |