Module: Ohm::SoftDelete

Defined in:
lib/ohm/contrib/soft_delete.rb

Overview

Provides support for soft deletion

Examples:


class Post < Ohm::Model
  include Ohm::SoftDelete

  attribute :title
  index :title
end

post = Post.create(:title => 'Title')

post.deleted?
# => false

post.delete

post.deleted?
# => true

Post.all.empty?
# => true

Post.find(:title => 'Title').empty?
# => true

Post.exists?(post.id)
# => true

post = Post[post.id]

post.deleted?
# => true

Defined Under Namespace

Modules: ClassMethods

Constant Summary collapse

IS_DELETED =
"1"

Class Method Summary collapse

Instance Method Summary collapse

Class Method Details

.included(base) ⇒ Object



39
40
41
42
43
# File 'lib/ohm/contrib/soft_delete.rb', line 39

def self.included(base)
  base.attribute :deleted
  base.index :deleted
  base.extend ClassMethods
end

Instance Method Details

#deleteObject



45
46
47
# File 'lib/ohm/contrib/soft_delete.rb', line 45

def delete
  update(:deleted => IS_DELETED)
end

#deleted?Boolean

Returns:

  • (Boolean)


49
50
51
# File 'lib/ohm/contrib/soft_delete.rb', line 49

def deleted?
  deleted == IS_DELETED
end