Module: Tenacity::OrmExt::Toystore::ClassMethods
- Includes:
- Helpers
- Defined in:
- lib/tenacity/orm_ext/toystore.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
97
98
99
100
101
102
103
|
# File 'lib/tenacity/orm_ext/toystore.rb', line 97
def _t_delete(ids, run_callbacks=true)
if run_callbacks
destroy(*ids)
else
delete(*ids)
end
end
|
#_t_find(id) ⇒ Object
56
57
58
|
# File 'lib/tenacity/orm_ext/toystore.rb', line 56
def _t_find(id)
(id.nil? || id.to_s.strip == "") ? nil : get(_t_serialize(id))
end
|
#_t_find_all_by_associate(property, id) ⇒ Object
68
69
70
|
# File 'lib/tenacity/orm_ext/toystore.rb', line 68
def _t_find_all_by_associate(property, id)
get_multi(_t_find_all_ids_by_associate(property, id))
end
|
#_t_find_all_ids_by_associate(property, id) ⇒ Object
72
73
74
|
# File 'lib/tenacity/orm_ext/toystore.rb', line 72
def _t_find_all_ids_by_associate(property, id)
get_index(property.to_sym, id)
end
|
#_t_find_bulk(ids) ⇒ Object
60
61
62
|
# File 'lib/tenacity/orm_ext/toystore.rb', line 60
def _t_find_bulk(ids)
get_multi(_t_serialize_ids(ids)).compact
end
|
#_t_find_first_by_associate(property, id) ⇒ Object
64
65
66
|
# File 'lib/tenacity/orm_ext/toystore.rb', line 64
def _t_find_first_by_associate(property, id)
send("first_by_#{property}", id)
end
|
#_t_id_type ⇒ Object
52
53
54
|
# File 'lib/tenacity/orm_ext/toystore.rb', line 52
def _t_id_type
String
end
|
#_t_initialize_belongs_to_association(association) ⇒ Object
90
91
92
93
94
95
|
# File 'lib/tenacity/orm_ext/toystore.rb', line 90
def _t_initialize_belongs_to_association(association)
attribute association.foreign_key, id_class_for(association)
attribute association.polymorphic_type, String if association.polymorphic?
index(association.foreign_key.to_sym)
after_destroy { |record| record._t_cleanup_belongs_to_association(association) }
end
|
#_t_initialize_has_many_association(association) ⇒ Object
85
86
87
88
|
# File 'lib/tenacity/orm_ext/toystore.rb', line 85
def _t_initialize_has_many_association(association)
after_save { |record| self.class._t_save_associates(record, association) }
before_destroy { |record| record._t_cleanup_has_many_association(association) }
end
|
#_t_initialize_has_one_association(association) ⇒ Object
81
82
83
|
# File 'lib/tenacity/orm_ext/toystore.rb', line 81
def _t_initialize_has_one_association(association)
before_destroy { |record| record._t_cleanup_has_one_association(association) }
end
|
#_t_initialize_tenacity ⇒ Object
76
77
78
79
|
# File 'lib/tenacity/orm_ext/toystore.rb', line 76
def _t_initialize_tenacity
before_save { |record| record._t_verify_associates_exist }
after_save { |record| record._t_save_autosave_associations }
end
|