Class: Inventory::Base
- Inherits:
-
Object
- Object
- Inventory::Base
- Includes:
- AwsServices
- Defined in:
- lib/inventory/base.rb
Overview
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.
Direct Known Subclasses
Acm, Cfn, Cloudwatch, Eb, Ec2, Ecs, Ecs::Cluster, Ecs::Service, Elb, Iam, Iam::Group, Iam::Summary, Iam::User, Keypair, Rds, Rds::Port, Rds::Summary, Route53, SecurityGroup, SecurityGroup::Open, SecurityGroup::Summary, Vpc
Class Method Summary collapse
-
.eager_load! ⇒ Object
Thought this might be useful for specs.
- .inherited(base) ⇒ Object
-
.subclasses ⇒ Object
Track all command subclasses.
Instance Method Summary collapse
-
#initialize(options) ⇒ Base
constructor
A new instance of Base.
- #report ⇒ Object
- #show(report_type) ⇒ Object
- #sort(data) ⇒ Object
- #test_mode ⇒ Object
Methods included from AwsServices
#acm, #cfn, #cw, #eb, #ec2, #ecs, #elbv1, #elbv2, #iam, #pricing, #rds, #route53
Methods included from Shared
Constructor Details
#initialize(options) ⇒ Base
Returns a new instance of Base.
9 10 11 |
# File 'lib/inventory/base.rb', line 9 def initialize() @options = end |
Class Method Details
.eager_load! ⇒ Object
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
56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 |
# File 'lib/inventory/base.rb', line 56 def eager_load! path = File.("../", __FILE__) Dir.glob("#{path}/**/*.rb").select do |path| next if !File.file?(path) or path =~ /version/ class_name = path .sub('.rb','') .sub(%r{.*/inventory}, 'inventory') .sub('presenters', 'presenter') # special rule .camelize # special rules class_name.sub!("Cli", "CLI") class_name.constantize # use constantize instead of require # so we dont have to worry about require order. end end |
.inherited(base) ⇒ Object
43 44 45 46 47 48 49 |
# File 'lib/inventory/base.rb', line 43 def inherited(base) super if base.name self.subclasses << base end end |
.subclasses ⇒ Object
Track all command subclasses.
39 40 41 |
# File 'lib/inventory/base.rb', line 39 def subclasses @subclasses ||= [] end |
Instance Method Details
#report ⇒ Object
13 14 15 16 17 18 19 20 |
# File 'lib/inventory/base.rb', line 13 def report return if test_mode results = sort(data) results.unshift(header) if header presenter = Inventory::Presenter.new(results) presenter.display end |
#show(report_type) ⇒ Object
33 34 35 |
# File 'lib/inventory/base.rb', line 33 def show(report_type) ["all", report_type.to_s].include?(@options[:report_type]) end |
#sort(data) ⇒ Object
22 23 24 |
# File 'lib/inventory/base.rb', line 22 def sort(data) data.sort_by {|a| a[0]} end |
#test_mode ⇒ Object
26 27 28 29 30 31 |
# File 'lib/inventory/base.rb', line 26 def test_mode if ENV['TEST'] puts "Testing #{self.class} report" # specs tests against this true end end |