Class: SettingsConfiguration
- Inherits:
-
Object
- Object
- SettingsConfiguration
- Defined in:
- lib/rsettings/core/internal/settings_configuration.rb
Instance Attribute Summary collapse
-
#missing ⇒ Object
readonly
Returns the value of attribute missing.
-
#names ⇒ Object
readonly
Returns the value of attribute names.
-
#settings ⇒ Object
readonly
Returns the value of attribute settings.
Instance Method Summary collapse
- #default(name, opts = {}) ⇒ Object
-
#initialize(&block) ⇒ SettingsConfiguration
constructor
A new instance of SettingsConfiguration.
- #inspect ⇒ Object
- #let(opts = {}) ⇒ Object
- #when_missing(type) ⇒ Object
- #with_settings(opts = {}) ⇒ Object
Constructor Details
#initialize(&block) ⇒ SettingsConfiguration
Returns a new instance of SettingsConfiguration.
4 5 6 7 8 9 10 11 12 13 14 15 |
# File 'lib/rsettings/core/internal/settings_configuration.rb', line 4 def initialize(&block) @names = Names.new @defaults = Defaults.new @names @settings = EnvironmentSettings.new instance_exec &block if block_given? @settings = SettingsChain.new(@settings).tap do |it| it.link @defaults if defaults? it.link tail end end |
Instance Attribute Details
#missing ⇒ Object (readonly)
Returns the value of attribute missing.
2 3 4 |
# File 'lib/rsettings/core/internal/settings_configuration.rb', line 2 def missing @missing end |
#names ⇒ Object (readonly)
Returns the value of attribute names.
2 3 4 |
# File 'lib/rsettings/core/internal/settings_configuration.rb', line 2 def names @names end |
#settings ⇒ Object (readonly)
Returns the value of attribute settings.
2 3 4 |
# File 'lib/rsettings/core/internal/settings_configuration.rb', line 2 def settings @settings end |
Instance Method Details
#default(name, opts = {}) ⇒ Object
25 26 27 28 |
# File 'lib/rsettings/core/internal/settings_configuration.rb', line 25 def default(name, opts = {}) fail "Expected the :to option so I can tell what the default value is" unless opts[:to] @defaults.add name, opts[:to] end |
#inspect ⇒ Object
17 18 19 |
# File 'lib/rsettings/core/internal/settings_configuration.rb', line 17 def inspect [@defaults.inspect, @names.inspect].join "\n" end |
#let(opts = {}) ⇒ Object
21 22 23 |
# File 'lib/rsettings/core/internal/settings_configuration.rb', line 21 def let(opts = {}) @names.add opts end |
#when_missing(type) ⇒ Object
30 31 32 |
# File 'lib/rsettings/core/internal/settings_configuration.rb', line 30 def when_missing(type) @tail = IgnoreMissing if type === :ignore end |
#with_settings(opts = {}) ⇒ Object
34 35 36 |
# File 'lib/rsettings/core/internal/settings_configuration.rb', line 34 def with_settings(opts={}) @settings = opts.is_a?(Hash) ? SettingsChain.new(opts[:chain].map{|it| it.new}) : opts.new end |