class Cinch::Configuration

@since 2.0.0

Constants

KnownOptions

Public Class Methods

default_config() click to toggle source

Generate a default configuration.

@return [Hash]

# File lib/cinch/configuration.rb, line 11
def self.default_config
  {}
end
new(base = nil) click to toggle source
Calls superclass method
# File lib/cinch/configuration.rb, line 15
def initialize(base = nil)
  base ||= self.class.default_config
  super(base)
end

Public Instance Methods

[](key) click to toggle source
# File lib/cinch/configuration.rb, line 25
def [](key)
  # FIXME: also adjust method_missing
  raise ArgumentError, "Unknown option #{key}" unless self.class::KnownOptions.include?(key)

  @table[key]
end
[]=(key, value) click to toggle source
# File lib/cinch/configuration.rb, line 32
def []=(key, value)
  # FIXME: also adjust method_missing
  raise ArgumentError, "Unknown option #{key}" unless self.class::KnownOptions.include?(key)

  modifiable[new_ostruct_member(key)] = value
end
load(new_config, from_default = false) click to toggle source

Loads a configuration from a hash by merging the hash with either the current configuration or the default configuration.

@param [Hash] new_config The configuration to load @param [Boolean] from_default If true, the configuration won't

be merged with the currently set up configuration (by prior
calls to {#load} or {Bot#configure}) but with the default
configuration.

@return [void]

# File lib/cinch/configuration.rb, line 48
def load(new_config, from_default = false)
  @table = self.class.default_config if from_default

  new_config.each do |option, value|
    if value.is_a?(Hash)
      if self[option].is_a?(Configuration)
        self[option].load(value)
      else
        # recursive merging is handled by subclasses like
        # Configuration::Plugins
        self[option] = value
      end
    else
      self[option] = value
    end
  end
end
load!(new_config) click to toggle source

Like {#load} but always uses the default configuration

@param [Hash] new_config (see load_config) @return [void] @see load

# File lib/cinch/configuration.rb, line 71
def load!(new_config)
  load(new_config, true)
end
to_h() click to toggle source

@return [Hash]

# File lib/cinch/configuration.rb, line 21
def to_h
  @table.clone
end