Class: Irc::Bot::Config::Value
- Inherits:
-
Object
- Object
- Irc::Bot::Config::Value
- Defined in:
- /home/apoc/projects/ruby/rbot/lib/rbot/config.rb
Direct Known Subclasses
ArrayValue, BooleanValue, EnumValue, FloatValue, IntegerValue, StringValue
Constant Summary
- @@order =
allow the definition order to be preserved so that sorting by definition order is possible. The Wizard does this to allow the :wizard questions to be in a sensible order.
0
Instance Attribute Summary (collapse)
-
- (Object) auth_path
readonly
Returns the value of attribute auth_path.
-
- (Object) desc
readonly
Returns the value of attribute desc.
-
- (Object) key
readonly
Returns the value of attribute key.
-
- (Object) manager
readonly
Returns the value of attribute manager.
-
- (Object) order
readonly
Returns the value of attribute order.
-
- (Object) requires_rescan
readonly
Returns the value of attribute requires_rescan.
-
- (Object) requires_restart
readonly
Returns the value of attribute requires_restart.
-
- (Object) store_default
readonly
Returns the value of attribute store_default.
-
- (Object) type
readonly
Returns the value of attribute type.
-
- (Object) wizard
readonly
Returns the value of attribute wizard.
Instance Method Summary (collapse)
- - (Object) default
- - (Object) get (also: #value)
-
- (Value) initialize(key, params)
constructor
A new instance of Value.
-
- (Object) parse(string)
override this.
- - (Object) set(value, on_change = true)
-
- (Object) set_string(string, on_change = true)
set string will raise ArgumentErrors on failed parse/validate.
- - (Object) to_s
- - (Object) unset
Constructor Details
- (Value) initialize(key, params)
Returns a new instance of Value
33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 |
# File '/home/apoc/projects/ruby/rbot/lib/rbot/config.rb', line 33 def initialize(key, params) @manager = Config.manager # Keys must be in the form 'module.name'. # They will be internally passed around as symbols, # but we accept them both in string and symbol form. unless key.to_s =~ /^.+\..+$/ raise ArgumentError,"key must be of the form 'module.name'" end @order = @@order @@order += 1 @key = key.to_sym if @manager.overrides.key?(@key) @default = @manager.overrides[@key] elsif params.has_key? :default @default = params[:default] else @default = false end @desc = params[:desc] @type = params[:type] || String @on_change = params[:on_change] @validate = params[:validate] @wizard = params[:wizard] @store_default = params[:store_default] @requires_restart = params[:requires_restart] @requires_rescan = params[:requires_rescan] @auth_path = "config::key::#{key.sub('.','::')}" end |
Instance Attribute Details
- (Object) auth_path (readonly)
Returns the value of attribute auth_path
32 33 34 |
# File '/home/apoc/projects/ruby/rbot/lib/rbot/config.rb', line 32 def auth_path @auth_path end |
- (Object) desc (readonly)
Returns the value of attribute desc
24 25 26 |
# File '/home/apoc/projects/ruby/rbot/lib/rbot/config.rb', line 24 def desc @desc end |
- (Object) key (readonly)
Returns the value of attribute key
25 26 27 |
# File '/home/apoc/projects/ruby/rbot/lib/rbot/config.rb', line 25 def key @key end |
- (Object) manager (readonly)
Returns the value of attribute manager
31 32 33 |
# File '/home/apoc/projects/ruby/rbot/lib/rbot/config.rb', line 31 def manager @manager end |
- (Object) order (readonly)
Returns the value of attribute order
30 31 32 |
# File '/home/apoc/projects/ruby/rbot/lib/rbot/config.rb', line 30 def order @order end |
- (Object) requires_rescan (readonly)
Returns the value of attribute requires_rescan
29 30 31 |
# File '/home/apoc/projects/ruby/rbot/lib/rbot/config.rb', line 29 def requires_rescan @requires_rescan end |
- (Object) requires_restart (readonly)
Returns the value of attribute requires_restart
28 29 30 |
# File '/home/apoc/projects/ruby/rbot/lib/rbot/config.rb', line 28 def requires_restart @requires_restart end |
- (Object) store_default (readonly)
Returns the value of attribute store_default
27 28 29 |
# File '/home/apoc/projects/ruby/rbot/lib/rbot/config.rb', line 27 def store_default @store_default end |
- (Object) type (readonly)
Returns the value of attribute type
23 24 25 |
# File '/home/apoc/projects/ruby/rbot/lib/rbot/config.rb', line 23 def type @type end |
- (Object) wizard (readonly)
Returns the value of attribute wizard
26 27 28 |
# File '/home/apoc/projects/ruby/rbot/lib/rbot/config.rb', line 26 def wizard @wizard end |
Instance Method Details
- (Object) default
61 62 63 64 65 66 67 |
# File '/home/apoc/projects/ruby/rbot/lib/rbot/config.rb', line 61 def default if @default.instance_of?(Proc) @default.call else @default end end |
- (Object) get Also known as: value
68 69 70 71 |
# File '/home/apoc/projects/ruby/rbot/lib/rbot/config.rb', line 68 def get return @manager.config[@key] if @manager.config.has_key?(@key) return default end |
- (Object) parse(string)
override this. the default will work for strings only
97 98 99 |
# File '/home/apoc/projects/ruby/rbot/lib/rbot/config.rb', line 97 def parse(string) string end |
- (Object) set(value, on_change = true)
73 74 75 76 77 78 |
# File '/home/apoc/projects/ruby/rbot/lib/rbot/config.rb', line 73 def set(value, on_change = true) @manager.config[@key] = value @manager.changed = true @on_change.call(@manager.bot, value) if on_change && @on_change return self end |
- (Object) set_string(string, on_change = true)
set string will raise ArgumentErrors on failed parse/validate
87 88 89 90 91 92 93 94 |
# File '/home/apoc/projects/ruby/rbot/lib/rbot/config.rb', line 87 def set_string(string, on_change = true) value = parse string if validate value set value, on_change else raise ArgumentError, "invalid value: #{string}" end end |
- (Object) to_s
101 102 103 |
# File '/home/apoc/projects/ruby/rbot/lib/rbot/config.rb', line 101 def to_s get.to_s end |
- (Object) unset
79 80 81 82 83 84 |
# File '/home/apoc/projects/ruby/rbot/lib/rbot/config.rb', line 79 def unset @manager.config.delete(@key) @manager.changed = true @on_change.call(@manager.bot, value) if @on_change return self end |