Sha256: 625be4b8d18c29d59247dca8b61b52276e758daa85ef2d1c55b5207fbf4f8271

Contents?: true

Size: 767 Bytes

Versions: 14

Compression:

Stored size: 767 Bytes

Contents

module Centaman
  #:nodoc:
  module JsonWrapper
    def objects
      @all ||= build_objects(self.fetch_all)
    end

    # i.e. from GET of an index
    def build_objects(resp)
      return [] unless resp.respond_to?(:map)
      @tickets = resp.map do |ticket_hash|
        object_class.new(ticket_hash.merge(additional_hash_to_serialize_after_response))
      end
    end

    # i.e. from GET of a show or POST
    def build_object(resp)
      return resp unless resp.respond_to?(:merge)
      @build_object ||= object_class.new(resp.merge(additional_hash_to_serialize_after_response))
    end

    def additional_hash_to_serialize_after_response
      {}
    end

    def object_class
      raise "object_class is required for #{self.class.name}"
    end
  end
end

Version data entries

14 entries across 14 versions & 1 rubygems

Version Path
centaman-0.1.13 lib/centaman/json_wrapper.rb
centaman-0.1.12 lib/centaman/json_wrapper.rb
centaman-0.1.11 lib/centaman/json_wrapper.rb
centaman-0.1.10 lib/centaman/json_wrapper.rb
centaman-0.1.9 lib/centaman/json_wrapper.rb
centaman-0.1.8 lib/centaman/json_wrapper.rb
centaman-0.1.7 lib/centaman/json_wrapper.rb
centaman-0.1.6 lib/centaman/json_wrapper.rb
centaman-0.1.5 lib/centaman/json_wrapper.rb
centaman-0.1.4 lib/centaman/json_wrapper.rb
centaman-0.1.3 lib/centaman/json_wrapper.rb
centaman-0.1.2 lib/centaman/json_wrapper.rb
centaman-0.1.1 lib/centaman/json_wrapper.rb
centaman-0.1.0 lib/centaman/json_wrapper.rb