Class: DataMapper::Types::ParanoidDateTime

Inherits:
Object
  • Object
show all
Defined in:
lib/gems/dm-core-0.9.9/lib/dm-core/types/paranoid_datetime.rb

Class Method Summary collapse

Class Method Details

.bind(property) ⇒ Object



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

def self.bind(property)
  model = property.model
  repository = property.repository

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

  model.class_eval <<-EOS, __FILE__, __LINE__

    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
  EOS

  model.default_scope(repository.name).update(property.name => nil)
end