Sha256: 71eef5e91624d7b74678a4d9bd5ca075c5fa463fedb0c98fc3cdd7e5bc7e374d

Contents?: true

Size: 1.37 KB

Versions: 15

Compression:

Stored size: 1.37 KB

Contents

require 'hanami/utils/class'
require 'hanami/utils/string'
require 'hanami/routing/error'

module Hanami
  module Routing
    module Parsing
      # Body parsing error
      # This is raised when parser fails to parse the body
      #
      # @since 0.5.0
      class BodyParsingError < Hanami::Routing::Error
      end

      # @since 0.2.0
      class UnknownParserError < Hanami::Routing::Error
        # @since 0.2.0
        # @api private
        def initialize(parser)
          super("Unknown Parser: `#{ parser }'")
        end
      end

      # @since 0.2.0
      class Parser
        # @since 0.2.0
        # @api private
        def self.for(parser)
          case parser
          when String, Symbol
            require_parser(parser)
          else
            parser
          end
        end

        # @since 0.2.0
        def mime_types
          raise NotImplementedError
        end

        # @since 0.2.0
        def parse(body)
          Hash.new
        end

        private
        # @since 0.2.0
        # @api private
        def self.require_parser(parser)
          require "hanami/routing/parsing/#{ parser }_parser"

          parser = Utils::String.classify(parser)
          Utils::Class.load!("Hanami::Routing::Parsing::#{ parser }Parser").new
        rescue LoadError, NameError
          raise UnknownParserError.new(parser)
        end
      end
    end
  end
end

Version data entries

15 entries across 15 versions & 1 rubygems

Version Path
hanami-router-1.3.2 lib/hanami/routing/parsing/parser.rb
hanami-router-1.3.1 lib/hanami/routing/parsing/parser.rb
hanami-router-1.3.0 lib/hanami/routing/parsing/parser.rb
hanami-router-1.3.0.beta1 lib/hanami/routing/parsing/parser.rb
hanami-router-1.2.0 lib/hanami/routing/parsing/parser.rb
hanami-router-1.2.0.rc2 lib/hanami/routing/parsing/parser.rb
hanami-router-1.2.0.rc1 lib/hanami/routing/parsing/parser.rb
hanami-router-1.2.0.beta2 lib/hanami/routing/parsing/parser.rb
hanami-router-1.2.0.beta1 lib/hanami/routing/parsing/parser.rb
hanami-router-1.1.1 lib/hanami/routing/parsing/parser.rb
hanami-router-1.1.0 lib/hanami/routing/parsing/parser.rb
hanami-router-1.1.0.rc1 lib/hanami/routing/parsing/parser.rb
hanami-router-1.1.0.beta3 lib/hanami/routing/parsing/parser.rb
hanami-router-1.1.0.beta2 lib/hanami/routing/parsing/parser.rb
hanami-router-1.1.0.beta1 lib/hanami/routing/parsing/parser.rb