Module: Spyke::Orm::ClassMethods

Defined in:
lib/spyke/orm.rb

Instance Method Summary collapse

Instance Method Details

#create(attributes = {}) ⇒ Object



42
43
44
45
46
# File 'lib/spyke/orm.rb', line 42

def create(attributes = {})
  record = new(attributes)
  record.save
  record
end

#destroy(id = nil) ⇒ Object



48
49
50
# File 'lib/spyke/orm.rb', line 48

def destroy(id = nil)
  new(primary_key => id).destroy
end

#fetchObject



38
39
40
# File 'lib/spyke/orm.rb', line 38

def fetch
  scoped_request :get
end

#find(id = nil, &block) ⇒ Object



28
29
30
31
32
33
34
35
36
# File 'lib/spyke/orm.rb', line 28

def find(id = nil, &block)
  if block_given?
    all.find_some.find(&block)
  else
    raise ResourceNotFound if id.blank?

    where(primary_key => id).find_one || raise(ResourceNotFound)
  end
end

#include_root_in_json(value) ⇒ Object



19
20
21
# File 'lib/spyke/orm.rb', line 19

def include_root_in_json(value)
  self.include_root = value
end

#method_for(callback, value = nil) ⇒ Object



23
24
25
26
# File 'lib/spyke/orm.rb', line 23

def method_for(callback, value = nil)
  self.callback_methods = callback_methods.merge(callback => value) if value
  callback_methods[callback]
end