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 9 def self.default_config {} end
new(base = nil)
click to toggle source
Calls superclass method
# File lib/cinch/configuration.rb, line 13 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 23 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 29 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 44 def load(new_config, from_default = false) if from_default @table = self.class.default_config end 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 69 def load!(new_config) load(new_config, true) end
to_h()
click to toggle source
@return [Hash]
# File lib/cinch/configuration.rb, line 19 def to_h @table.clone end