Class: ForemanDatacenter::Rack
- Inherits:
-
ActiveRecord::Base
- Object
- ActiveRecord::Base
- ForemanDatacenter::Rack
- Includes:
- Authorizable, ScopedSearchExtensions
- Defined in:
- app/models/foreman_datacenter/rack.rb
Instance Method Summary collapse
- #device_at(position) ⇒ Object
- #devices_count ⇒ Object
-
#positioned_devices ⇒ Object
def positioned_devices height.downto(1).map { |position| [position, device_at(position)] } end.
- #unpositioned_devices ⇒ Object
Instance Method Details
#device_at(position) ⇒ Object
25 26 27 |
# File 'app/models/foreman_datacenter/rack.rb', line 25 def device_at(position) devices.where(position: position).to_a end |
#devices_count ⇒ Object
49 50 51 52 53 |
# File 'app/models/foreman_datacenter/rack.rb', line 49 def devices_count @devices_count ||= self.class.where(id: id). joins(:devices). count end |
#positioned_devices ⇒ Object
def positioned_devices
height.downto(1).map { |position| [position, device_at(position)] }
end
33 34 35 36 37 38 39 40 41 42 43 |
# File 'app/models/foreman_datacenter/rack.rb', line 33 def positioned_devices devs = devices.map{ |d| [d.positions, [d]] } result = [] i = 1 loop do current_device = devs.select{ |d| d[0].include?(i) } current_device == [] ? (result << [[i],[]]; i +=1 ) : (result << merge_devices(current_device, i); i = i + current_device[0][1].last.size) break if i > height end device_sorting(result) end |
#unpositioned_devices ⇒ Object
45 46 47 |
# File 'app/models/foreman_datacenter/rack.rb', line 45 def unpositioned_devices devices.where(position: nil).to_a end |