Module: ZendeskAPI::Associations

Included in:
Data
Defined in:
lib/zendesk_api/associations.rb

Overview

This module holds association method for resources. Associations can be loaded in three ways:

  • Commonly used resources are automatically side-loaded server side and sent along with their parent object.

  • Associated resource ids are sent and are then loaded one-by-one into the parent collection.

  • The association is represented with Rails’ nested association urls (such as tickets/:id/groups) and are loaded that way.

Defined Under Namespace

Modules: ClassMethods

Class Method Summary collapse

Instance Method Summary collapse

Class Method Details

.included(base) ⇒ Object



12
13
14
# File 'lib/zendesk_api/associations.rb', line 12

def self.included(base)
  base.extend ClassMethods
end

Instance Method Details

#wrap_resource(resource, class_level_association, options = {}) ⇒ Object



16
17
18
19
20
21
22
23
24
25
26
27
28
29
# File 'lib/zendesk_api/associations.rb', line 16

def wrap_resource(resource, class_level_association, options = {})
  instance_association = Association.new(class_level_association.merge(:parent => self))
  klass = class_level_association[:class]

  case resource
  when Hash
    klass.new(@client, resource.merge(:association => instance_association))
  when String, Fixnum
    klass.new(@client, (options[:include_key] || :id) => resource, :association => instance_association)
  else
    resource.association = instance_association
    resource
  end
end