Sha256: 7098ec1dda338982723da9b0bb7b8f20c3fd4326ec7b8dff4d701b146c294a49
Contents?: true
Size: 1.51 KB
Versions: 6
Compression:
Stored size: 1.51 KB
Contents
class IRC class ConfigError < StandardError; end Config = Struct.new(:nick, :ident, :realname, :servers) class ConfigDSL dsl_accessor :nick, :ident, :realname attr_accessor :servers def self.run(&block) confdsl = self.new block.arity < 1 ? confdsl.instance_eval(&block) : block.call(confdsl) raise ConfigError, 'no nick' unless confdsl.nick raise ConfigError, 'no servers' unless confdsl.servers conf = Config.new conf.nick = confdsl.nick conf.ident = confdsl.ident || confdsl.nick conf.realname = confdsl.realname || confdsl.nick conf.servers = confdsl.servers conf end def server(id, &block) @servers ||= {} @servers[id] = ServerConfigDSL.run(&block) @servers[id] end end ServerConfig = Struct.new(:address, :port, :nick, :ident, :realname, :ssl) class ServerConfigDSL dsl_accessor :address, :port, :nick, :ident, :realname bool_dsl_accessor :ssl def self.run(&block) confdsl = self.new block.arity < 1 ? confdsl.instance_eval(&block) : block.call(confdsl) raise ConfigError, 'no address' unless confdsl.address conf = ServerConfig.new conf.address = confdsl.address # If not supplied, the port defaults to 6667, or 6697 if ssl is used conf.port = confdsl.port || (confdsl.ssl? ? 6697 : 6667) conf.ssl = confdsl.ssl? conf.nick = confdsl.nick conf.ident = confdsl.ident conf.realname = confdsl.realname conf end end end
Version data entries
6 entries across 6 versions & 1 rubygems