### Home Classes Methods

### In Files

- lib/rbot/config.rb

### Parent

Object

### Methods

- ::new
- #default
- #get
- #parse
- #set
- #set_string
- #to_s
- #unset
- #validate
- #value

### Class/Module Index

Quicksearch

- Irc
- Irc::AsciiCasemap
- Irc::BanlistMessage
- Irc::BasicUserMessage
- Irc::Bot
- Irc::Bot::Auth
- Irc::Bot::Auth::BotOwnerClass
- Irc::Bot::Auth::BotUser
- Irc::Bot::Auth::Command
- Irc::Bot::Auth::DefaultBotUserClass
- Irc::Bot::Auth::InvalidPassword
- Irc::Bot::Auth::ManagerClass
- Irc::Bot::Auth::PermissionSet
- Irc::Bot::Config
- Irc::Bot::Config::ArrayValue
- Irc::Bot::Config::BooleanValue
- Irc::Bot::Config::EnumValue
- Irc::Bot::Config::FloatValue
- Irc::Bot::Config::IntegerValue
- Irc::Bot::Config::ManagerClass
- Irc::Bot::Config::StringValue
- Irc::Bot::Config::Value
- Irc::Bot::Config::Wizard
- Irc::Bot::DataFilter
- Irc::Bot::DataStream
- Irc::Bot::Language
- Irc::Bot::MessageMapper
- Irc::Bot::MessageMapper::Failure
- Irc::Bot::MessageMapper::FriendlyFailure
- Irc::Bot::MessageMapper::NoActionFailure
- Irc::Bot::MessageMapper::NoMatchFailure
- Irc::Bot::MessageMapper::NotPrivateFailure
- Irc::Bot::MessageMapper::NotPublicFailure
- Irc::Bot::MessageMapper::PartialMatchFailure
- Irc::Bot::MessageParameter
- Irc::Bot::MessageTemplate
- Irc::Bot::Plugins
- Irc::Bot::Plugins::BotModule
- Irc::Bot::Plugins::CoreBotModule
- Irc::Bot::Plugins::Plugin
- Irc::Bot::Plugins::PluginManagerClass
- Irc::Bot::Plugins::RecurseTooDeep
- Irc::Bot::Plugins::RemoteBotModule
- Irc::Bot::Plugins::RemoteCoreBotModule
- Irc::Bot::Plugins::RemotePlugin
- Irc::Bot::Registry
- Irc::Bot::Registry::Accessor
- Irc::Bot::RemoteDispatcher
- Irc::Bot::RemoteMessage
- Irc::Bot::RemoteObject
- Irc::Bot::Wordlist
- Irc::BotConfig
- Irc::Casemap
- Irc::Channel
- Irc::Channel::Mode
- Irc::Channel::ModeHash
- Irc::Channel::ModeTypeA
- Irc::Channel::ModeTypeB
- Irc::Channel::ModeTypeC
- Irc::Channel::ModeTypeD
- Irc::Channel::Topic
- Irc::Channel::UserMode
- Irc::ChannelList
- Irc::Client
- Irc::DBHash
- Irc::DBTree
- Irc::InviteMessage
- Irc::JoinMessage
- Irc::KickMessage
- Irc::MessageQueue
- Irc::ModeChangeMessage
- Irc::MotdMessage
- Irc::NamesMessage
- Irc::Netmask
- Irc::NetmaskDb
- Irc::NetmaskDb::Tree
- Irc::NetmaskList
- Irc::NickMessage
- Irc::NoSuchTargetMessage
- Irc::NoticeMessage
- Irc::PartMessage
- Irc::PrivMessage
- Irc::QueueRing
- Irc::QuitMessage
- Irc::RfcCasemap
- Irc::Server
- Irc::ServerOrCasemap
- Irc::Socket
- Irc::Socket::IdentityFilter
- Irc::StrictRfcCasemap
- Irc::TopicMessage
- Irc::UnknownMessage
- Irc::User
- Irc::UserList
- Irc::UserMessage
- Irc::Utils
- Irc::Utils::HttpUtil
- Irc::Utils::HttpUtil::CachedObject
- Irc::Utils::ParseTime
- Irc::WelcomeMessage
- Irc::WhoisMessage
- BDB
- BDB::CIBtree
- MonitorMixin
- MonitorMixin::ConditionVariable
- Net
- Net::HTTPResponse
- Regexp
- Regexp::Irc
- Singleton
- Singleton::SingletonClassMethods
- Timer
- Timer::Action
- TokyoCabinet
- TokyoCabinet::CIBDB
- UnicodePlugin
- UnicodePlugin::UnicodeFilter
- Array
- ArrayOf
- AuthModule
- BasicsModule
- ConditionVariable
- ConfigModule
- DottedIndex
- Enumerable
- Exception
- FiltersModule
- GetText
- GetTextVersionError
- HttpUtilPlugin
- IrcLogModule
- Module
- Numeric
- Object
- Range
- RemoteModule
- ServerError
- String
- Symbol
- UserDataModule
- WordlistModule
- YAML

No matching classes.

# Irc::Bot::Config::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

new(key, params) click to toggle source

    # File lib/rbot/config.rb, line 32
    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]
      @requires_restart = params[:requires_restart]
      @requires_rescan = params[:requires_rescan]
      @auth_path = "config::key::#{key.sub('.','::')}"
    end

### Public Instance Methods

default() click to toggle source

    # File lib/rbot/config.rb, line 59
    def default
      if @default.instance_of?(Proc)
        @default.call
      else
        @default
      end
    end

get() click to toggle source

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

Also aliased as: value
parse(string) click to toggle source

override this. the default will work for strings only

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

set(value, on_change = true) click to toggle source

    # File lib/rbot/config.rb, line 71
    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

set_string(string, on_change = true) click to toggle source

set string will raise ArgumentErrors on failed parse/validate

    # File lib/rbot/config.rb, line 85
    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

to_s() click to toggle source

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

unset() click to toggle source

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

value() click to toggle source
Alias for: get

### Protected Instance Methods

validate(val, validator = @validate) click to toggle source

    # File lib/rbot/config.rb, line 104
    def validate(val, validator  = @validate)
      case validator
      when false, nil
        return true
      when Proc
        return validator.call(val)
      when Regexp
        raise ArgumentError, "validation via Regexp only supported for strings!" unless String === val
        return validator.match(val)
      else
        raise ArgumentError, "validation type #{validator.class} not supported"
      end
    end

[Validate]

Generated with the Darkfish Rdoc Generator 2.