Module: Centaman::JsonWrapper

Overview

:nodoc:

Instance Method Summary collapse

Instance Method Details

#additional_hash_to_serialize_after_responseObject



22
23
24
# File 'lib/centaman/json_wrapper.rb', line 22

def additional_hash_to_serialize_after_response
  {}
end

#build_object(resp) ⇒ Object

i.e. from GET of a show or POST



17
18
19
20
# File 'lib/centaman/json_wrapper.rb', line 17

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

#build_objects(resp) ⇒ Object

i.e. from GET of an index



9
10
11
12
13
14
# File 'lib/centaman/json_wrapper.rb', line 9

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

#final_object_classObject



30
31
32
33
34
35
# File 'lib/centaman/json_wrapper.rb', line 30

def final_object_class
  name = object_class.name.split('::').last
  override = Centaman.configuration.object_overrides[name]
  override_class = override.constantize if override
  override_class || object_class
end

#object_classObject



26
27
28
# File 'lib/centaman/json_wrapper.rb', line 26

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

#objectsObject



4
5
6
# File 'lib/centaman/json_wrapper.rb', line 4

def objects
  @all ||= build_objects(self.fetch_all)
end