Class: Nagi::Plugin
- Inherits:
-
Object
- Object
- Nagi::Plugin
- Defined in:
- lib/nagi/plugin.rb
Instance Attribute Summary collapse
-
#fallback ⇒ Object
Returns the value of attribute fallback.
-
#name ⇒ Object
Returns the value of attribute name.
-
#optionparser ⇒ Object
Returns the value of attribute optionparser.
-
#prefix ⇒ Object
Returns the value of attribute prefix.
-
#version ⇒ Object
Returns the value of attribute version.
Instance Method Summary collapse
- #check(options) ⇒ Object
-
#initialize ⇒ Plugin
constructor
A new instance of Plugin.
- #run(args) ⇒ Object
- #run! ⇒ Object
Constructor Details
#initialize ⇒ Plugin
Returns a new instance of Plugin.
5 6 7 |
# File 'lib/nagi/plugin.rb', line 5 def initialize @optionparser = Nagi::OptionParser.new end |
Instance Attribute Details
#fallback ⇒ Object
Returns the value of attribute fallback.
3 4 5 |
# File 'lib/nagi/plugin.rb', line 3 def fallback @fallback end |
#name ⇒ Object
Returns the value of attribute name.
3 4 5 |
# File 'lib/nagi/plugin.rb', line 3 def name @name end |
#optionparser ⇒ Object
Returns the value of attribute optionparser.
3 4 5 |
# File 'lib/nagi/plugin.rb', line 3 def optionparser @optionparser end |
#prefix ⇒ Object
Returns the value of attribute prefix.
3 4 5 |
# File 'lib/nagi/plugin.rb', line 3 def prefix @prefix end |
#version ⇒ Object
Returns the value of attribute version.
3 4 5 |
# File 'lib/nagi/plugin.rb', line 3 def version @version end |
Instance Method Details
#check(options) ⇒ Object
9 10 11 |
# File 'lib/nagi/plugin.rb', line 9 def check() raise NotImplementedError.new('No check defined') end |
#run(args) ⇒ Object
18 19 20 21 22 23 24 25 26 27 28 29 |
# File 'lib/nagi/plugin.rb', line 18 def run(args) = @optionparser.parse(args) begin status = self.check() rescue StandardError => e status = Nagi::Status::Unknown.new(e.) end unless status.is_a?Nagi::Status::Status status = @fallback || Nagi::Status::Unknown.new('Check did not provide a status') end return status end |
#run! ⇒ Object
31 32 33 34 35 36 37 38 39 40 41 42 |
# File 'lib/nagi/plugin.rb', line 31 def run! begin status = run(ARGV) puts "#{@prefix.upcase if @prefix} #{status}".strip exit status.code rescue ArgumentError => e STDERR.puts("Error: #{e.}") puts "" puts @optionparser exit 4 end end |