Module: Closet::Restore::InstanceMethods

Defined in:
lib/closet/restore/instance_methods.rb

Instance Method Summary collapse

Instance Method Details

#restore(options = { dependent: true }) ⇒ Object



17
18
19
20
21
22
23
# File 'lib/closet/restore/instance_methods.rb', line 17

def restore( options = { dependent: true } )
  begin
    self.restore!( dependent: options.with_indifferent_access[:dependent] )
  rescue
    false
  end
end

#restore!(options = { dependent: true }) ⇒ Object



5
6
7
8
9
10
11
12
13
14
15
# File 'lib/closet/restore/instance_methods.rb', line 5

def restore!( options = { dependent: true } )
  if options.with_indifferent_access[:dependent]
    ActiveRecord::Base.transaction do
      run_callbacks( :restore ) do
        flag_as_restored
      end
    end
  else
    flag_as_restored
  end
end