Sha256: cf7ea9df9d182f042d4589ab8a2f3ef64262796bc9fa6b802cb4ba27b47b9191

Contents?: true

Size: 673 Bytes

Versions: 4

Compression:

Stored size: 673 Bytes

Contents

module SkipEmbedded
  module LogicalDestroyable
    def self.included(base)
      base.named_scope(:active, {:conditions => {:deleted_at => nil}})
      base.attr_protected :deleted_at, :deleted
    end

    def deleted
      !!self.deleted_at
    end
    alias deleted? deleted

    def deleted=(is_deleted)
      self.deleted_at = is_deleted ? Time.now : nil
    end

    def logical_destroy
      before_logical_destroy
      result = update_attribute(:deleted_at, Time.now)
      after_logical_destroy
      result
    end

    def before_logical_destroy;end
    def after_logical_destroy;end

    def recover
      update_attribute(:deleted_at, nil)
    end
  end
end

Version data entries

4 entries across 4 versions & 1 rubygems

Version Path
openskip-skip_embedded-0.9.16 lib/skip_embedded/logical_destroyable.rb
openskip-skip_embedded-0.9.17 lib/skip_embedded/logical_destroyable.rb
openskip-skip_embedded-0.9.18 lib/skip_embedded/logical_destroyable.rb
openskip-skip_embedded-0.9.19 lib/skip_embedded/logical_destroyable.rb