Class: DataMapper::Types::ParanoidDateTime

Inherits:
DataMapper::Type show all
Defined in:
lib/dm-core/types/paranoid_datetime.rb

Constant Summary

Constants inherited from DataMapper::Type

DataMapper::Type::PROPERTY_OPTIONS

Class Method Summary collapse

Methods inherited from DataMapper::Type

configure, dump, inherited, load, options, primitive

Class Method Details

.bind(property) ⇒ Object

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

TODO: document



9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
# File 'lib/dm-core/types/paranoid_datetime.rb', line 9

def self.bind(property)
  repository_name = property.repository_name
  model           = property.model
  property_name   = property.name

  model.send(:set_paranoid_property, property_name){DateTime.now}

  model.class_eval <<-RUBY, __FILE__, __LINE__ + 1
    def self.with_deleted
      with_exclusive_scope(#{property_name.inspect}.not => nil) do
        yield
      end
    end

    def destroy
      self.class.paranoid_properties.each do |name, blk|
        attribute_set(name, blk.call(self))
      end
      save
    end
  RUBY

  model.default_scope(repository_name).update(property_name => nil)
end