Class: Couchbase::Model::OrmAdapter
- Inherits:
-
OrmAdapter::Base
- Object
- OrmAdapter::Base
- Couchbase::Model::OrmAdapter
show all
- Defined in:
- lib/orm_adapter-couchbase/couchbase.rb
Defined Under Namespace
Classes: MissingViewException
Instance Method Summary
collapse
Instance Method Details
#create!(attrs) ⇒ Object
19
20
21
22
|
# File 'lib/orm_adapter-couchbase/couchbase.rb', line 19
def create! attrs
klass.create! attrs
end
|
#destroy(model) ⇒ Object
24
25
26
27
28
29
30
31
|
# File 'lib/orm_adapter-couchbase/couchbase.rb', line 24
def destroy model
return nil unless model.is_a? klass
id = model.id
model.delete
model.id = id
end
|
#find_all(options = {}) ⇒ Object
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
|
# File 'lib/orm_adapter-couchbase/couchbase.rb', line 41
def find_all options = {}
view_name, view_options, options = view_for_options(options)
conditions, order, limit, offset = (options)
stream = klass.send(view_name, view_options)
stream = apply_conditions(stream, conditions)
stream = apply_order(stream, order)
stream = stream.drop(offset) if offset
stream = stream.take(limit) if limit
stream.to_a end
|
#find_first(options = {}) ⇒ Object
58
59
60
61
62
63
64
65
66
67
|
# File 'lib/orm_adapter-couchbase/couchbase.rb', line 58
def find_first options = {}
id = options.delete(:id)
conditions, _ = (options.dup)
if id
apply_conditions([get(id)], conditions).first
else
find_all(options).first
end
end
|
#get(id) ⇒ Object
37
38
39
|
# File 'lib/orm_adapter-couchbase/couchbase.rb', line 37
def get id
klass.find_by_id wrap_key(id)
end
|
#get!(id) ⇒ Object
33
34
35
|
# File 'lib/orm_adapter-couchbase/couchbase.rb', line 33
def get! id
klass.find wrap_key(id)
end
|