Module: Naplug::InstanceMethods
- Defined in:
- lib/naplug.rb
Instance Attribute Summary collapse
-
#plugins ⇒ Object
readonly
Returns the value of attribute plugins.
Instance Method Summary collapse
-
#args ⇒ Hash
Returns the arguments of the plugin.
-
#args!(args) ⇒ Object
Sets and propagates plugin arguments.
- #eject!(payload = nil) ⇒ Object
- #eval(tag = default_plugin.tag) ⇒ Object
- #eval!(tag = default_plugin.tag) ⇒ Object
-
#exec(t = default_plugin.tag) ⇒ Object
Execute the plugin.
-
#exec!(tag = default_plugin.tag) ⇒ Object
Execute, evaluate and exit the plugin according to the plugin status, outputting the plugin’s text output (and performance data, if applicable).
- #initialize(args = {}) ⇒ Object
-
#perfdata(tag = default_plugin.tag) ⇒ Array<PerformanceData>
A list of performance data objects.
- #to_str(tag = default_plugin.tag) ⇒ Object
Dynamic Method Handling
This class handles dynamic methods through the method_missing method
#method_missing(method, *args, &block) ⇒ Object (private)
214 215 216 217 218 219 220 221 222 |
# File 'lib/naplug.rb', line 214 def method_missing(method, *args, &block) = "undefined instance variable or method #{method}" case @_runinng when nil? begin; raise Naplug::Error, ; rescue => e; eject! e ; end else raise Naplug::Error, end end |
Instance Attribute Details
#plugins ⇒ Object (readonly)
Returns the value of attribute plugins.
81 82 83 |
# File 'lib/naplug.rb', line 81 def plugins @plugins end |
Instance Method Details
#args ⇒ Hash
Returns the arguments of the plugin
93 94 95 |
# File 'lib/naplug.rb', line 93 def args @_args end |
#args!(args) ⇒ Object
Sets and propagates plugin arguments
99 100 101 102 103 104 105 106 |
# File 'lib/naplug.rb', line 99 def args!(args) @_args.merge! args @plugins.each do |tag,plugin| plugin_args = args.key?(tag) ? args[tag] : {} shared_args = args.select { |t,a| not @plugins.keys.include? t } plugin.args! shared_args.merge! plugin_args end end |
#eject!(payload = nil) ⇒ Object
148 149 150 151 152 153 154 155 156 157 |
# File 'lib/naplug.rb', line 148 def eject!(payload = nil) o = case payload when String then payload when Exception then "#{payload.backtrace[1][/.+:\d+/]}: #{payload.message}" else nil caller[0][/.+:\d+/] end print "UNKNOWN: plugin eject! in %s\n" % [o] Kernel::exit 3 end |
#eval(tag = default_plugin.tag) ⇒ Object
139 140 141 |
# File 'lib/naplug.rb', line 139 def eval(tag = default_plugin.tag) @plugins[tag].eval end |
#eval!(tag = default_plugin.tag) ⇒ Object
143 144 145 146 |
# File 'lib/naplug.rb', line 143 def eval!(tag = default_plugin.tag) @plugins[tag].eval exit tag end |
#exec(t = default_plugin.tag) ⇒ Object
Execute the plugin
130 131 132 133 134 135 136 137 |
# File 'lib/naplug.rb', line 130 def exec(t = default_plugin.tag) plugin = target_plugin t if plugin.has_plugins? plugin.plugins.each_value { |p| exec p } else plexec plugin end end |
#exec!(tag = default_plugin.tag) ⇒ Object
Execute, evaluate and exit the plugin according to the plugin status, outputting the plugin’s text output (and performance data, if applicable)
122 123 124 125 126 |
# File 'lib/naplug.rb', line 122 def exec!(tag = default_plugin.tag) exec tag eval tag exit tag end |
#initialize(args = {}) ⇒ Object
83 84 85 86 87 88 89 |
# File 'lib/naplug.rb', line 83 def initialize(args = {}) @plugins = Hash.new plugins! @_args = Hash.new args! args end |
#perfdata(tag = default_plugin.tag) ⇒ Array<PerformanceData>
Returns a list of performance data objects.
160 161 162 163 164 165 166 167 |
# File 'lib/naplug.rb', line 160 def perfdata(tag = default_plugin.tag) plugin = @plugins[tag] if plugin.has_plugins? plugin.plugins.values.select { |plug| plug.perfdata }.map { |plug| plug.perfdata } else plugin.perfdata ? [plugin.perfdata] : [] end end |
#to_str(tag = default_plugin.tag) ⇒ Object
108 109 110 111 112 113 114 115 116 117 118 |
# File 'lib/naplug.rb', line 108 def to_str(tag = default_plugin.tag) pd = perfdata(tag) if pd.empty? s_format = '%s: %s' s_array = [@plugins[tag].status,@plugins[tag].output] else s_format = '%s: %s | %s' s_array = [@plugins[tag].status,@plugins[tag].output,pd.join(' ').strip] end s_format % s_array end |