Module: Closet::Bury::ClassMethods

Defined in:
lib/closet/bury/class_methods.rb

Instance Method Summary collapse

Instance Method Details

#buried?(id) ⇒ Boolean

Returns:

  • (Boolean)


21
22
23
# File 'lib/closet/bury/class_methods.rb', line 21

def buried?(id)
  self.find(id).buried_at != nil
end

#bury(id, options = { dependent: true }) ⇒ Object



13
14
15
16
17
18
19
# File 'lib/closet/bury/class_methods.rb', line 13

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

#bury!(id, options = { dependent: true }) ⇒ Object



5
6
7
8
9
10
11
# File 'lib/closet/bury/class_methods.rb', line 5

def bury!( id, options= { dependent: true } )
  if options.with_indifferent_access[:dependent]
    self.find(id).bury!
  else
    self.find(id).bury!( dependent: false )
  end
end

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



41
42
43
44
45
46
47
# File 'lib/closet/bury/class_methods.rb', line 41

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

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



25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
# File 'lib/closet/bury/class_methods.rb', line 25

def bury_all!( options = { dependent: true } )
  if options.with_indifferent_access[:dependent]
    ActiveRecord::Base.transaction do
      self.all.each do |record|
        record.bury!
      end
    end
  else
    ActiveRecord::Base.transaction do
      self.all.each do |record|
        record.bury!( dependent: false )
      end
    end
  end
end