Class: WavefrontOutput::Base
- Inherits:
-
Object
- Object
- WavefrontOutput::Base
- Defined in:
- lib/wavefront-cli/output/base.rb
Overview
WavefrontCli::Base looks for a class WavefrontOutput::Format where ‘Format’ is something like ‘Json’, or ‘Yaml’. If it finds that class it creates a new instance, passing through the response object (@resp) and options hash (@options), then calls the #run method.
All those classes are an extension of this one. Some, like Json or Yaml, are generic, and dump a straight translation of the response object. Others, like Hcl or Wavefront, have subclasses which deal with the output of specific commands.
Instance Attribute Summary collapse
-
#cmd ⇒ Object
readonly
Returns the value of attribute cmd.
-
#options ⇒ Object
readonly
Returns the value of attribute options.
-
#resp ⇒ Object
readonly
Returns the value of attribute resp.
Instance Method Summary collapse
- #_run ⇒ Object
- #command_class ⇒ Object
- #command_class_name ⇒ Object
- #command_file ⇒ Object
-
#initialize(resp = {}, options = {}) ⇒ Base
constructor
A new instance of Base.
- #my_format ⇒ Object
-
#run ⇒ Object
We used to call #run directly, but now we use this wrapper to make it easier to test the #_run methods.
Constructor Details
#initialize(resp = {}, options = {}) ⇒ Base
17 18 19 20 21 |
# File 'lib/wavefront-cli/output/base.rb', line 17 def initialize(resp = {}, = {}) @cmd = [:class] @resp = resp = end |
Instance Attribute Details
#cmd ⇒ Object (readonly)
Returns the value of attribute cmd.
15 16 17 |
# File 'lib/wavefront-cli/output/base.rb', line 15 def cmd @cmd end |
#options ⇒ Object (readonly)
Returns the value of attribute options.
15 16 17 |
# File 'lib/wavefront-cli/output/base.rb', line 15 def end |
#resp ⇒ Object (readonly)
Returns the value of attribute resp.
15 16 17 |
# File 'lib/wavefront-cli/output/base.rb', line 15 def resp @resp end |
Instance Method Details
#_run ⇒ Object
30 31 32 |
# File 'lib/wavefront-cli/output/base.rb', line 30 def _run command_class.run end |
#command_class ⇒ Object
46 47 48 49 |
# File 'lib/wavefront-cli/output/base.rb', line 46 def command_class require_relative command_file Object.const_get(command_class_name).new(resp, ) end |
#command_class_name ⇒ Object
38 39 40 |
# File 'lib/wavefront-cli/output/base.rb', line 38 def command_class_name format('Wavefront%sOutput::%s', my_format.capitalize, cmd.capitalize) end |
#command_file ⇒ Object
42 43 44 |
# File 'lib/wavefront-cli/output/base.rb', line 42 def command_file File.join(my_format, cmd) end |
#my_format ⇒ Object
34 35 36 |
# File 'lib/wavefront-cli/output/base.rb', line 34 def my_format self.class.name.split('::').last.downcase end |
#run ⇒ Object
We used to call #run directly, but now we use this wrapper to make it easier to test the #_run methods.
26 27 28 |
# File 'lib/wavefront-cli/output/base.rb', line 26 def run puts _run end |