Module: Tenacity::OrmExt::CouchRest::ClassMethods
- Includes:
- Helpers
- Defined in:
- lib/tenacity/orm_ext/couchrest.rb
Overview
Instance Method Summary
collapse
Methods included from Helpers
#_t_serialize_id_for_sql, #_t_serialize_ids, #id_class_for
Instance Method Details
#_t_delete(ids, run_callbacks = true) ⇒ Object
128
129
130
131
132
133
134
135
|
# File 'lib/tenacity/orm_ext/couchrest.rb', line 128
def _t_delete(ids, run_callbacks=true)
docs = _t_find_bulk(ids)
if run_callbacks
docs.each { |doc| doc.destroy }
else
docs.each { |doc| database.delete_doc(doc) }
end
end
|
#_t_find(id) ⇒ Object
75
76
77
|
# File 'lib/tenacity/orm_ext/couchrest.rb', line 75
def _t_find(id)
(id.nil? || id.strip == "") ? nil : get(_t_serialize(id))
end
|
#_t_find_all_by_associate(property, id) ⇒ Object
95
96
97
|
# File 'lib/tenacity/orm_ext/couchrest.rb', line 95
def _t_find_all_by_associate(property, id)
self.send("by_#{property}", :key => _t_serialize(id))
end
|
#_t_find_all_ids_by_associate(property, id) ⇒ Object
99
100
101
102
|
# File 'lib/tenacity/orm_ext/couchrest.rb', line 99
def _t_find_all_ids_by_associate(property, id)
results = self.send("by_#{property}", :key => _t_serialize(id), :include_docs => false)
results['rows'].map { |r| r['id'] }
end
|
#_t_find_bulk(ids) ⇒ Object
79
80
81
82
83
84
85
86
87
88
89
|
# File 'lib/tenacity/orm_ext/couchrest.rb', line 79
def _t_find_bulk(ids)
return [] if ids.nil? || ids.empty?
ids = [ids] unless ids.class == Array
docs = []
result = database.get_bulk(_t_serialize_ids(ids))
result['rows'].each do |row|
docs << (row['doc'].nil? ? nil : create_from_database(row['doc']))
end
docs.reject { |doc| doc.nil? }
end
|
#_t_find_first_by_associate(property, id) ⇒ Object
91
92
93
|
# File 'lib/tenacity/orm_ext/couchrest.rb', line 91
def _t_find_first_by_associate(property, id)
self.send("by_#{property}", :key => _t_serialize(id)).first
end
|
#_t_id_type ⇒ Object
71
72
73
|
# File 'lib/tenacity/orm_ext/couchrest.rb', line 71
def _t_id_type
String
end
|
#_t_initialize_belongs_to_association(association) ⇒ Object
118
119
120
121
122
123
124
125
126
|
# File 'lib/tenacity/orm_ext/couchrest.rb', line 118
def _t_initialize_belongs_to_association(association)
property_name = association.foreign_key
unless self.respond_to?(property_name)
property property_name, :type => id_class_for(association)
property association.polymorphic_type, :type => String if association.polymorphic?
view_by property_name
after_destroy { |record| record._t_cleanup_belongs_to_association(association) }
end
end
|
#_t_initialize_has_many_association(association) ⇒ Object
113
114
115
116
|
# File 'lib/tenacity/orm_ext/couchrest.rb', line 113
def _t_initialize_has_many_association(association)
after_save { |record| record.class._t_save_associates(record, association) }
before_destroy { |record| record._t_cleanup_has_many_association(association) }
end
|
#_t_initialize_has_one_association(association) ⇒ Object
109
110
111
|
# File 'lib/tenacity/orm_ext/couchrest.rb', line 109
def _t_initialize_has_one_association(association)
before_destroy { |record| record._t_cleanup_has_one_association(association) }
end
|
#_t_initialize_tenacity ⇒ Object
104
105
106
107
|
# File 'lib/tenacity/orm_ext/couchrest.rb', line 104
def _t_initialize_tenacity
before_save { |record| record._t_verify_associates_exist }
after_save { |record| record._t_save_autosave_associations }
end
|