forked from ManageIQ/manageiq
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy patharchived_mixin.rb
39 lines (32 loc) · 962 Bytes
/
archived_mixin.rb
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
module ArchivedMixin
extend ActiveSupport::Concern
included do
scope :archived, -> { where.not(:deleted_on => nil) }
scope :active, -> { where(:deleted_on => nil) }
belongs_to :old_ext_management_system, :foreign_key => :old_ems_id, :class_name => 'ExtManagementSystem'
end
def archived?
!active?
end
alias_method :archived, :archived?
def active?
deleted_on.nil?
end
alias_method :active, :active?
def archive!
update_attributes!(:deleted_on => Time.now.utc)
end
def unarchive!
update_attributes!(:deleted_on => nil)
end
# Needed for metrics
def my_zone
if ext_management_system.present?
ext_management_system.my_zone
elsif old_ext_management_system.present?
# Archived container entities need to retain their zone for metric collection
# This makes the association more complex and might need a performance fix
old_ext_management_system.my_zone
end
end
end