Class Irc::Bot::Config::Value
In: lib/rbot/config.rb
Parent: Object
BasicUserMessage JoinMessage NamesMessage WhoisMessage ModeChangeMessage KickMessage MotdMessage QuitMessage BanlistMessage UserMessage NoSuchTargetMessage TopicMessage NickMessage WelcomeMessage UnknownMessage InviteMessage PartMessage NetmaskList UserList ArrayOf ChannelList Netmask User\n[lib/rbot/botuser.rb\nlib/rbot/irc.rb] Channel Singleton RfcCasemap StrictRfcCasemap AsciiCasemap Casemap PrivMessage NoticeMessage TokyoCabinet::BDB CIBDB Btree CIBtree Socket MessageQueue QueueRing Client DBHash\n[lib/rbot/registry/bdb.rb\nlib/rbot/registry/tc.rb] DBTree\n[lib/rbot/registry/bdb.rb\nlib/rbot/registry/tc.rb] Server NetmaskDb Bot\n[lib/rbot/botuser.rb\nlib/rbot/config.rb\nlib/rbot/ircbot.rb\nlib/rbot/language.rb\nlib/rbot/message.rb\nlib/rbot/messagemapper.rb\nlib/rbot/plugins.rb\nlib/rbot/rbotconfig.rb\nlib/rbot/registry/bdb.rb\nlib/rbot/registry/tc.rb] lib/rbot/ircsocket.rb lib/rbot/rfc2812.rb lib/rbot/registry/tc.rb lib/rbot/irc.rb lib/rbot/maskdb.rb lib/rbot/message.rb lib/rbot/messagemapper.rb lib/rbot/botuser.rb lib/rbot/registry/tc.rb (null) BotConfig PKGConfig ServerOrCasemap Irc dot/m_35_0.png

Methods

default   get   new   parse   set   set_string   to_s   unset   validate   value  

Attributes

auth_path  [R] 
desc  [R] 
key  [R] 
manager  [R] 
order  [R] 
requires_rescan  [R] 
requires_restart  [R] 
type  [R] 
wizard  [R] 

Public Class methods

[Source]

    # File lib/rbot/config.rb, line 32
32:     def initialize(key, params)
33:       @manager = Config.manager
34:       # Keys must be in the form 'module.name'.
35:       # They will be internally passed around as symbols,
36:       # but we accept them both in string and symbol form.
37:       unless key.to_s =~ /^.+\..+$/
38:         raise ArgumentError,"key must be of the form 'module.name'"
39:       end
40:       @order = @@order
41:       @@order += 1
42:       @key = key.to_sym
43:       if @manager.overrides.key?(@key)
44:         @default = @manager.overrides[@key]
45:       elsif params.has_key? :default
46:         @default = params[:default]
47:       else
48:         @default = false
49:       end
50:       @desc = params[:desc]
51:       @type = params[:type] || String
52:       @on_change = params[:on_change]
53:       @validate = params[:validate]
54:       @wizard = params[:wizard]
55:       @requires_restart = params[:requires_restart]
56:       @requires_rescan = params[:requires_rescan]
57:       @auth_path = "config::key::#{key.sub('.','::')}"
58:     end

Public Instance methods

[Source]

    # File lib/rbot/config.rb, line 59
59:     def default
60:       if @default.instance_of?(Proc)
61:         @default.call
62:       else
63:         @default
64:       end
65:     end

[Source]

    # File lib/rbot/config.rb, line 66
66:     def get
67:       return @manager.config[@key] if @manager.config.has_key?(@key)
68:       return default
69:     end

override this. the default will work for strings only

[Source]

    # File lib/rbot/config.rb, line 95
95:     def parse(string)
96:       string
97:     end

[Source]

    # File lib/rbot/config.rb, line 71
71:     def set(value, on_change = true)
72:       @manager.config[@key] = value
73:       @manager.changed = true
74:       @on_change.call(@manager.bot, value) if on_change && @on_change
75:       return self
76:     end

set string will raise ArgumentErrors on failed parse/validate

[Source]

    # File lib/rbot/config.rb, line 85
85:     def set_string(string, on_change = true)
86:       value = parse string
87:       if validate value
88:         set value, on_change
89:       else
90:         raise ArgumentError, "invalid value: #{string}"
91:       end
92:     end

[Source]

     # File lib/rbot/config.rb, line 99
 99:     def to_s
100:       get.to_s
101:     end

[Source]

    # File lib/rbot/config.rb, line 77
77:     def unset
78:       @manager.config.delete(@key)
79:       @manager.changed = true
80:       @on_change.call(@manager.bot, value) if @on_change
81:       return self
82:     end
value()

Alias for get

Protected Instance methods

[Source]

     # File lib/rbot/config.rb, line 104
104:     def validate(val, validator  = @validate)
105:       case validator
106:       when false, nil
107:         return true
108:       when Proc
109:         return validator.call(val)
110:       when Regexp
111:         raise ArgumentError, "validation via Regexp only supported for strings!" unless String === val
112:         return validator.match(val)
113:       else
114:         raise ArgumentError, "validation type #{validator.class} not supported"
115:       end
116:     end

[Validate]