Class: Legion::Data::Model::DigitalWorker

Inherits:
Sequel::Model
  • Object
show all
Defined in:
lib/legion/data/models/digital_worker.rb

Constant Summary collapse

LIFECYCLE_STATES =
%w[bootstrap active paused retired terminated].freeze
%w[supervised consult notify autonomous].freeze
RISK_TIERS =
%w[low medium high critical].freeze
HEALTH_STATUSES =
%w[online offline unknown].freeze

Instance Method Summary collapse

Instance Method Details

#active?Boolean

Returns:

  • (Boolean)


22
23
24
# File 'lib/legion/data/models/digital_worker.rb', line 22

def active?
  lifecycle_state == 'active'
end

#offline?Boolean

Returns:

  • (Boolean)


38
39
40
# File 'lib/legion/data/models/digital_worker.rb', line 38

def offline?
  health_status == 'offline'
end

#online?Boolean

Returns:

  • (Boolean)


34
35
36
# File 'lib/legion/data/models/digital_worker.rb', line 34

def online?
  health_status == 'online'
end

#paused?Boolean

Returns:

  • (Boolean)


30
31
32
# File 'lib/legion/data/models/digital_worker.rb', line 30

def paused?
  lifecycle_state == 'paused'
end

#terminated?Boolean

Returns:

  • (Boolean)


26
27
28
# File 'lib/legion/data/models/digital_worker.rb', line 26

def terminated?
  lifecycle_state == 'terminated'
end

#validateObject



14
15
16
17
18
19
20
# File 'lib/legion/data/models/digital_worker.rb', line 14

def validate
  super
  errors.add(:lifecycle_state, 'invalid') unless LIFECYCLE_STATES.include?(lifecycle_state)
  errors.add(:consent_tier, 'invalid')    unless CONSENT_TIERS.include?(consent_tier)
  errors.add(:risk_tier, 'invalid')        if risk_tier && !RISK_TIERS.include?(risk_tier)
  errors.add(:health_status, 'invalid')    if health_status && !HEALTH_STATUSES.include?(health_status)
end