Module: Zendesk2::Attributes
- Included in:
- AuditEvent, Brand, Forum, Group, HelpCenter::AccessPolicy, HelpCenter::Article, HelpCenter::Category, HelpCenter::Post, HelpCenter::Section, HelpCenter::Subscription, HelpCenter::Topic, HelpCenter::Translation, Membership, Memberships, Organizations, Ticket, TicketAudit, TicketField, TicketForm, TicketMetric, Tickets, Topic, TopicComment, User, UserField, UserIdentity, View, Views
- Defined in:
- lib/zendesk2/attributes.rb
Instance Method Summary collapse
- #assoc_accessor(name, options = {}) ⇒ Object
- #assoc_reader(name, options = {}) ⇒ Object
- #assoc_writer(name, options = {}) ⇒ Object
Instance Method Details
#assoc_accessor(name, options = {}) ⇒ Object
27 28 29 30 |
# File 'lib/zendesk2/attributes.rb', line 27 def assoc_accessor(name, = {}) assoc_reader(name, ) assoc_writer(name, ) end |
#assoc_reader(name, options = {}) ⇒ Object
3 4 5 6 7 8 9 10 11 12 13 14 |
# File 'lib/zendesk2/attributes.rb', line 3 def assoc_reader(name, = {}) assoc_key = [:key] || "#{name}_id" collection = [:collection] || "#{name}s" define_method(name) do assoc_id = send(assoc_key) if assoc_id cistern.send(collection).get(assoc_id) else instance_variable_get("@#{name}") end end end |
#assoc_writer(name, options = {}) ⇒ Object
16 17 18 19 20 21 22 23 24 25 |
# File 'lib/zendesk2/attributes.rb', line 16 def assoc_writer(name, = {}) assoc_key = [:key] || "#{name}_id" define_method("#{name}=") do |assoc| if assoc.is_a?(Cistern::Model) send("#{assoc_key}=", assoc.identity) else instance_variable_set("@#{name}", assoc) end end end |