### Home Classes Methods

### In Files

- lib/rbot/config.rb

### Parent

Object

### Methods

- ::new
- #[]
- #[]=
- #bot_associate
- #method_missing
- #register
- #reset_config
- #save

### Included Modules

- Singleton

### 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::ManagerClass

container for bot configuration

### Attributes

bot[R]
changed[RW]
config[R]
items[R]
overrides[R]

### Public Class Methods

new() click to toggle source

    # File lib/rbot/config.rb, line 234
    def initialize
      bot_associate(nil,true)
    end

### Public Instance Methods

[](key) click to toggle source

currently we store values in a hash but this could be changed in the future. We use hash semantics, however. components that register their config keys and setup defaults are supported via []

    # File lib/rbot/config.rb, line 295
    def [](key)
      # return @items[key].value if @items.has_key?(key)
      return @items[key.to_sym].value if @items.has_key?(key.to_sym)
      # try to still support unregistered lookups
      # but warn about them
      #      if @config.has_key?(key)
      #        warning "Unregistered lookup #{key.inspect}"
      #        return @config[key]
      #      end
      if @config.has_key?(key.to_sym)
        warning _("Unregistered lookup #{key.to_sym.inspect}")
        return @config[key.to_sym]
      end
      return false
    end

[]=(key, value) click to toggle source

    # File lib/rbot/config.rb, line 311
    def []=(key, value)
      return @items[key.to_sym].set(value) if @items.has_key?(key.to_sym)
      if @config.has_key?(key.to_sym)
        warning _("Unregistered lookup #{key.to_sym.inspect}")
        return @config[key.to_sym] = value
      end
    end

bot_associate(bot, reset=false) click to toggle source

Associate with bot bot

    # File lib/rbot/config.rb, line 259
    def bot_associate(bot, reset=false)
      reset_config if reset
      @bot = bot
      return unless @bot

      @changed = false
      conf = @bot.path 'conf.yaml'
      if File.exist? conf
        begin
          newconfig = YAML::load_file conf
          newconfig.each { |key, val|
            @config[key.to_sym] = val
          }
          return
        rescue
          error "failed to read conf.yaml: #{$!}"
        end
      end
      # if we got here, we need to run the first-run wizard
      Wizard.new(@bot).run
      # save newly created config
      @changed = true
      save
    end

method_missing(method, *args, &block) click to toggle source

pass everything else through to the hash

    # File lib/rbot/config.rb, line 320
    def method_missing(method, *args, &block)
      return @config.send(method, *args, &block)
    end

register(item) click to toggle source

    # File lib/rbot/config.rb, line 284
    def register(item)
      unless item.kind_of?(Value)
        raise ArgumentError,"item must be an Irc::Bot::Config::Value"
      end
      @items[item.key] = item
    end

reset_config() click to toggle source

    # File lib/rbot/config.rb, line 238
    def reset_config
      @items = Hash.new
      @config = Hash.new(false)

      # We allow default values for config keys to be overridden by
      # the config file /etc/rbot.conf
      # The main purpose for this is to allow distro or system-wide
      # settings such as external program paths (figlet, toilet, ispell)
      # to be set once for all the bots.
      @overrides = Hash.new
      etcfile = "/etc/rbot.conf"
      if File.exist?(etcfile)
        log "Loading defaults from #{etcfile}"
        etcconf = YAML::load_file(etcfile)
        etcconf.each { |k, v|
          @overrides[k.to_sym] = v
        }
      end
    end

save() click to toggle source

write current configuration to #{botclass}/conf.yaml

    # File lib/rbot/config.rb, line 325
    def save
      if not @changed
        debug "Not writing conf.yaml (unchanged)"
        return
      end
      begin
        conf = @bot.path 'conf.yaml'
        fnew = conf + '.new'
        debug "Writing new conf.yaml ..."
        File.open(fnew, "w") do |file|
          savehash = {}
          @config.each { |key, val|
            savehash[key.to_s] = val
          }
          file.puts savehash.to_yaml
        end
        debug "Officializing conf.yaml ..."
        File.rename(fnew, conf)
        @changed = false
      rescue => e
        error "failed to write configuration file conf.yaml! #{$!}"
        error "#{e.class}: #{e}"
        error e.backtrace.join("\n")
      end
    end

[Validate]

Generated with the Darkfish Rdoc Generator 2.