class InventorySync::Async::HostResult
Public Class Methods
new(result)
click to toggle source
# File lib/inventory_sync/async/host_result.rb, line 4 def initialize(result) @total = result['total'] @count = result['count'] @page = result['page'] @per_page = result['per_page'] @fqdns = result["results"].map { |host| host['fqdn'] } end
Public Instance Methods
host_id(fqdn)
click to toggle source
# File lib/inventory_sync/async/host_result.rb, line 30 def host_id(fqdn) hosts[fqdn] end
hosts()
click to toggle source
# File lib/inventory_sync/async/host_result.rb, line 34 def hosts @hosts ||= Hash[ Host.where(name: @fqdns).pluck(:name, :id) ] end
last?()
click to toggle source
# File lib/inventory_sync/async/host_result.rb, line 45 def last? @total <= @per_page * @page end
percentage()
click to toggle source
# File lib/inventory_sync/async/host_result.rb, line 40 def percentage ratio = @per_page * @page * 1.0 / @total * 100 ratio > 100 ? 100 : ratio.truncate(2) end
status_hashes()
click to toggle source
# File lib/inventory_sync/async/host_result.rb, line 12 def status_hashes @fqdns.map do |fqdn| host_id = host_id(fqdn) if host_id touched << host_id { host_id: host_id, status: InventorySync::InventoryStatus::SYNC, reported_at: DateTime.current, } end end.compact end
touched()
click to toggle source
# File lib/inventory_sync/async/host_result.rb, line 26 def touched @touched ||= [] end