Module: ActiveArchive::Base

Defined in:
lib/active_archive/base.rb

Class Method Summary collapse

Instance Method Summary collapse

Class Method Details

.included(base) ⇒ Object



4
5
6
7
8
9
10
11
12
13
# File 'lib/active_archive/base.rb', line 4

def self.included(base)
  base.extend Methods
  base.extend Scopes

  base.instance_eval do
    define_model_callbacks :unarchive

    before_unarchive :unarchive_destroyed_dependent_records
  end
end

Instance Method Details

#archivable?Boolean

Returns:

  • (Boolean)


19
20
21
# File 'lib/active_archive/base.rb', line 19

def archivable?
  respond_to?(:archived_at)
end

#archived?Boolean

Returns:

  • (Boolean)


15
16
17
# File 'lib/active_archive/base.rb', line 15

def archived?
  archivable? ? !!archived_at : destroyed?
end

#destroy(force = nil) ⇒ Object Also known as: archive



23
24
25
26
27
28
29
30
31
# File 'lib/active_archive/base.rb', line 23

def destroy(force=nil)
  with_transaction_returning_status do
    if unarchivable? || should_force_destroy?(force)
      permanently_delete_records_after { super() }
    else
      destroy_with_permanent_records(force)
    end
  end
end

#unarchivable?Boolean

Returns:

  • (Boolean)


46
47
48
# File 'lib/active_archive/base.rb', line 46

def unarchivable?
  !archivable?
end

#unarchive(validate = nil) ⇒ Object



35
36
37
38
39
40
# File 'lib/active_archive/base.rb', line 35

def unarchive(validate=nil)
  with_transaction_returning_status do
    run_callbacks(:unarchive) { set_archived_at(nil, validate) }
    self
  end
end

#unarchived?Boolean

Returns:

  • (Boolean)


42
43
44
# File 'lib/active_archive/base.rb', line 42

def unarchived?
  !archived?
end