class ForemanInventoryUpload::Generators::Metadata

Public Class Methods

new(output = []) click to toggle source
# File lib/foreman_inventory_upload/generators/metadata.rb, line 4
def initialize(output = [])
  @stream = JsonStream.new(output)
end

Public Instance Methods

add_slice(slice_id, hosts_count, first) click to toggle source
# File lib/foreman_inventory_upload/generators/metadata.rb, line 8
def add_slice(slice_id, hosts_count, first)
  @stream.comma unless first

  @stream.object_field(slice_id, :last) do
    @stream.simple_field('number_hosts', hosts_count, :last)
  end
end
render(metadata = nil, &block) click to toggle source
# File lib/foreman_inventory_upload/generators/metadata.rb, line 16
def render(metadata = nil, &block)
  render_report(metadata, &block)
  @stream.out
end

Private Instance Methods

render_report(metadata) { |self| ... } click to toggle source
# File lib/foreman_inventory_upload/generators/metadata.rb, line 23
def render_report(metadata)
  metadata ||= {}
  metadata['foreman_rh_cloud_version'] = ForemanRhCloud::VERSION

  @stream.object do
    @stream.simple_field('report_id', Foreman.uuid)
    @stream.simple_field('host_inventory_api_version', '1.0')
    @stream.simple_field('source', 'Satellite')
    @stream.simple_field('source_metadata', metadata)
    @stream.object_field('report_slices', :last) do
      yield(self)
    end
  end
end