Passed
Push — master ( 9967e2...628790 )
by Jesus
08:18
created

Deleteable.permanent_delete()   A

Complexity

Conditions 1

Size

Total Lines 3

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 1
dl 0
loc 3
rs 10
c 0
b 0
f 0
1
# frozen_string_literal: true
2
3
# BigBlueButton open source conferencing system - http://www.bigbluebutton.org/.
4
#
5
# Copyright (c) 2018 BigBlueButton Inc. and by respective authors (see below).
6
#
7
# This program is free software; you can redistribute it and/or modify it under the
8
# terms of the GNU Lesser General Public License as published by the Free Software
9
# Foundation; either version 3.0 of the License, or (at your option) any later
10
# version.
11
#
12
# BigBlueButton is distributed in the hope that it will be useful, but WITHOUT ANY
13
# WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A
14
# PARTICULAR PURPOSE. See the GNU Lesser General Public License for more details.
15
#
16
# You should have received a copy of the GNU Lesser General Public License along
17
# with BigBlueButton; if not, see <http://www.gnu.org/licenses/>.
18
19
module Deleteable
20
  extend ActiveSupport::Concern
21
22
  included do
23
    # By default don't include deleted if the column has been created
24
    default_scope { where(deleted: false) } if column_names.include? 'deleted'
25
    scope :include_deleted, -> { unscope(where: :deleted) }
26
    scope :deleted, -> { include_deleted.where(deleted: true) }
27
  end
28
29
  def destroy(permanent = false)
30
    if permanent
31
      super()
32
    else
33
      run_callbacks :destroy do end
34
      update_attribute(:deleted, true)
35
    end
36
  end
37
38
  def delete(permanent = false)
39
    destroy(permanent)
40
  end
41
42
  def undelete!
43
    update_attribute(:deleted, false)
44
  end
45
46
  def permanent_delete
47
    destroy(true)
48
  end
49
50
  def deleted?
51
    deleted
52
  end
53
end
54