Class: Cinch::Configuration
- Inherits:
-
OpenStruct
- Object
- OpenStruct
- Cinch::Configuration
- Defined in:
- lib/cinch/configuration.rb,
lib/cinch/configuration/bot.rb,
lib/cinch/configuration/dcc.rb,
lib/cinch/configuration/ssl.rb,
lib/cinch/configuration/sasl.rb,
lib/cinch/configuration/storage.rb,
lib/cinch/configuration/plugins.rb,
lib/cinch/configuration/timeouts.rb
Overview
Defined Under Namespace
Classes: Bot, DCC, Plugins, SASL, SSL, Storage, Timeouts
Constant Summary
- KnownOptions =
[]
Class Method Summary (collapse)
-
+ (Hash) default_config
Generate a default configuration.
Instance Method Summary (collapse)
-
- (Object) [](key)
-
- (Object) []=(key, value)
-
- (Configuration) initialize(base = nil)
constructor
A new instance of Configuration.
-
- load(new_config, from_default = false)
Loads a configuration from a hash by merging the hash with either the current configuration or the default configuration.
-
- load!(new_config)
Like #load but always uses the default configuration.
-
- (Hash) to_h
Constructor Details
- (Configuration) initialize(base = nil)
A new instance of Configuration
13 14 15 16 |
# File 'lib/cinch/configuration.rb', line 13 def initialize(base = nil) base ||= self.class.default_config super(base) end |
Class Method Details
+ (Hash) default_config
Generate a default configuration.
9 10 11 |
# File 'lib/cinch/configuration.rb', line 9 def self.default_config {} end |
Instance Method Details
- (Object) [](key)
23 24 25 26 27 |
# 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 |
- (Object) []=(key, value)
29 30 31 32 33 |
# 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)
This method returns an undefined value.
Loads a configuration from a hash by merging the hash with either the current configuration or the default configuration.
44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 |
# 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)
This method returns an undefined value.
Like #load but always uses the default configuration
69 70 71 |
# File 'lib/cinch/configuration.rb', line 69 def load!(new_config) load(new_config, true) end |
- (Hash) to_h
19 20 21 |
# File 'lib/cinch/configuration.rb', line 19 def to_h @table.clone end |