diff options
author | John Keiser <jkeiser@opscode.com> | 2013-09-13 11:27:36 -0700 |
---|---|---|
committer | John Keiser <jkeiser@opscode.com> | 2013-09-13 11:27:36 -0700 |
commit | 1abcb1162a4330eb78b4599c99f355c6420da453 (patch) | |
tree | da891a28e17799001e4fe8dead933cfd24685bec | |
parent | 5fd3f8667f5792f522fb9096eb7fb50089372706 (diff) | |
download | mixlib-config-1abcb1162a4330eb78b4599c99f355c6420da453.tar.gz |
Inherit config_strict_mode in child contexts
-rw-r--r-- | lib/mixlib/config.rb | 17 | ||||
-rw-r--r-- | spec/mixlib/config_spec.rb | 4 |
2 files changed, 15 insertions, 6 deletions
diff --git a/lib/mixlib/config.rb b/lib/mixlib/config.rb index d17b60b..4a1a094 100644 --- a/lib/mixlib/config.rb +++ b/lib/mixlib/config.rb @@ -28,10 +28,10 @@ module Mixlib class << base; attr_accessor :configuration; end class << base; attr_accessor :configurables; end class << base; attr_accessor :config_contexts; end + class << base; attr_accessor :config_parent; end base.configuration = Hash.new base.configurables = Hash.new base.config_contexts = Array.new - base.config_strict_mode false end # Loads a given ruby file, and runs instance_eval against it in the context of the current @@ -208,6 +208,7 @@ module Mixlib def config_context(symbol, &block) context = Class.new context.extend(::Mixlib::Config) + context.config_parent = self config_contexts << context if block context.instance_eval(&block) @@ -238,7 +239,15 @@ module Mixlib # def config_strict_mode(value = NOT_PASSED) if value == NOT_PASSED - @config_strict_mode + if @config_strict_mode.nil? + if config_parent + config_parent.config_strict_mode + else + false + end + else + @config_strict_mode + end else self.config_strict_mode = value end @@ -258,8 +267,8 @@ module Mixlib # <ArgumentError>:: if value is set to something other than true, false, or :warn # def config_strict_mode=(value) - if ![ true, false, :warn ].include?(value) - raise ArgumentError, "config_strict_mode must be true, false or :warn" + if ![ true, false, :warn, nil ].include?(value) + raise ArgumentError, "config_strict_mode must be true, false, nil or :warn" end @config_strict_mode = value end diff --git a/spec/mixlib/config_spec.rb b/spec/mixlib/config_spec.rb index e515301..ec6ece5 100644 --- a/spec/mixlib/config_spec.rb +++ b/spec/mixlib/config_spec.rb @@ -492,8 +492,8 @@ describe Mixlib::Config do lambda { StrictClass3.y = 10 }.should raise_error(Mixlib::Config::UnknownConfigOptionError) end - it "The nested class allows you to set arbitrary config options" do - StrictClass3.c.y = 10 + it "The nested class does not allow you to set arbitrary config options" do + lambda { StrictClass3.y = 10 }.should raise_error(Mixlib::Config::UnknownConfigOptionError) end end end |