Sha256: 306e842d8552e8191167049edac735261ff6d47de6cab74bd5854e8e1d0bee90

Contents?: true

Size: 596 Bytes

Versions: 3

Compression:

Stored size: 596 Bytes

Contents

# frozen_string_literal: true
module Aitch
  module ResponseParser
    PARSERS = []

    def self.prepend(name, parser)
      unregister(name)
      PARSERS.unshift parser
    end

    def self.append(name, parser)
      unregister(name)
      PARSERS << parser
    end

    def self.unregister(name)
      PARSERS.delete_if {|parser| parser.type == name }
    end

    def self.find(content_type)
      PARSERS.find {|parser| parser.match?(content_type) }
    end

    append :json, JSONParser
    append :xml, XMLParser
    append :html, HTMLParser
    append :default, DefaultParser
  end
end

Version data entries

3 entries across 3 versions & 1 rubygems

Version Path
aitch-1.0.2 lib/aitch/response_parser.rb
aitch-1.0.1 lib/aitch/response_parser.rb
aitch-1.0.0 lib/aitch/response_parser.rb