Sha256: f8150df55ef9cc00fde2dde6e0f856cc9592b172bd77f9fd29b782e71633e115

Contents?: true

Size: 943 Bytes

Versions: 41

Compression:

Stored size: 943 Bytes

Contents

module ForemanInventoryUpload
  module Generators
    class Metadata
      def initialize(output = [])
        @stream = JsonStream.new(output)
      end

      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

      def render(metadata = nil, &block)
        render_report(metadata, &block)
        @stream.out
      end

      private

      def render_report(metadata)
        @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
    end
  end
end

Version data entries

41 entries across 41 versions & 2 rubygems

Version Path
foreman_rh_cloud-0.9.10 lib/foreman_inventory_upload/generators/metadata.rb
foreman_rh_cloud-1.0.10 lib/foreman_inventory_upload/generators/metadata.rb
foreman_rh_cloud-2.0.10 lib/foreman_inventory_upload/generators/metadata.rb
foreman_rh_cloud-2.0.9 lib/foreman_inventory_upload/generators/metadata.rb
foreman_rh_cloud-1.0.9 lib/foreman_inventory_upload/generators/metadata.rb
foreman_rh_cloud-0.9.9 lib/foreman_inventory_upload/generators/metadata.rb
foreman_rh_cloud-0.9.8 lib/foreman_inventory_upload/generators/metadata.rb
foreman_rh_cloud-1.0.8 lib/foreman_inventory_upload/generators/metadata.rb
foreman_rh_cloud-2.0.8 lib/foreman_inventory_upload/generators/metadata.rb
foreman_rh_cloud-0.9.7 lib/foreman_inventory_upload/generators/metadata.rb
foreman_rh_cloud-1.0.7 lib/foreman_inventory_upload/generators/metadata.rb
foreman_rh_cloud-2.0.7 lib/foreman_inventory_upload/generators/metadata.rb
foreman_rh_cloud-0.9.6 lib/foreman_inventory_upload/generators/metadata.rb
foreman_rh_cloud-1.0.6 lib/foreman_inventory_upload/generators/metadata.rb
foreman_rh_cloud-2.0.6 lib/foreman_inventory_upload/generators/metadata.rb
foreman_rh_cloud-0.9.5 lib/foreman_inventory_upload/generators/metadata.rb
foreman_rh_cloud-1.0.5 lib/foreman_inventory_upload/generators/metadata.rb
foreman_rh_cloud-2.0.5 lib/foreman_inventory_upload/generators/metadata.rb
foreman_rh_cloud-0.9.4.1 lib/foreman_inventory_upload/generators/metadata.rb
foreman_rh_cloud-1.0.4.1 lib/foreman_inventory_upload/generators/metadata.rb