module ZendeskAPI::Associations

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

@private

Public Class Methods

included(base) click to toggle source
# File lib/zendesk_api/associations.rb, line 12
def self.included(base)
  base.extend ClassMethods
end

Public Instance Methods

wrap_resource(resource, class_level_association, options = {}) click to toggle source
# 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, Integer
    klass.new(@client, (options[:include_key] || :id) => resource, :association => instance_association)
  else
    resource.association = instance_association
    resource
  end
end