lib/scout/plugin_options.rb in scout-5.3.2 vs lib/scout/plugin_options.rb in scout-5.3.3
- old
+ new
@@ -3,19 +3,20 @@
require 'yaml'
module Scout
# a data structure of an individual plugin option
class PluginOption
- attr_reader :name, :notes, :default, :advanced, :password, :required
+ attr_reader :name, :notes, :default, :advanced, :password, :required, :hash
def initialize(name, h)
@name=name
@notes=h['notes'] || ''
@default=h['default'] || ''
@attributes=h['attributes'] || ''
@advanced = @attributes.include?('advanced')
@password = @attributes.include?('password')
@required = @attributes.include?('required')
+ @hash = h
end
# convenience -- for nicer syntax
def advanced?; @advanced; end
def password?; @password; end
@@ -25,10 +26,14 @@
def to_s
required_string = required? ? " (required). " : ""
default_string = default == '' ? '' : " Default: #{default}. "
"'#{name}'#{required_string}#{default_string}#{notes}"
end
+
+ def to_hash
+ @hash
+ end
end
# A collection of pluginOption
# Create: opts=PluginOptions.from_yaml(yaml_string)
# Check if there were any problems -- opts.error -- should be nil.
@@ -41,11 +46,11 @@
# notes: If swap used over memory used is larger than this amount, an alert is generated
# default: 3
# attributes: required advanced
class PluginOptions < Array
- attr_accessor :error
+ attr_accessor :error, :hash
# Should be valid YAML, a hash of hashes ... if not, will be caught in the rescue below
def self.from_yaml(string)
options_array=[]
error=nil
@@ -55,10 +60,11 @@
rescue
error="Invalid Plugin Options"
ensure
res=PluginOptions.new(options_array)
res.error=error
+ res.hash = items unless res.error
return res
end
def advanced
select{|o|o.advanced? }
@@ -72,9 +78,13 @@
res=[]
each_with_index do |opt,i|
res.push "#{i+1}. #{opt.to_s}"
end
res.join("\n")
+ end
+
+ def to_hash
+ hash
end
end
end