Module: ActiveDisablable

Included in:
City, CompanyBusiness, Customer, TaskType, User
Defined in:
lib/active_extend/active_disablable.rb

Defined Under Namespace

Modules: ClassMethods

Class Method Summary collapse

Instance Method Summary collapse

Class Method Details

.included(base) ⇒ Object



6
7
8
9
# File 'lib/active_extend/active_disablable.rb', line 6

def self.included(base)
  base.extend(ClassMethods)
  base.send(:default_scope) { base.where(:enabled => true) }
end

Instance Method Details

#destroyObject



40
41
42
43
44
45
46
47
# File 'lib/active_extend/active_disablable.rb', line 40

def destroy
  if (@destroy_fully || self.disabled?)
    super
  else
    disable
    self.save
  end
end

#destroy_fullyObject



54
55
56
57
# File 'lib/active_extend/active_disablable.rb', line 54

def destroy_fully
  @destroy_fully = true
  self.destroy
end

#disableObject



24
25
26
# File 'lib/active_extend/active_disablable.rb', line 24

def disable
  self.enabled = false
end

#disabled?Boolean

Returns:

  • (Boolean)


36
37
38
# File 'lib/active_extend/active_disablable.rb', line 36

def disabled?
  !self.enabled
end

#enableObject



28
29
30
# File 'lib/active_extend/active_disablable.rb', line 28

def enable
  self.enabled = true
end

#enabled?Boolean

Returns:

  • (Boolean)


32
33
34
# File 'lib/active_extend/active_disablable.rb', line 32

def enabled?
  self.enabled
end

#recoveryObject



49
50
51
52
# File 'lib/active_extend/active_disablable.rb', line 49

def recovery
  enable
  self.save
end