lib/munson.rb in munson-0.1.0 vs lib/munson.rb in munson-0.2.0

- old
+ new

@@ -1,11 +1,7 @@ require 'json' - -require 'active_support/concern' -require "active_support/inflector" -require "active_support/core_ext/hash" - +require 'cgi' require 'faraday' require 'faraday_middleware' require "munson/version" @@ -20,10 +16,12 @@ require 'munson/agent' require 'munson/resource' module Munson @registered_types = {} + @registered_paginators = {} + class << self # Configure the default connection. # # @param [Hash] opts {Munson::Connection} configuration options # @param [Proc] block to yield to Faraday::Connection @@ -46,21 +44,29 @@ # This is used in Faraday response middleware to package the JSON into a domain model # # @example Mapping a type # Munson.register_type("addresses", Address) # - # @param [#to_s] type JSON Spec type + # @param [#to_sym] type JSON Spec type # @param [Class] klass to map to def register_type(type, klass) - @registered_types[type] = klass + @registered_types[type.to_sym] = klass end + def register_paginator(name, klass) + @registered_paginators[name.to_sym] = klass + end + + def lookup_paginator(name) + @registered_paginators[name.to_sym] + end + # Lookup a class by JSON Spec type name # - # @param [#to_s] type JSON Spec type + # @param [#to_sym] type JSON Spec type # @return [Class] domain model def lookup_type(type) - @registered_types[type] + @registered_types[type.to_sym] end # @private def flush_types! @registered_types = {}