Class: Scout::PluginOptions

Inherits:
Array
  • Object
show all
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

Class Method Summary collapse

Instance Method Summary collapse

Instance Attribute Details

#errorObject

Returns the value of attribute error.



51
52
53
# File 'lib/scout/plugin_options.rb', line 51

def error
  @error
end

#hashObject

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)
  options_array=[]
  error=nil

  items=YAML.load(string)
  items.each_pair {|name, hash| options_array.push(PluginOption.new(name,hash)) }
rescue
  error="Invalid Plugin Options"
ensure
  res=PluginOptions.new(options_array)
  res.error=error
  res.hash = items unless res.error
  return res
end

Instance Method Details

#advancedObject



69
70
71
# File 'lib/scout/plugin_options.rb', line 69

def advanced
  select{|o|o.advanced? }
end

#regularObject



73
74
75
# File 'lib/scout/plugin_options.rb', line 73

def regular
  select{|o|!o.advanced? }
end

#to_hashObject



85
86
87
# File 'lib/scout/plugin_options.rb', line 85

def to_hash
  hash
end

#to_sObject



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