Class: Naplug::Plugin
- Inherits:
-
Object
- Object
- Naplug::Plugin
- Includes:
- Helpers::Grokkers
- Defined in:
- lib/naplug/plugin.rb
Instance Attribute Summary collapse
-
#block ⇒ Object
readonly
Returns the value of attribute block.
-
#plugins ⇒ Object
readonly
Returns the value of attribute plugins.
-
#tag ⇒ Object
readonly
Returns the value of attribute tag.
Instance Method Summary collapse
- #[](k) ⇒ Object
- #[]=(k, v) ⇒ Object
- #args ⇒ Object
- #args!(args) ⇒ Object
- #description ⇒ Object
- #eval ⇒ Object
-
#has_plugins? ⇒ Boolean
(also: #has_plugs?)
true when a plugin contains plugs.
-
#initialize(tag, block, meta) ⇒ Plugin
constructor
A new instance of Plugin.
- #long_output ⇒ Object
- #long_output!(long_output) ⇒ Object
- #meta ⇒ Object
-
#output ⇒ String
Gets plugin text output.
-
#output!(text_output) ⇒ String
Sets plugin text output.
- #parent ⇒ Object
- #payload ⇒ Object
- #payload!(p) ⇒ Object
-
#perfdata(mode = nil) ⇒ Object
returns the performance data of the plugin as a PerformanceData object.
- #perfdata!(label, value, f = {}) ⇒ Object
-
#status ⇒ Status
Plugin status.
- #to_str ⇒ Object
Methods included from Helpers::Grokkers
Constructor Details
#initialize(tag, block, meta) ⇒ Plugin
Returns a new instance of Plugin.
17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 |
# File 'lib/naplug/plugin.rb', line 17 def initialize(tag, block, ) @tag = tag @block = block @plugins = Hash.new @_args = Hash.new @_data = OpenStruct.new :status => Status.new, :output => Output.new, :payload => nil, :perfdata => nil @_meta = Meta.new begin instance_eval &block rescue ArgumentError => e raise rescue nil end end |
Instance Attribute Details
#block ⇒ Object (readonly)
Returns the value of attribute block.
15 16 17 |
# File 'lib/naplug/plugin.rb', line 15 def block @block end |
#plugins ⇒ Object (readonly)
Returns the value of attribute plugins.
15 16 17 |
# File 'lib/naplug/plugin.rb', line 15 def plugins @plugins end |
#tag ⇒ Object (readonly)
Returns the value of attribute tag.
15 16 17 |
# File 'lib/naplug/plugin.rb', line 15 def tag @tag end |
Instance Method Details
#[](k) ⇒ Object
116 117 118 |
# File 'lib/naplug/plugin.rb', line 116 def [](k) @_args[k] end |
#[]=(k, v) ⇒ Object
120 121 122 |
# File 'lib/naplug/plugin.rb', line 120 def []=(k,v) @_args[k] = v end |
#args ⇒ Object
103 104 105 |
# File 'lib/naplug/plugin.rb', line 103 def args @_args end |
#args!(args) ⇒ Object
107 108 109 110 111 112 113 114 |
# File 'lib/naplug/plugin.rb', line 107 def args!(args) @_args.merge! args @plugins.each do |tag,plug| plug_args = args.key?(tag) ? args[tag] : {} shared_args = args.select { |t,a| not @plugins.keys.include? t } plug.args! shared_args.merge! plug_args end end |
#description ⇒ Object
44 45 46 |
# File 'lib/naplug/plugin.rb', line 44 def description @_meta.description end |
#eval ⇒ Object
128 129 130 131 132 133 134 135 |
# File 'lib/naplug/plugin.rb', line 128 def eval unless @plugins.empty? wcu_plugins = @plugins.values.select { |plug| plug.status.not_ok? } plugins = wcu_plugins.empty? ? @plugins.values : wcu_plugins output! plugins.map { |plug| "[#{plug.status.to_y}#{plug.tag} #{plug.output}]" }.join(' ') @_data.status = plugins.map { |plug| plug.status }.max end end |
#has_plugins? ⇒ Boolean Also known as: has_plugs?
true when a plugin contains plugs
49 50 51 |
# File 'lib/naplug/plugin.rb', line 49 def has_plugins? @plugins.empty? ? false : true end |
#long_output ⇒ Object
72 73 74 |
# File 'lib/naplug/plugin.rb', line 72 def long_output @_data.output.long_output end |
#long_output!(long_output) ⇒ Object
76 77 78 |
# File 'lib/naplug/plugin.rb', line 76 def long_output!(long_output) @_data.output.push long_output end |
#meta ⇒ Object
36 37 38 |
# File 'lib/naplug/plugin.rb', line 36 def @_meta end |
#output ⇒ String
Gets plugin text output
61 62 63 |
# File 'lib/naplug/plugin.rb', line 61 def output @_data.output end |
#output!(text_output) ⇒ String
Sets plugin text output
68 69 70 |
# File 'lib/naplug/plugin.rb', line 68 def output!(text_output) @_data.output.text_output = text_output end |
#parent ⇒ Object
40 41 42 |
# File 'lib/naplug/plugin.rb', line 40 def parent @_meta.parent end |
#payload ⇒ Object
95 96 97 |
# File 'lib/naplug/plugin.rb', line 95 def payload @_data.payload end |
#payload!(p) ⇒ Object
99 100 101 |
# File 'lib/naplug/plugin.rb', line 99 def payload!(p) @_data.payload = p end |
#perfdata(mode = nil) ⇒ Object
returns the performance data of the plugin as a PerformanceData object
81 82 83 84 85 86 87 88 |
# File 'lib/naplug/plugin.rb', line 81 def perfdata(mode = nil) case mode when :deep plugins.values.map { |p| p.perfdata :deep }.push @_data.perfdata else @_data.perfdata end end |
#perfdata!(label, value, f = {}) ⇒ Object
90 91 92 93 |
# File 'lib/naplug/plugin.rb', line 90 def perfdata!(label,value,f = {}) @_data.perfdata ||= PerformanceData.new self @_data.perfdata[label] = value, f end |
#status ⇒ Status
Returns plugin status.
55 56 57 |
# File 'lib/naplug/plugin.rb', line 55 def status @_data.status end |
#to_str ⇒ Object
124 125 126 |
# File 'lib/naplug/plugin.rb', line 124 def to_str '%s: %s' % [status,output] end |