Class: BjnInventory::SourceCommand

Inherits:
Object
  • Object
show all
Defined in:
lib/bjn_inventory/source_command.rb,
lib/bjn_inventory/source_command/aws_ec2.rb,
lib/bjn_inventory/source_command/aws_elb.rb,
lib/bjn_inventory/source_command/aws_rds.rb

Direct Known Subclasses

AwsEc2, AwsElb, AwsRds

Defined Under Namespace

Classes: AwsEc2, AwsElb, AwsRds

Instance Method Summary collapse

Constructor Details

#initialize(kwargs = {}) ⇒ SourceCommand

Intended to be the result of command-line parsing



8
9
10
11
12
# File 'lib/bjn_inventory/source_command.rb', line 8

def initialize(kwargs={})
    @output = kwargs[:output] || nil
    @logger = kwargs[:logger] || BjnInventory::DefaultLogger.new
    set_options kwargs
end

Instance Method Details

#loggerObject



18
19
20
# File 'lib/bjn_inventory/source_command.rb', line 18

def logger()
    @logger
end

#retrieve_entriesObject

Raises:

  • (RuntimeError)


35
36
37
# File 'lib/bjn_inventory/source_command.rb', line 35

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

#runObject



22
23
24
25
26
27
28
29
30
31
32
33
# File 'lib/bjn_inventory/source_command.rb', line 22

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

#set_options(kwargs = {}) ⇒ Object



14
15
16
# File 'lib/bjn_inventory/source_command.rb', line 14

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