Class: Jabbot::Config

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

Overview

The main configuration of Jabbot. It’s nothing more than a simple struct of key-value pairs.

Examples:

Jabbot::Config.new({:login => "[email protected]", :password => "secret",
                    :debug => true})
# => #<struct Jabbot::Config login="[email protected]", password="secret",
     nick="jabbot", server=nil, channel=nil, resource="jabbot",
     log_level="info", log_file=nil, debug=true>

Jabbot::Config.new("[email protected]", "secret")
# => #<struct Jabbot::Config login="[email protected]", password="secret",
     nick="jabbot", server=nil, channel=nil, resource="jabbot",
     log_level="info", log_file=nil, debug=false>

config.
# => "[email protected]"
config.channel
# => nil
config.channel = "[email protected]"
# => "[email protected]"

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(*args) ⇒ Config

Public: Initialize new configuration object.

*args - Any number of valid arguments passed to the super class.

If there is only one argument and it is kind of a Hash,
it is treated as the key-value pairs are the options.
If there is a default value for an option key,
it is set if needed.


61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
# File 'lib/jabbot/config.rb', line 61

def initialize(*args)
  # First: call the super class.
  super

  # If we got a hash, treat it as the configuration options.
  if args.size == 1 && args.first.kind_of?(Hash)
    self. = nil # Reset first value.

    args.first.each do |key, value|
      send("#{key}=", value)
    end
  end

  # Set defaults.
  DEFAULT_CONFIG.each do |key, value|
    self.send(key.to_s) || self.send("#{key}=", value)
  end
end

Instance Attribute Details

#channelObject

Returns the value of attribute channel

Returns:

  • (Object)

    the current value of channel



41
42
43
# File 'lib/jabbot/config.rb', line 41

def channel
  @channel
end

#channel_passwordObject

Returns the value of attribute channel_password

Returns:

  • (Object)

    the current value of channel_password



41
42
43
# File 'lib/jabbot/config.rb', line 41

def channel_password
  @channel_password
end

#debugObject

Returns the value of attribute debug

Returns:

  • (Object)

    the current value of debug



41
42
43
# File 'lib/jabbot/config.rb', line 41

def debug
  @debug
end

#log_fileObject

Returns the value of attribute log_file

Returns:

  • (Object)

    the current value of log_file



41
42
43
# File 'lib/jabbot/config.rb', line 41

def log_file
  @log_file
end

#log_levelObject

Returns the value of attribute log_level

Returns:

  • (Object)

    the current value of log_level



41
42
43
# File 'lib/jabbot/config.rb', line 41

def log_level
  @log_level
end

#loginObject

Returns the value of attribute login

Returns:

  • (Object)

    the current value of login



41
42
43
# File 'lib/jabbot/config.rb', line 41

def 
  @login
end

#nickObject

Returns the value of attribute nick

Returns:

  • (Object)

    the current value of nick



41
42
43
# File 'lib/jabbot/config.rb', line 41

def nick
  @nick
end

#passwordObject

Returns the value of attribute password

Returns:

  • (Object)

    the current value of password



41
42
43
# File 'lib/jabbot/config.rb', line 41

def password
  @password
end

#resourceObject

Returns the value of attribute resource

Returns:

  • (Object)

    the current value of resource



41
42
43
# File 'lib/jabbot/config.rb', line 41

def resource
  @resource
end

#serverObject

Returns the value of attribute server

Returns:

  • (Object)

    the current value of server



41
42
43
# File 'lib/jabbot/config.rb', line 41

def server
  @server
end