Class: HostStatus::ExpirationStatus

Inherits:
Status
  • Object
show all
Defined in:
app/models/host_status/expiration_status.rb

Constant Summary collapse

OK =
0
EXPIRED =
1
IN_GRACE_PERIOD =
2
EXPIRES_TODAY =
3
PENDING =
4

Class Method Summary collapse

Instance Method Summary collapse

Class Method Details

.status_nameObject



11
12
13
# File 'app/models/host_status/expiration_status.rb', line 11

def self.status_name
  N_('Expiration Status')
end

Instance Method Details

#relevant?(_options = {}) ⇒ Boolean

Returns:

  • (Boolean)


56
57
58
# File 'app/models/host_status/expiration_status.rb', line 56

def relevant?(_options = {})
  host.expires?
end

#to_global(_options = {}) ⇒ Object



24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
# File 'app/models/host_status/expiration_status.rb', line 24

def to_global(_options = {})
  case to_status
  when OK
    HostStatus::Global::OK
  when EXPIRES_TODAY
    HostStatus::Global::WARN
  when PENDING
    HostStatus::Global::WARN
  when IN_GRACE_PERIOD
    HostStatus::Global::ERROR
  when EXPIRED
    HostStatus::Global::ERROR
  else
    HostStatus::Global::OK
  end
end

#to_label(_options = {}) ⇒ Object



41
42
43
44
45
46
47
48
49
50
51
52
53
54
# File 'app/models/host_status/expiration_status.rb', line 41

def to_label(_options = {})
  case to_status
  when OK
    N_('Expires on %s') % I18n.l(host.expired_on.to_date)
  when EXPIRES_TODAY
    N_('Expires today')
  when IN_GRACE_PERIOD
    N_('Expired on %s, in grace period') % I18n.l(host.expired_on.to_date)
  when EXPIRED
    N_('Expired on %s') % I18n.l(host.expired_on.to_date)
  else
    N_('Pending expiration on %s') % I18n.l(host.expired_on.to_date)
  end
end

#to_status(_options = {}) ⇒ Object



15
16
17
18
19
20
21
22
# File 'app/models/host_status/expiration_status.rb', line 15

def to_status(_options = {})
  return EXPIRES_TODAY if host.expires_today?
  return EXPIRED if host.expired_past_grace_period?
  return IN_GRACE_PERIOD if host.expired?
  return PENDING if host.pending_expiration?

  OK
end