Class: CouchRest::Model::Base::OrmAdapter

Inherits:
OrmAdapter::Base
  • Object
show all
Defined in:
lib/orm_adapter_couchrest_model/couchrest_model.rb

Instance Method Summary collapse

Instance Method Details

#column_namesObject



9
10
11
# File 'lib/orm_adapter_couchrest_model/couchrest_model.rb', line 9

def column_names
  klass.properties
end

#create!(attributes = {}) ⇒ Object



45
46
47
# File 'lib/orm_adapter_couchrest_model/couchrest_model.rb', line 45

def create!(attributes = {})
  klass.create!(attributes)
end

#destroy(object) ⇒ Object



49
50
51
# File 'lib/orm_adapter_couchrest_model/couchrest_model.rb', line 49

def destroy(object)
  object.destroy if valid_object?(object)
end

#find_all(options = {}) ⇒ Object



33
34
35
36
37
38
39
40
41
42
43
# File 'lib/orm_adapter_couchrest_model/couchrest_model.rb', line 33

def find_all(options = {})
  conditions, order, limit, offset = extract_conditions!(options)
  if conditions.empty?
    klass.all(:limit => limit, :skip => offset).all
  elsif conditions.keys.first == :id
    klass.get(conditions.values.first)
  else
    view = klass.send("by_#{conditions.keys.first}")
    view.key(conditions.values.first).limit(limit).skip(offset).all
  end
end

#find_first(options = {}) ⇒ Object



21
22
23
24
25
26
27
28
29
30
31
# File 'lib/orm_adapter_couchrest_model/couchrest_model.rb', line 21

def find_first(options = {})
  conditions, order, limit, offset = extract_conditions!(options)
  if conditions.empty?
    klass.first
  elsif conditions.keys.first == :id
    klass.get(conditions.values.first)
  else
    view = klass.send("by_#{conditions.keys.first}")
    view.key(conditions.values.first).limit(1).first
  end
end

#get(id) ⇒ Object



17
18
19
# File 'lib/orm_adapter_couchrest_model/couchrest_model.rb', line 17

def get(id)
  klass.get(wrap_key(id))
end

#get!(id) ⇒ Object



13
14
15
# File 'lib/orm_adapter_couchrest_model/couchrest_model.rb', line 13

def get!(id)
  klass.get!(wrap_key(id))
end