Module: Settingable::Settings
- Extended by:
- Forwardable
- Defined in:
- lib/settingable/settings.rb
Overview
A module containing the settings configuration.
Defined Under Namespace
Modules: ClassMethods
Class Method Summary collapse
Instance Method Summary collapse
-
#[](key) ⇒ Object
Retrieves a key.
-
#[]=(key, value) ⇒ void
Sets a key to a value.
-
#build { ... } ⇒ self
Builds the settings construct.
-
#initialize(settings = {}) ⇒ Object
Initialize the settings.
-
#method_missing(method, *args, &block) ⇒ Object
Method missing.
Dynamic Method Handling
This class handles dynamic methods through the method_missing method
#method_missing(method, *args, &block) ⇒ Object
Method missing. For set methods, it maps to the :[]= method; for
regular methods (i.e. not bang or ? methods), it maps to the :[]
method.
89 90 91 92 |
# File 'lib/settingable/settings.rb', line 89 def method_missing(method, *args, &block) return super if args.length > 1 || block_given? || method =~ /(\?|\!)\z/ map_method(method, args) end |
Class Method Details
.included(base) ⇒ Object
42 43 44 |
# File 'lib/settingable/settings.rb', line 42 def self.included(base) base.extend ClassMethods end |
Instance Method Details
#[](key) ⇒ Object
Retrieves a key. If it doesn't exist, it errors.
80 81 82 |
# File 'lib/settingable/settings.rb', line 80 def [](key) @settings.fetch(key.to_s.to_sym) end |
#[]=(key, value) ⇒ void
This method returns an undefined value.
Sets a key to a value.
72 73 74 |
# File 'lib/settingable/settings.rb', line 72 def []=(key, value) @settings[key.to_s.to_sym] = value end |
#build { ... } ⇒ self
Builds the settings construct. It yields itself, and then returns itself.
62 63 64 65 |
# File 'lib/settingable/settings.rb', line 62 def build yield self self end |
#initialize(settings = {}) ⇒ Object
Initialize the settings. Merges the given settings to the default settings.
53 54 55 |
# File 'lib/settingable/settings.rb', line 53 def initialize(settings = {}) @settings = self.class.default_settings.merge(settings) end |