class Pocus::Association
Attributes
klass[R]
owner[R]
path[R]
Public Class Methods
new(owner, name, options)
click to toggle source
# File lib/pocus/association.rb, line 5 def initialize(owner, name, options) @owner = owner @path = options[:path] || "/#{name}" @klass = Object.const_get('Pocus::'.concat(options[:class] || camelize(name))) end
Public Instance Methods
all()
click to toggle source
# File lib/pocus/association.rb, line 11 def all @all ||= owner.get_multiple(path, klass) end
create(fields_multiple)
click to toggle source
# File lib/pocus/association.rb, line 15 def create(fields_multiple) if fields_multiple.is_a?(Array) owner.post_multiple(path, klass, fields_multiple) else response = owner.post_multiple(path, klass, [fields_multiple]) return response if response.empty? resource = response.first resource.assign_attributes(errors: response.errors || [], warnings: response.warnings || []) resource end end
find(id)
click to toggle source
# File lib/pocus/association.rb, line 27 def find(id) owner.get("#{path}/#{id}", klass) end
find_or_create_by(attributes)
click to toggle source
# File lib/pocus/association.rb, line 31 def find_or_create_by(attributes) where(attributes).first || create(attributes) end
where(filters)
click to toggle source
# File lib/pocus/association.rb, line 35 def where(filters) owner.get_multiple(path, klass, filters) end