Module: Closet::Restore::ClassMethods
- Defined in:
- lib/closet/restore/class_methods.rb
Instance Method Summary collapse
- #restore(id, options = { dependent: true }) ⇒ Object
- #restore!(id, options = { dependent: true }) ⇒ Object
- #restore_all(options = { dependent: true }) ⇒ Object
- #restore_all!(options = { dependent: true }) ⇒ Object
Instance Method Details
#restore(id, options = { dependent: true }) ⇒ Object
13 14 15 16 17 18 19 |
# File 'lib/closet/restore/class_methods.rb', line 13 def restore( id, = { dependent: true } ) begin self.restore!( id, dependent: .with_indifferent_access[:dependent] ) rescue false end end |
#restore!(id, options = { dependent: true }) ⇒ Object
5 6 7 8 9 10 11 |
# File 'lib/closet/restore/class_methods.rb', line 5 def restore!( id, = { dependent: true } ) if .with_indifferent_access[:dependent] self.find(id).restore! else self.find(id).restore!( dependent: false ) end end |
#restore_all(options = { dependent: true }) ⇒ Object
37 38 39 40 41 42 43 |
# File 'lib/closet/restore/class_methods.rb', line 37 def restore_all( = { dependent: true } ) begin self.restore_all!( dependent: .with_indifferent_access[:dependent] ) rescue false end end |
#restore_all!(options = { dependent: true }) ⇒ Object
21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 |
# File 'lib/closet/restore/class_methods.rb', line 21 def restore_all!( = { dependent: true } ) if .with_indifferent_access[:dependent] ActiveRecord::Base.transaction do self.all.lazy.each do |record| record.restore! end end else ActiveRecord::Base.transaction do self.all.lazy.each do |record| record.restore!( dependent: false ) end end end end |