Class: IRC::ConfigDSL

Inherits:
Object
  • Object
show all
Defined in:
lib/on_irc/config.rb

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Instance Attribute Details

#serversObject

Returns the value of attribute servers.



8
9
10
# File 'lib/on_irc/config.rb', line 8

def servers
  @servers
end

Class Method Details

.run(&block) ⇒ Object

Raises:



10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
# File 'lib/on_irc/config.rb', line 10

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

Instance Method Details

#server(id, &block) ⇒ Object



27
28
29
30
31
# File 'lib/on_irc/config.rb', line 27

def server(id, &block)
  @servers ||= {}
  @servers[id] = ServerConfigDSL.run(&block)
  @servers[id]
end