Class: ForemanDatacenter::DeviceRole

Inherits:
ActiveRecord::Base
  • Object
show all
Includes:
Authorizable, ScopedSearchExtensions
Defined in:
app/models/foreman_datacenter/device_role.rb

Constant Summary collapse

COLORS =
[
    'Teal', 'Green', 'Blue', 'Purple', 'Yellow', 'Orange', 'Red',
    'Light Gray', 'Medium Gray', 'Dark Gray'
].freeze

Class Method Summary collapse

Instance Method Summary collapse

Class Method Details

.for_hostObject



28
29
30
31
32
33
34
35
# File 'app/models/foreman_datacenter/device_role.rb', line 28

def self.for_host
  role = find_by_name('Server')
  if role
    role
  else
    create!(name: 'Server', color: 'Green')
  end
end

Instance Method Details

#devices_countObject



22
23
24
25
26
# File 'app/models/foreman_datacenter/device_role.rb', line 22

def devices_count
  @devices_count ||= self.class.where(id: id).
      joins(:devices).
      count
end