Module: Tenacity::OrmExt::DataMapper::ClassMethods

Includes:
Helpers
Defined in:
lib/tenacity/orm_ext/datamapper.rb

Overview

:nodoc:

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



112
113
114
115
116
117
118
119
# File 'lib/tenacity/orm_ext/datamapper.rb', line 112

def _t_delete(ids, run_callbacks=true)
  objects = _t_find_bulk(ids)
  if run_callbacks
    objects.each { |object| object.destroy }
  else
    objects.each { |object| object.destroy! }
  end
end

#_t_find(id) ⇒ Object



59
60
61
# File 'lib/tenacity/orm_ext/datamapper.rb', line 59

def _t_find(id)
  get(_t_serialize(id))
end

#_t_find_all_by_associate(property, id) ⇒ Object



72
73
74
# File 'lib/tenacity/orm_ext/datamapper.rb', line 72

def _t_find_all_by_associate(property, id)
  all(property => _t_serialize(id))
end

#_t_find_all_ids_by_associate(property, id) ⇒ Object



76
77
78
# File 'lib/tenacity/orm_ext/datamapper.rb', line 76

def _t_find_all_ids_by_associate(property, id)
  repository.adapter.select("SELECT id from #{storage_names[:default]} WHERE #{property} = #{_t_serialize_id_for_sql(id)}")
end

#_t_find_bulk(ids) ⇒ Object



63
64
65
66
# File 'lib/tenacity/orm_ext/datamapper.rb', line 63

def _t_find_bulk(ids)
  return [] if ids.nil? || ids == []
  all(:id => _t_serialize_ids(ids))
end

#_t_find_first_by_associate(property, id) ⇒ Object



68
69
70
# File 'lib/tenacity/orm_ext/datamapper.rb', line 68

def _t_find_first_by_associate(property, id)
  first(property => _t_serialize(id))
end

#_t_id_typeObject



51
52
53
54
55
56
57
# File 'lib/tenacity/orm_ext/datamapper.rb', line 51

def _t_id_type
  @_t_id_type_clazz ||= begin
                          properties.find{ |x| x.key? }.primitive
                        rescue
                          Integer
                        end
end

#_t_initialize_belongs_to_association(association) ⇒ Object



106
107
108
109
110
# File 'lib/tenacity/orm_ext/datamapper.rb', line 106

def _t_initialize_belongs_to_association(association)
  after :destroy do |record|
    record._t_cleanup_belongs_to_association(association)
  end
end

#_t_initialize_has_many_association(association) ⇒ Object



96
97
98
99
100
101
102
103
104
# File 'lib/tenacity/orm_ext/datamapper.rb', line 96

def _t_initialize_has_many_association(association)
  after :save do |record|
    record.class._t_save_associates(record, association)
  end

  before :destroy do |record|
    record._t_cleanup_has_many_association(association)
  end
end

#_t_initialize_has_one_association(association) ⇒ Object



90
91
92
93
94
# File 'lib/tenacity/orm_ext/datamapper.rb', line 90

def _t_initialize_has_one_association(association)
  before :destroy do |record|
    record._t_cleanup_has_one_association(association)
  end
end

#_t_initialize_tenacityObject



80
81
82
83
84
85
86
87
88
# File 'lib/tenacity/orm_ext/datamapper.rb', line 80

def _t_initialize_tenacity
  before :save do |record|
    record._t_verify_associates_exist
  end

  after :save do |record|
    record._t_save_autosave_associations
  end
end