diff options
author | Lamont Granquist <lamont@scriptkiddie.org> | 2018-07-02 11:23:18 -0700 |
---|---|---|
committer | GitHub <noreply@github.com> | 2018-07-02 11:23:18 -0700 |
commit | 8d3ff1b82cec32af20ad8a5ce3111235a8e6fa0d (patch) | |
tree | ae4bb6cf5d38a7711143788bea6629a9b277d2bb | |
parent | 8ca490b951b45fca98c5722839386ddd2f5f087c (diff) | |
parent | 2ce87e2e87916a8ed91f76730b4e98d976e5a784 (diff) | |
download | mixlib-config-8d3ff1b82cec32af20ad8a5ce3111235a8e6fa0d.tar.gz |
Merge pull request #63 from chef/lcg/add-key-method
add `#key?` alias to `#has_key?`
-rw-r--r-- | lib/mixlib/config.rb | 6 | ||||
-rw-r--r-- | spec/mixlib/config_spec.rb | 8 |
2 files changed, 11 insertions, 3 deletions
diff --git a/lib/mixlib/config.rb b/lib/mixlib/config.rb index 03486a8..ce4d185 100644 --- a/lib/mixlib/config.rb +++ b/lib/mixlib/config.rb @@ -2,7 +2,7 @@ # Author:: Adam Jacob (<adam@chef.io>) # Author:: Nuo Yan (<nuo@chef.io>) # Author:: Christopher Brown (<cb@chef.io>) -# Copyright:: Copyright (c) 2008-2016 Chef Software, Inc. +# Copyright:: Copyright (c) 2008-2018, Chef Software Inc. # License:: Apache License, Version 2.0 # # Licensed under the Apache License, Version 2.0 (the "License"); @@ -152,10 +152,12 @@ module Mixlib # === Returns # <True>:: If the config option exists # <False>:: If the config option does not exist - def has_key?(key) + def key?(key) configuration.has_key?(key.to_sym) end + alias_method :has_key?, :key? + # Resets a config option to its default. # # === Parameters diff --git a/spec/mixlib/config_spec.rb b/spec/mixlib/config_spec.rb index 1716dee..6bc31b0 100644 --- a/spec/mixlib/config_spec.rb +++ b/spec/mixlib/config_spec.rb @@ -1,6 +1,6 @@ # # Author:: Adam Jacob (<adam@chef.io>) -# Copyright:: Copyright (c) 2008-2016 Chef Software, Inc. +# Copyright:: Copyright (c) 2008-2018, Chef Software Inc. # License:: Apache License, Version 2.0 # # Licensed under the Apache License, Version 2.0 (the "License"); @@ -162,6 +162,12 @@ describe Mixlib::Config do expect(ConfigIt.has_key?(:monkey)).to be true end + it "returns true or false with key?" do + expect(ConfigIt.key?(:monkey2)).to be false + ConfigIt[:monkey2] = "gotcha" + expect(ConfigIt.key?(:monkey2)).to be true + end + describe "when a class method override writer exists" do before do @klass = Class.new |