class AwsInventory::Base
Child class must implement this interface. Methods:
header - header row to display. Array of strings. data - data to display under header. 2D Array. Each item in the array represents a row of data.
Public Class Methods
eager_load!()
click to toggle source
Thought this might be useful for specs. Eager load all classes so then we can loop thorugh the methods and run specs on any new cli commands. The rspec code turn out a too ugly to follow though. Leaving this around in case eager_laod is useful for other purposes
# File lib/aws_inventory/base.rb, line 56 def eager_load! path = File.expand_path("../", __FILE__) Dir.glob("#{path}/**/*.rb").select do |path| next if !File.file?(path) or path =~ /version/ class_name = path .sub('.rb','') .sub(%r{.*/aws_inventory}, 'aws_inventory') .camelize # special rules class_name = class_name.sub("Cli", "CLI") .sub('Presenters', 'Presenter') class_name.constantize # use constantize instead of require # so we dont have to worry about require order. end end
inherited(base)
click to toggle source
Calls superclass method
# File lib/aws_inventory/base.rb, line 43 def inherited(base) super if base.name self.subclasses << base end end
new(options)
click to toggle source
# File lib/aws_inventory/base.rb, line 9 def initialize(options) @options = options end
subclasses()
click to toggle source
Track all command subclasses.
# File lib/aws_inventory/base.rb, line 39 def subclasses @subclasses ||= [] end
Public Instance Methods
report()
click to toggle source
# File lib/aws_inventory/base.rb, line 13 def report return if test_mode results = sort(data) results.unshift(header) if header presenter = AwsInventory::Presenter.new(@options, results) presenter.display end
show(report)
click to toggle source
# File lib/aws_inventory/base.rb, line 33 def show(report) ["all", report.to_s].include?(@options[:report]) end
sort(data)
click to toggle source
# File lib/aws_inventory/base.rb, line 22 def sort(data) data.sort_by {|a| a[0]} end
test_mode()
click to toggle source
# File lib/aws_inventory/base.rb, line 26 def test_mode if ENV['TEST'] puts "Testing #{self.class} report" # specs tests against this true end end