Class: Scout::PluginOptions
- Inherits:
-
Array
- Object
- Array
- Scout::PluginOptions
- Defined in:
- lib/scout/plugin_options.rb
Overview
A collection of pluginOption Create: opts=PluginOptions.from_yaml(yaml_string) Check if there were any problems – opts.error – should be nil.
A valid options yaml looks like this:
max_swap_used:
notes: If swap is larger than this amount, an alert is generated. Amount should be in MB.
default: 2048 # 2 GB
max_swap_ratio:
notes: If swap used over memory used is larger than this amount, an alert is generated
default: 3
attributes: required advanced
Instance Attribute Summary collapse
-
#error ⇒ Object
Returns the value of attribute error.
-
#hash ⇒ Object
Returns the value of attribute hash.
Class Method Summary collapse
-
.from_yaml(string) ⇒ Object
Should be valid YAML, a hash of hashes …
Instance Method Summary collapse
Instance Attribute Details
#error ⇒ Object
Returns the value of attribute error.
51 52 53 |
# File 'lib/scout/plugin_options.rb', line 51 def error @error end |
#hash ⇒ Object
Returns the value of attribute hash.
51 52 53 |
# File 'lib/scout/plugin_options.rb', line 51 def hash @hash end |
Class Method Details
.from_yaml(string) ⇒ Object
Should be valid YAML, a hash of hashes … if not, will be caught in the rescue below
54 55 56 57 58 59 60 61 62 63 64 65 66 67 |
# File 'lib/scout/plugin_options.rb', line 54 def self.from_yaml(string) =[] error=nil items=YAML.load(string) items.each_pair {|name, hash| .push(PluginOption.new(name,hash)) } rescue error="Invalid Plugin Options" ensure res=PluginOptions.new() res.error=error res.hash = items unless res.error return res end |
Instance Method Details
#advanced ⇒ Object
69 70 71 |
# File 'lib/scout/plugin_options.rb', line 69 def advanced select{|o|o.advanced? } end |
#regular ⇒ Object
73 74 75 |
# File 'lib/scout/plugin_options.rb', line 73 def regular select{|o|!o.advanced? } end |
#to_hash ⇒ Object
85 86 87 |
# File 'lib/scout/plugin_options.rb', line 85 def to_hash hash end |
#to_s ⇒ Object
77 78 79 80 81 82 83 |
# File 'lib/scout/plugin_options.rb', line 77 def to_s res=[] each_with_index do |opt,i| res.push "#{i+1}. #{opt.to_s}" end res.join("\n") end |