module Formstack::Model::ClassMethods
Public Instance Methods
all(*args)
click to toggle source
# File lib/formstack/model.rb, line 43 def all(*args) new_from_response client.public_send("#{client_method}s", *args), context: args end
client()
click to toggle source
# File lib/formstack/model.rb, line 68 def client Formstack.client end
client_method()
click to toggle source
# File lib/formstack/model.rb, line 72 def client_method raise NotImplementedError end
create(*args)
click to toggle source
# File lib/formstack/model.rb, line 51 def create(*args) new_from_response(client.public_send("create_#{client_method}", *args)).tap do |obj| obj.load if obj[:id] end end
find(*args)
click to toggle source
# File lib/formstack/model.rb, line 47 def find(*args) new_from_response client.public_send(client_method, *args) end
new_from_response(response, context: [])
click to toggle source
# File lib/formstack/model.rb, line 57 def new_from_response(response, context: []) if response.respond_to?(:has_key?) && response.has_key?(response_nesting) response = response[response_nesting] end if response.is_a?(Array) Collection.new(response.map { |item| new item }, klass: self, context: context) else new response end end
response_nesting()
click to toggle source
# File lib/formstack/model.rb, line 76 def response_nesting "" end