module Formstack::Model
Public Class Methods
included(base)
click to toggle source
# File lib/formstack/model.rb, line 7 def self.included(base) base.send :attr_reader, :attributes base.extend ClassMethods base.extend Forwardable base.def_delegators :'self.class', :client, :client_method, :new_from_response end
new(attributes={})
click to toggle source
# File lib/formstack/model.rb, line 14 def initialize(attributes={}) @attributes = attributes end
Public Instance Methods
[](key)
click to toggle source
# File lib/formstack/model.rb, line 18 def [](key) attributes[key.to_s] end
delete()
click to toggle source
# File lib/formstack/model.rb, line 31 def delete client.public_send("delete_#{client_method}", self[:id]) end
load()
click to toggle source
# File lib/formstack/model.rb, line 22 def load @attributes = client.public_send(client_method, self[:id]) end
update(new_attributes={})
click to toggle source
# File lib/formstack/model.rb, line 26 def update(new_attributes={}) attributes.merge!(stringify_hash_keys(new_attributes)) client.public_send("update_#{client_method}", self[:id], attributes) end
Private Instance Methods
stringify_hash_keys(hash)
click to toggle source
# File lib/formstack/model.rb, line 37 def stringify_hash_keys(hash) hash.each_with_object({}) { |(k, v), h| h[k.to_s] = v } end