Sha256: 065882e691a227780380b43ca14ecfa8c01fab9b26abc0b8f8cf5b20cacccf57

Contents?: true

Size: 1.09 KB

Versions: 6

Compression:

Stored size: 1.09 KB

Contents

require 'bjn_inventory/default_logger'

module BjnInventory

    class SourceCommand

        # Intended to be the result of command-line parsing
        def initialize(kwargs={})
            @output = kwargs[:output] || nil
            @logger = kwargs[:logger] || BjnInventory::DefaultLogger.new
            set_options kwargs
        end

        def set_options(kwargs={})
            @options = kwargs
        end

        def logger()
            @logger
        end

        def run()
            entries = retrieve_entries
            if @output
                tmpfile = File.join(File.dirname(@output), '.' + File.basename(@output) + '.tmp.' + Process.pid.to_s)
                File.open(tmpfile, 'w') do |fh|
                    fh.write JSON.pretty_generate entries
                end
                File.rename(tmpfile, @output)
            else
                $stdout.write JSON.pretty_generate entries
            end
        end

        def retrieve_entries
            raise RuntimeError, "#{self.class} has no retrieve_entries() implementation - source type unsupported"
        end

    end

end

Version data entries

6 entries across 6 versions & 1 rubygems

Version Path
bjn_inventory-1.7.1 lib/bjn_inventory/source_command.rb
bjn_inventory-1.7.0 lib/bjn_inventory/source_command.rb
bjn_inventory-1.6.1 lib/bjn_inventory/source_command.rb
bjn_inventory-1.5.1 lib/bjn_inventory/source_command.rb
bjn_inventory-1.3.1 lib/bjn_inventory/source_command.rb
bjn_inventory-1.3.0 lib/bjn_inventory/source_command.rb