module CiscoSpark::Model
Public Class Methods
included(base)
click to toggle source
# File lib/cisco_spark/model.rb, line 7 def self.included(base) base.extend(ClassMethods) end
new(attributes={})
click to toggle source
# File lib/cisco_spark/model.rb, line 74 def initialize(attributes={}) assign_attributes(attributes) end
Public Instance Methods
destroy()
click to toggle source
# File lib/cisco_spark/model.rb, line 87 def destroy self.class.destroy(id) end
fetch()
click to toggle source
# File lib/cisco_spark/model.rb, line 78 def fetch merge_attributes(self.class.fetch(id)) self end
persist()
click to toggle source
# File lib/cisco_spark/model.rb, line 83 def persist id ? update : create end
to_h()
click to toggle source
# File lib/cisco_spark/model.rb, line 91 def to_h self.class.attributes.keys.each_with_object({}) { |name, hash| hash[name] = send(name) } end
Private Instance Methods
assign_attributes(attributes)
click to toggle source
# File lib/cisco_spark/model.rb, line 115 def assign_attributes(attributes) attributes.each do |name, value| send("#{name}=", value) end end
create()
click to toggle source
# File lib/cisco_spark/model.rb, line 99 def create merge_attributes(self.class.create(to_h)) self end
merge_attributes(object)
click to toggle source
# File lib/cisco_spark/model.rb, line 111 def merge_attributes(object) assign_attributes(object.to_h) end
update()
click to toggle source
# File lib/cisco_spark/model.rb, line 104 def update attrs = to_h id = attrs.delete(:id) merge_attributes(self.class.update(id, attrs)) self end