Class: Naplug::Plugin
- Inherits:
-
Object
- Object
- Naplug::Plugin
- Defined in:
- lib/naplug/plugin.rb
Defined Under Namespace
Classes: DuplicatePlugin
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
-
#disable! ⇒ Object
disable execution of the plugin; metaplugins cannot be disabled.
-
#enable! ⇒ Object
enable execution of the plugin; metaplugins are always enabled.
- #eval ⇒ Object
-
#has_plugins? ⇒ Boolean
(also: #has_plugs?)
true when a plugin contains plugs.
-
#initialize(tag, meta = false, block) ⇒ Plugin
constructor
A new instance of Plugin.
-
#is_disabled? ⇒ Boolean
true when the plugin is disabled; false otherwise.
-
#is_enabled? ⇒ Boolean
true when plugin is enabled; false otherwise.
-
#is_meta? ⇒ True, ...
# true if this plugin is a metaplugin, false otherwise.
- #long_output ⇒ Object
- #long_output!(long_output) ⇒ Object
-
#output ⇒ String
Gets plugin text output.
-
#output!(text_output) ⇒ String
Sets plugin text output.
- #payload ⇒ Object
- #payload!(p) ⇒ Object
-
#perfdata ⇒ Object
returns the performance data of the plugin as a PerformanceData object.
- #perfdata!(label, value, f = {}) ⇒ Object
-
#status ⇒ Status
Plugin status.
- #to_s ⇒ Object
Constructor Details
#initialize(tag, meta = false, block) ⇒ Plugin
Returns a new instance of Plugin.
15 16 17 18 19 20 21 22 23 24 25 26 |
# File 'lib/naplug/plugin.rb', line 15 def initialize(tag, = false, block) @tag = tag @block = block @plugins = Hash.new @_args = Hash.new @_data = OpenStruct.new :status => Status.new, :output => Output.new, :payload => nil, :perfdata => nil = OpenStruct.new :status => , :enabled => true, :debug => true begin; instance_eval &block ; rescue => e; nil ; end end |
Instance Attribute Details
#block ⇒ Object (readonly)
Returns the value of attribute block.
11 12 13 |
# File 'lib/naplug/plugin.rb', line 11 def block @block end |
#plugins ⇒ Object (readonly)
Returns the value of attribute plugins.
11 12 13 |
# File 'lib/naplug/plugin.rb', line 11 def plugins @plugins end |
#tag ⇒ Object (readonly)
Returns the value of attribute tag.
11 12 13 |
# File 'lib/naplug/plugin.rb', line 11 def tag @tag end |
Instance Method Details
#[](k) ⇒ Object
119 120 121 |
# File 'lib/naplug/plugin.rb', line 119 def [](k) @_args[k] end |
#[]=(k, v) ⇒ Object
123 124 125 |
# File 'lib/naplug/plugin.rb', line 123 def []=(k,v) @_args[k] = v end |
#args ⇒ Object
106 107 108 |
# File 'lib/naplug/plugin.rb', line 106 def args @_args end |
#args!(args) ⇒ Object
110 111 112 113 114 115 116 117 |
# File 'lib/naplug/plugin.rb', line 110 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 |
#disable! ⇒ Object
disable execution of the plugin; metaplugins cannot be disabled
42 43 44 |
# File 'lib/naplug/plugin.rb', line 42 def disable! ? nil : .enabled = false end |
#enable! ⇒ Object
enable execution of the plugin; metaplugins are always enabled
37 38 39 |
# File 'lib/naplug/plugin.rb', line 37 def enable! ? nil : .enabled = true end |
#eval ⇒ Object
131 132 133 134 135 136 137 138 |
# File 'lib/naplug/plugin.rb', line 131 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
57 58 59 |
# File 'lib/naplug/plugin.rb', line 57 def has_plugins? @plugins.empty? ? false : true end |
#is_disabled? ⇒ Boolean
true when the plugin is disabled; false otherwise
52 53 54 |
# File 'lib/naplug/plugin.rb', line 52 def is_disabled? not .enabled end |
#is_enabled? ⇒ Boolean
true when plugin is enabled; false otherwise
47 48 49 |
# File 'lib/naplug/plugin.rb', line 47 def is_enabled? .enabled end |
#is_meta? ⇒ True, ...
# true if this plugin is a metaplugin, false otherwise
32 33 34 |
# File 'lib/naplug/plugin.rb', line 32 def .status end |
#long_output ⇒ Object
80 81 82 |
# File 'lib/naplug/plugin.rb', line 80 def long_output @_data.output.long_output end |
#long_output!(long_output) ⇒ Object
84 85 86 |
# File 'lib/naplug/plugin.rb', line 84 def long_output!(long_output) @_data.output.push long_output end |
#output ⇒ String
Gets plugin text output
69 70 71 |
# File 'lib/naplug/plugin.rb', line 69 def output @_data.output end |
#output!(text_output) ⇒ String
Sets plugin text output
76 77 78 |
# File 'lib/naplug/plugin.rb', line 76 def output!(text_output) @_data.output.text_output = text_output end |
#payload ⇒ Object
98 99 100 |
# File 'lib/naplug/plugin.rb', line 98 def payload @_data.payload end |
#payload!(p) ⇒ Object
102 103 104 |
# File 'lib/naplug/plugin.rb', line 102 def payload!(p) @_data.payload = p end |
#perfdata ⇒ Object
returns the performance data of the plugin as a PerformanceData object
89 90 91 |
# File 'lib/naplug/plugin.rb', line 89 def perfdata @_data.perfdata end |
#perfdata!(label, value, f = {}) ⇒ Object
93 94 95 96 |
# File 'lib/naplug/plugin.rb', line 93 def perfdata!(label,value,f = {}) @_data.perfdata ||= PerformanceData.new @tag @_data.perfdata.store label, value, f end |
#status ⇒ Status
Returns plugin status.
63 64 65 |
# File 'lib/naplug/plugin.rb', line 63 def status @_data.status end |
#to_s ⇒ Object
127 128 129 |
# File 'lib/naplug/plugin.rb', line 127 def to_s '%s: %s' % [status,output] end |