Module: Formstack::Model

Included in:
ConfirmationEmail, Field, Form, NotificationEmail, Submission, Webhook
Defined in:
lib/formstack/model.rb

Defined Under Namespace

Modules: ClassMethods

Class Method Summary collapse

Instance Method Summary collapse

Class Method Details

.included(base) ⇒ Object



7
8
9
10
11
12
# 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

Instance Method Details

#[](key) ⇒ Object



18
19
20
# File 'lib/formstack/model.rb', line 18

def [](key)
  attributes[key.to_s]
end

#deleteObject



31
32
33
# File 'lib/formstack/model.rb', line 31

def delete
  client.public_send("delete_#{client_method}", self[:id])
end

#initialize(attributes = {}) ⇒ Object



14
15
16
# File 'lib/formstack/model.rb', line 14

def initialize(attributes={})
  @attributes = attributes
end

#loadObject



22
23
24
# File 'lib/formstack/model.rb', line 22

def load
  @attributes = client.public_send(client_method, self[:id])
end

#update(new_attributes = {}) ⇒ Object



26
27
28
29
# 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