Sha256: 79641c482511a3d4d4c686e839be9c73ba1266f7df34b321d8e2d4573280f65d
Contents?: true
Size: 1018 Bytes
Versions: 17
Compression:
Stored size: 1018 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| final_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 ||= final_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 def final_object_class name = self.class.name.split('::').last override = Centaman.configuration.object_overrides[name] override_class = override.constantize if override override_class || object_class end end end
Version data entries
17 entries across 17 versions & 1 rubygems