Module: Rackconnect::Model::ClassMethods

Defined in:
lib/rackconnect/lib/model.rb

Instance Method Summary collapse

Instance Method Details

#all(*args) ⇒ Object



37
38
39
40
41
# File 'lib/rackconnect/lib/model.rb', line 37

def all(*args)
  apply(args)
  resp = Rackconnect::Request.get(@_endpoint)
  resp.body.map{ |obj| self.new(json: obj) }
end

#attributes(*args) ⇒ Object



33
34
35
# File 'lib/rackconnect/lib/model.rb', line 33

def attributes(*args)
  attr_accessor *args
end

#create(options = {}) ⇒ Object



49
50
51
52
# File 'lib/rackconnect/lib/model.rb', line 49

def create(options={})
  resp = Rackconnect::Request.post(@_endpoint, body: options.to_json)
  self.new(json: resp.body)
end

#endpoint(str = nil, options = {}, &block) ⇒ Object



24
25
26
# File 'lib/rackconnect/lib/model.rb', line 24

def endpoint(str=nil, options={}, &block)
  @_endpoint = block_given? ? yield(block) : str
end

#endpoint_vars(*args) ⇒ Object



28
29
30
31
# File 'lib/rackconnect/lib/model.rb', line 28

def endpoint_vars(*args)
  # Inject into class level of descendant class
  self.class.module_eval{ attr_accessor *args }
end

#find(*args) ⇒ Object



43
44
45
46
47
# File 'lib/rackconnect/lib/model.rb', line 43

def find(*args)
  id = apply(args)
  resp = Rackconnect::Request.get("#{@_endpoint}/#{id}")
  self.new(json: resp.body)
end