Module: StorageUnit::Core

Extended by:
ActiveSupport::Concern
Defined in:
lib/storage_unit/core.rb

Defined Under Namespace

Modules: ClassMethods

Instance Method Summary collapse

Instance Method Details

#recover!(opts = {}) ⇒ Object



50
51
52
53
54
55
# File 'lib/storage_unit/core.rb', line 50

def recover!(opts = {})
  run_callbacks :recover do
    update_columns trash_hash(nil)
    recover_dependents
  end
end

#recover_dependentsObject



57
58
59
60
61
# File 'lib/storage_unit/core.rb', line 57

def recover_dependents
  Array(storage_unit_opts[:cascade]).each do |x|
    send(x).with_deleted.update_all trash_hash(nil)
  end
end

#trash!Object



37
38
39
40
41
42
# File 'lib/storage_unit/core.rb', line 37

def trash!
  run_callbacks :trash do
    update_columns trash_hash(DateTime.now)
    trash_dependents
  end
end

#trash_dependentsObject



44
45
46
47
48
# File 'lib/storage_unit/core.rb', line 44

def trash_dependents
  Array(storage_unit_opts[:cascade]).each do |x|
    send(x).update_all trash_hash(DateTime.now)
  end
end

#trash_hash(value) ⇒ Object



63
64
65
# File 'lib/storage_unit/core.rb', line 63

def trash_hash(value)
  {}.tap { |h| h[storage_unit_opts[:column]] = value }
end

#trashed?Boolean

Returns:

  • (Boolean)


33
34
35
# File 'lib/storage_unit/core.rb', line 33

def trashed?
  send(storage_unit_opts[:column]).present?
end