Module: ActsAsParanoid::ClassMethods
- Defined in:
- lib/rails4_acts_as_paranoid.rb
Class Method Summary collapse
Instance Method Summary collapse
- #after_recover(method) ⇒ Object
- #before_recover(method) ⇒ Object
- #delete(id_or_array) ⇒ Object
- #delete!(id_or_array) ⇒ Object
- #delete_all(conditions = nil) ⇒ Object
- #delete_all!(conditions = nil) ⇒ Object
- #delete_now_value(column = nil) ⇒ Object
- #deletion_conditions(id_or_array) ⇒ Object
- #dependent_associations ⇒ Object
- #only_deleted ⇒ Object
- #paranoid_column ⇒ Object
- #paranoid_column_type ⇒ Object
- #with_deleted ⇒ Object
Class Method Details
.extended(base) ⇒ Object
175 176 177 178 |
# File 'lib/rails4_acts_as_paranoid.rb', line 175 def self.extended(base) base.define_callbacks :recover base.skip_time_zone_conversion_for_attributes = [base.paranoid_column, :created_at, :updated_at] end |
Instance Method Details
#after_recover(method) ⇒ Object
184 185 186 |
# File 'lib/rails4_acts_as_paranoid.rb', line 184 def after_recover(method) set_callback :recover, :after, method end |
#before_recover(method) ⇒ Object
180 181 182 |
# File 'lib/rails4_acts_as_paranoid.rb', line 180 def before_recover(method) set_callback :recover, :before, method end |
#delete(id_or_array) ⇒ Object
204 205 206 |
# File 'lib/rails4_acts_as_paranoid.rb', line 204 def delete(id_or_array) delete_all(deletion_conditions(id_or_array)) end |
#delete!(id_or_array) ⇒ Object
200 201 202 |
# File 'lib/rails4_acts_as_paranoid.rb', line 200 def delete!(id_or_array) delete_all!(deletion_conditions(id_or_array)) end |
#delete_all(conditions = nil) ⇒ Object
212 213 214 215 216 217 218 219 220 221 |
# File 'lib/rails4_acts_as_paranoid.rb', line 212 def delete_all(conditions = nil) columns = secondary_paranoid_columns.push(primary_paranoid_column) sql = columns.map do |column| "#{column[:column]} = ?" end.join(", ") values = columns.map{ |column| delete_now_value(column) } where(conditions).update_all [sql, *values] end |
#delete_all!(conditions = nil) ⇒ Object
208 209 210 |
# File 'lib/rails4_acts_as_paranoid.rb', line 208 def delete_all!(conditions = nil) self.unscoped.delete_all!(conditions) end |
#delete_now_value(column = nil) ⇒ Object
235 236 237 238 239 240 241 242 |
# File 'lib/rails4_acts_as_paranoid.rb', line 235 def delete_now_value(column=nil) column ||= primary_paranoid_column case column[:column_type] when "time" then Time.now.utc when "boolean" then true when "string" then column[:deleted_value] end end |
#deletion_conditions(id_or_array) ⇒ Object
196 197 198 |
# File 'lib/rails4_acts_as_paranoid.rb', line 196 def deletion_conditions(id_or_array) ["id in (?)", [id_or_array].flatten] end |
#dependent_associations ⇒ Object
231 232 233 |
# File 'lib/rails4_acts_as_paranoid.rb', line 231 def dependent_associations self.reflect_on_all_associations.select {|a| [:destroy, :delete_all].include?(a.[:dependent]) } end |
#only_deleted ⇒ Object
192 193 194 |
# File 'lib/rails4_acts_as_paranoid.rb', line 192 def only_deleted self.unscoped.where(*is_paranoid_deleted) end |
#paranoid_column ⇒ Object
223 224 225 |
# File 'lib/rails4_acts_as_paranoid.rb', line 223 def paranoid_column primary_paranoid_column[:column].to_sym end |
#paranoid_column_type ⇒ Object
227 228 229 |
# File 'lib/rails4_acts_as_paranoid.rb', line 227 def paranoid_column_type primary_paranoid_column[:column_type].to_sym end |
#with_deleted ⇒ Object
188 189 190 |
# File 'lib/rails4_acts_as_paranoid.rb', line 188 def with_deleted self.unscoped end |