Sha256: 6cf44e722101a0e580c2b179d109bc24cf75248b58a36b58544dceb31a765247

Contents?: true

Size: 796 Bytes

Versions: 22

Compression:

Stored size: 796 Bytes

Contents

module Zendesk2::Attributes
  def assoc_reader(name, options={})
    assoc_key  = options[:key] || "#{name}_id"
    collection = options[:collection] || "#{name}s"
    define_method(name) do
      if assoc_id = self.send(assoc_key)
        self.service.send(collection).get(assoc_id)
      else self.instance_variable_get("@#{name}")
      end
    end
  end

  def assoc_writer(name, options={})
    assoc_key = options[:key] || "#{name}_id"
    define_method("#{name}=") do |assoc|
      if assoc.is_a?(Cistern::Model)
        self.send("#{assoc_key}=", assoc.identity)
      else
        self.instance_variable_set("@#{name}", assoc)
      end
    end
  end

  def assoc_accessor(name, options={})
    assoc_reader(name, options)
    assoc_writer(name, options)
  end

  # TODO: collection
end

Version data entries

22 entries across 22 versions & 1 rubygems

Version Path
zendesk2-1.8.1 lib/zendesk2/attributes.rb
zendesk2-1.7.5 lib/zendesk2/attributes.rb
zendesk2-1.7.4 lib/zendesk2/attributes.rb
zendesk2-1.7.2 lib/zendesk2/attributes.rb
zendesk2-1.7.1 lib/zendesk2/attributes.rb
zendesk2-1.7.0 lib/zendesk2/attributes.rb
zendesk2-1.6.1 lib/zendesk2/attributes.rb
zendesk2-1.5.17 lib/zendesk2/attributes.rb
zendesk2-1.5.16 lib/zendesk2/attributes.rb
zendesk2-1.5.15 lib/zendesk2/attributes.rb
zendesk2-1.5.14 lib/zendesk2/attributes.rb
zendesk2-1.5.13 lib/zendesk2/attributes.rb
zendesk2-1.5.12 lib/zendesk2/attributes.rb
zendesk2-1.5.11 lib/zendesk2/attributes.rb
zendesk2-1.5.10 lib/zendesk2/attributes.rb
zendesk2-1.5.9 lib/zendesk2/attributes.rb
zendesk2-1.5.8 lib/zendesk2/attributes.rb
zendesk2-1.5.7 lib/zendesk2/attributes.rb
zendesk2-1.5.6 lib/zendesk2/attributes.rb
zendesk2-1.5.5 lib/zendesk2/attributes.rb