Hello community,
here is the log from the commit of package rubygem-mixlib-config for
openSUSE:Factory checked in at 2018-07-18 22:54:16
++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
Comparing /work/SRC/openSUSE:Factory/rubygem-mixlib-config (Old)
and /work/SRC/openSUSE:Factory/.rubygem-mixlib-config.new (New)
++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
Package is "rubygem-mixlib-config"
Wed Jul 18 22:54:16 2018 rev:10 rq:622574 version:2.2.13
Changes:
--------
---
/work/SRC/openSUSE:Factory/rubygem-mixlib-config/rubygem-mixlib-config.changes
2018-02-12 10:16:04.343651390 +0100
+++
/work/SRC/openSUSE:Factory/.rubygem-mixlib-config.new/rubygem-mixlib-config.changes
2018-07-18 22:55:00.614747937 +0200
@@ -1,0 +2,42 @@
+Thu Jul 12 06:14:41 UTC 2018 - [email protected]
+
+- updated to version 2.2.13
+ no changelog found
+
+-------------------------------------------------------------------
+Thu Jul 12 03:14:21 UTC 2018 - [email protected]
+
+- updated to version 2.2.13
+ no changelog found
+
+-------------------------------------------------------------------
+Fri Jul 6 01:06:57 UTC 2018 - [email protected]
+
+- updated to version 2.2.12
+ no changelog found
+
+-------------------------------------------------------------------
+Tue Jul 3 23:05:28 UTC 2018 - [email protected]
+
+- updated to version 2.2.11
+ no changelog found
+
+-------------------------------------------------------------------
+Mon Jul 2 19:06:32 UTC 2018 - [email protected]
+
+- updated to version 2.2.10
+ no changelog found
+
+-------------------------------------------------------------------
+Wed Jun 13 12:07:29 UTC 2018 - [email protected]
+
+- updated to version 2.2.8
+ no changelog found
+
+-------------------------------------------------------------------
+Fri Mar 23 05:30:07 UTC 2018 - [email protected]
+
+- updated to version 2.2.6
+ no changelog found
+
+-------------------------------------------------------------------
Old:
----
mixlib-config-2.2.5.gem
New:
----
mixlib-config-2.2.13.gem
++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
Other differences:
------------------
++++++ rubygem-mixlib-config.spec ++++++
--- /var/tmp/diff_new_pack.1H0pXN/_old 2018-07-18 22:55:02.086743056 +0200
+++ /var/tmp/diff_new_pack.1H0pXN/_new 2018-07-18 22:55:02.090743043 +0200
@@ -24,7 +24,7 @@
#
Name: rubygem-mixlib-config
-Version: 2.2.5
+Version: 2.2.13
Release: 0
%define mod_name mixlib-config
%define mod_full_name %{mod_name}-%{version}
++++++ mixlib-config-2.2.5.gem -> mixlib-config-2.2.13.gem ++++++
diff -urN '--exclude=CVS' '--exclude=.cvsignore' '--exclude=.svn'
'--exclude=.svnignore' old/README.md new/README.md
--- old/README.md 2018-02-09 19:25:02.000000000 +0100
+++ new/README.md 2018-07-11 23:14:00.000000000 +0200
@@ -43,11 +43,12 @@
MyConfig[:first_value] = 'foobar' # sets first_value to 'foobar'
```
-If you prefer to allow your users to pass in configuration via YAML or JSON
files, `mixlib-config` supports that too!
+If you prefer to allow your users to pass in configuration via YAML, JSON or
TOML files, `mixlib-config` supports that too!
```ruby
MyConfig.from_file('~/.myconfig.yml')
MyConfig.from_file('~/.myconfig.json')
+ MyConfig.from_file('~/.myconfig.toml')
```
This way, a user could write a YAML config file that looked like this:
@@ -67,6 +68,13 @@
}
```
+or a TOML file that looks like this:
+
+```toml
+first_value = "hi"
+second_value = "goodbye"
+```
+
Please note: There is an inherent limitation in the logic you can do with YAML
and JSON file. At this time, `mixlib-config` does not support ERB or other
logic in YAML or JSON config (read "static content only").
## Nested Configuration
@@ -240,6 +248,18 @@
print_network_requests false
```
+You can also inspect if the values are still their defaults or not:
+
+```ruby
+MyConfig.is_default?(:verbosity) # == true
+MyConfig[:verbosity] = 5
+MyConfig.is_default?(:verbosity) # == false
+MyConfig[:verbosity] = 1
+MyConfig.is_default?(:verbosity) # == true
+```
+
+Trying to call `is_default?` on a config context or a config which does not
have a declared default is an error and will raise.
+
## Strict Mode
Misspellings are a common configuration problem, and Mixlib::Config has an
answer: `config_strict_mode`. Setting `config_strict_mode` to `true` will cause
any misspelled or incorrect configuration option references to throw
`Mixlib::Config::UnknownConfigOptionError`.
@@ -294,4 +314,3 @@
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
-
diff -urN '--exclude=CVS' '--exclude=.cvsignore' '--exclude=.svn'
'--exclude=.svnignore' old/Rakefile new/Rakefile
--- old/Rakefile 2018-02-09 19:25:02.000000000 +0100
+++ new/Rakefile 2018-07-11 23:14:00.000000000 +0200
@@ -14,8 +14,6 @@
spec.pattern = "spec/**/*_spec.rb"
end
-gem_spec = eval(File.read("mixlib-config.gemspec"))
-
begin
require "chefstyle"
require "rubocop/rake_task"
@@ -28,7 +26,7 @@
RDoc::Task.new do |rdoc|
rdoc.rdoc_dir = "rdoc"
- rdoc.title = "mixlib-config #{gem_spec.version}"
+ rdoc.title = "mixlib-config #{Mixlib::Config::VERSION}"
rdoc.rdoc_files.include("README*")
rdoc.rdoc_files.include("lib/**/*.rb")
end
Binary files old/checksums.yaml.gz and new/checksums.yaml.gz differ
diff -urN '--exclude=CVS' '--exclude=.cvsignore' '--exclude=.svn'
'--exclude=.svnignore' old/lib/mixlib/config/configurable.rb
new/lib/mixlib/config/configurable.rb
--- old/lib/mixlib/config/configurable.rb 2018-02-09 19:25:02.000000000
+0100
+++ new/lib/mixlib/config/configurable.rb 2018-07-11 23:14:00.000000000
+0200
@@ -1,6 +1,6 @@
#
# Author:: John Keiser (<[email protected]>)
-# Copyright:: Copyright (c) 2013-2016 Chef Software, Inc.
+# Copyright:: Copyright (c) 2013-2018, Chef Software Inc.
# License:: Apache License, Version 2.0
#
# Licensed under the Apache License, Version 2.0 (the "License");
@@ -19,20 +19,31 @@
module Mixlib
module Config
class Configurable
+ attr_reader :symbol
+ attr_reader :default_value
+ attr_reader :default_block
+
def initialize(symbol)
@symbol = symbol
- @default_block = nil
- @has_default = false
- @default_value = nil
- @writes_value = nil
end
- attr_reader :has_default
+ def has_default?
+ instance_variable_defined?(:@default_value)
+ end
+
+ def writes_value?
+ instance_variable_defined?(:@writes_value)
+ end
+
+ def default_block?
+ instance_variable_defined?(:@default_block)
+ end
+
+ alias_method :has_default, :has_default?
def defaults_to(default_value = nil, &block)
- @has_default = true
- @default_block = block
@default_value = default_value
+ @default_block = block if block_given?
self
end
@@ -42,32 +53,38 @@
end
def get(config)
- if config.has_key?(@symbol)
- config[@symbol]
- elsif @default_block
- @default_block.call
+ if config.key?(symbol)
+ config[symbol]
+ elsif default_block?
+ default_block.call
else
- begin
- # Some things cannot be dup'd, and you won't know this till after
the fact
- # because all values implement dup
- config[@symbol] = @default_value.dup
- rescue TypeError
- @default_value
- end
+ config[symbol] = safe_dup(default_value)
end
end
def set(config, value)
- config[@symbol] = @writes_value ? @writes_value.call(value) : value
+ config[symbol] = writes_value? ? @writes_value.call(value) : value
end
def default
- if @default_block
- @default_block.call
+ if default_block?
+ default_block.call
else
- @default_value
+ default_value
end
end
+
+ def is_default?(config)
+ !config.key?(symbol) || config[symbol] == default_value
+ end
+
+ private
+
+ def safe_dup(e)
+ e.dup
+ rescue TypeError
+ e
+ end
end
end
end
diff -urN '--exclude=CVS' '--exclude=.cvsignore' '--exclude=.svn'
'--exclude=.svnignore' old/lib/mixlib/config/version.rb
new/lib/mixlib/config/version.rb
--- old/lib/mixlib/config/version.rb 2018-02-09 19:25:02.000000000 +0100
+++ new/lib/mixlib/config/version.rb 2018-07-11 23:14:00.000000000 +0200
@@ -1,6 +1,6 @@
#
# Author:: Daniel DeLeo (<[email protected]>)
-# Copyright:: Copyright (c) 2013-2016 Chef Software, Inc.
+# Copyright:: Copyright (c) 2013-2018, Chef Software Inc.
# License:: Apache License, Version 2.0
#
# Licensed under the Apache License, Version 2.0 (the "License");
@@ -19,7 +19,7 @@
module Mixlib
module Config
- VERSION = "2.2.5"
+ VERSION = "2.2.13"
end
end
diff -urN '--exclude=CVS' '--exclude=.cvsignore' '--exclude=.svn'
'--exclude=.svnignore' old/lib/mixlib/config.rb new/lib/mixlib/config.rb
--- old/lib/mixlib/config.rb 2018-02-09 19:25:02.000000000 +0100
+++ new/lib/mixlib/config.rb 2018-07-11 23:14:00.000000000 +0200
@@ -2,7 +2,7 @@
# Author:: Adam Jacob (<[email protected]>)
# Author:: Nuo Yan (<[email protected]>)
# Author:: Christopher Brown (<[email protected]>)
-# 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");
@@ -57,6 +57,8 @@
from_yaml(filename)
elsif File.extname(filename) == ".json"
from_json(filename)
+ elsif File.extname(filename) == ".toml"
+ from_toml(filename)
else
instance_eval(IO.read(filename), filename, 1)
end
@@ -68,7 +70,7 @@
# filename<String>:: A filename to read from
def from_yaml(filename)
require "yaml"
- from_hash(YAML.load(IO.read(filename)), filename)
+ from_hash(YAML.load(IO.read(filename)))
end
# Parses valid JSON structure into Ruby
@@ -77,27 +79,20 @@
# filename<String>:: A filename to read from
def from_json(filename)
require "json"
- from_hash(JSON.parse(IO.read(filename)), filename)
+ from_hash(JSON.parse(IO.read(filename)))
+ end
+
+ def from_toml(filename)
+ require "tomlrb"
+ from_hash(Tomlrb.parse(IO.read(filename), symbolize_keys: true))
end
# Transforms a Hash into method-style configuration syntax to be processed
#
# === Parameters
# hash<Hash>:: A Hash containing configuration
- def from_hash(hash, filename = "in_memory")
- ruby_translation = []
-
- to_dotted_hash(hash).each do |k, v|
- if v.is_a? Array
- ruby_translation << "#{k} #{v}"
- elsif v.is_a? String
- ruby_translation << "#{k} \"#{v}\""
- else
- ruby_translation << "#{k} #{v}"
- end
- end
-
- instance_eval(ruby_translation.join("\n"), filename, 1)
+ def from_hash(hash)
+ apply_nested_hash(hash)
end
# Pass Mixlib::Config.configure() a block, and it will yield itself
@@ -145,8 +140,19 @@
# === Returns
# <True>:: If the config option exists
# <False>:: If the config option does not exist
- def has_key?(key)
- configuration.has_key?(key.to_sym)
+ def key?(key)
+ configuration.has_key?(key.to_sym) ||
config_contexts.has_key?(key.to_sym)
+ end
+
+ alias_method :has_key?, :key?
+
+ def is_default?(key)
+ symbol = key.to_sym
+ if configurables.has_key?(symbol)
+ configurables[symbol].is_default?(configuration)
+ else
+ raise ArgumentError, "config option must exist, and not be a context
to check for default values"
+ end
end
# Resets a config option to its default.
@@ -429,7 +435,7 @@
# block<Block>: a block that will be run in the context of this new config
# class.
def config_context_list(plural_symbol, singular_symbol, &block)
- if configurables.has_key?(symbol)
+ if configurables.has_key?(plural_symbol)
raise ReopenedConfigurableWithConfigContextError, "Cannot redefine
config value #{plural_symbol} with a config context"
end
@@ -461,7 +467,7 @@
# block<Block>: a block that will be run in the context of this new config
# class.
def config_context_hash(plural_symbol, singular_symbol, &block)
- if configurables.has_key?(symbol)
+ if configurables.has_key?(plural_symbol)
raise ReopenedConfigurableWithConfigContextError, "Cannot redefine
config value #{plural_symbol} with a config context"
end
@@ -549,6 +555,25 @@
internal_get_or_set(method_symbol, *args)
end
+ protected
+
+ # Given a (nested) Hash, apply it to the config object and any contexts.
+ #
+ # This is preferable to converting it to the string representation with
+ # the #to_dotted_hash method above.
+ #
+ # === Parameters
+ # hash<Hash>:: The hash to apply to the config oject
+ def apply_nested_hash(hash)
+ hash.each do |k, v|
+ if v.is_a? Hash
+ internal_get(k.to_sym).apply_nested_hash(v)
+ else
+ internal_set(k.to_sym, v)
+ end
+ end
+ end
+
private
# Given a (nested) Hash, turn it into a single top-level hash using dots as
diff -urN '--exclude=CVS' '--exclude=.cvsignore' '--exclude=.svn'
'--exclude=.svnignore' old/metadata new/metadata
--- old/metadata 2018-02-09 19:25:02.000000000 +0100
+++ new/metadata 2018-07-11 23:14:00.000000000 +0200
@@ -1,16 +1,30 @@
--- !ruby/object:Gem::Specification
name: mixlib-config
version: !ruby/object:Gem::Version
- version: 2.2.5
+ version: 2.2.13
platform: ruby
authors:
- Chef Software, Inc.
autorequire:
bindir: bin
cert_chain: []
-date: 2018-02-09 00:00:00.000000000 Z
+date: 2018-07-11 00:00:00.000000000 Z
dependencies:
- !ruby/object:Gem::Dependency
+ name: tomlrb
+ requirement: !ruby/object:Gem::Requirement
+ requirements:
+ - - ">="
+ - !ruby/object:Gem::Version
+ version: '0'
+ type: :runtime
+ prerelease: false
+ version_requirements: !ruby/object:Gem::Requirement
+ requirements:
+ - - ">="
+ - !ruby/object:Gem::Version
+ version: '0'
+- !ruby/object:Gem::Dependency
name: rake
requirement: !ruby/object:Gem::Requirement
requirements:
@@ -108,7 +122,7 @@
version: '0'
requirements: []
rubyforge_project:
-rubygems_version: 2.7.4
+rubygems_version: 2.7.6
signing_key:
specification_version: 4
summary: A class based configuration library
diff -urN '--exclude=CVS' '--exclude=.cvsignore' '--exclude=.svn'
'--exclude=.svnignore' old/mixlib-config.gemspec new/mixlib-config.gemspec
--- old/mixlib-config.gemspec 2018-02-09 19:25:02.000000000 +0100
+++ new/mixlib-config.gemspec 2018-07-11 23:14:00.000000000 +0200
@@ -23,6 +23,8 @@
s.description = s.summary
s.license = "Apache-2.0"
+ s.add_dependency "tomlrb"
+
s.add_development_dependency "rake"
s.add_development_dependency "rspec", "~> 3.0"
s.add_development_dependency "chefstyle"
diff -urN '--exclude=CVS' '--exclude=.cvsignore' '--exclude=.svn'
'--exclude=.svnignore' old/spec/mixlib/config_spec.rb
new/spec/mixlib/config_spec.rb
--- old/spec/mixlib/config_spec.rb 2018-02-09 19:25:02.000000000 +0100
+++ new/spec/mixlib/config_spec.rb 2018-07-11 23:14:00.000000000 +0200
@@ -1,6 +1,6 @@
#
# Author:: Adam Jacob (<[email protected]>)
-# 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");
@@ -115,6 +115,26 @@
it "raises an error when you set an arbitrary config option with [:y] =
10" do
expect(lambda { StrictClass[:y] = 10 }).to
raise_error(Mixlib::Config::UnknownConfigOptionError, "Cannot set unsupported
config value y.")
end
+
+ it "does not break config_context_list" do
+ expect(lambda do
+ StrictClass.class_eval do
+ config_context_list(:lists, :list) do
+ default :y, 20
+ end
+ end
+ end).not_to raise_error
+ end
+
+ it "does not break config_context_hash" do
+ expect(lambda do
+ StrictClass.class_eval do
+ config_context_hash(:hashes, :hash) do
+ default :z, 20
+ end
+ end
+ end).not_to raise_error
+ end
end
describe "when a block has been used to set config values" do
@@ -122,7 +142,7 @@
ConfigIt.configure { |c| c[:cookbook_path] = "monkey_rabbit";
c[:otherthing] = "boo" }
end
- { :cookbook_path => "monkey_rabbit", :otherthing => "boo" }.each do |k, v|
+ { cookbook_path: "monkey_rabbit", otherthing: "boo" }.each do |k, v|
it "allows you to retrieve the config value for #{k} via []" do
expect(ConfigIt[k]).to eql(v)
end
@@ -142,6 +162,12 @@
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
@@ -209,6 +235,23 @@
expect(@klass.respond_to?("z=".to_sym)).to be false
end
+ it "returns true for is_default? for a default value" do
+ expect(@klass[:a]).to eql(1)
+ expect(@klass.is_default?(:a)).to be true
+ end
+
+ it "returns true for is_default? for an overwritten default value" do
+ @klass[:a] = 1
+ expect(@klass[:a]).to eql(1)
+ expect(@klass.is_default?(:a)).to be true
+ end
+
+ it "returns false for is_default? for a value that is not the default" do
+ @klass[:a] = 2
+ expect(@klass[:a]).to eql(2)
+ expect(@klass.is_default?(:a)).to be false
+ end
+
describe "and extra methods have been dumped into Object" do
class NopeError < StandardError
end
@@ -281,12 +324,12 @@
end
it "save with include_defaults should save all defaults" do
- expect(@klass.save(true)).to eql({ :attr => 4 })
+ expect(@klass.save(true)).to eql({ attr: 4 })
end
it "saves the new value if it gets set" do
@klass.attr 5
- expect((saved = @klass.save)).to eql({ :attr => 5 })
+ expect((saved = @klass.save)).to eql({ attr: 5 })
@klass.reset
expect(@klass.attr).to eql(4)
@klass.restore(saved)
@@ -295,11 +338,11 @@
it "saves the new value even if it is set to its default value" do
@klass.attr 4
- expect((saved = @klass.save)).to eql({ :attr => 4 })
+ expect((saved = @klass.save)).to eql({ attr: 4 })
@klass.reset
expect(@klass.save).to eql({})
@klass.restore(saved)
- expect(@klass.save).to eql({ :attr => 4 })
+ expect(@klass.save).to eql({ attr: 4 })
end
end
@@ -349,12 +392,12 @@
end
it "save with include_defaults should save all defaults" do
- expect(@klass.save(true)).to eql({ :attr => 8, :x => 4 })
+ expect(@klass.save(true)).to eql({ attr: 8, x: 4 })
end
it "saves the new value if it gets set" do
@klass.attr 5
- expect((saved = @klass.save)).to eql({ :attr => 5 })
+ expect((saved = @klass.save)).to eql({ attr: 5 })
@klass.reset
expect(@klass.attr).to eql(8)
@klass.restore(saved)
@@ -363,11 +406,11 @@
it "saves the new value even if it is set to its default value" do
@klass.attr 8
- expect((saved = @klass.save)).to eql({ :attr => 8 })
+ expect((saved = @klass.save)).to eql({ attr: 8 })
@klass.reset
expect(@klass.save).to eql({})
@klass.restore(saved)
- expect(@klass.save).to eql({ :attr => 8 })
+ expect(@klass.save).to eql({ attr: 8 })
end
end
@@ -390,12 +433,12 @@
end
it "save with include_defaults should save all defaults" do
- expect(@klass.save(true)).to eql({ :attr => [] })
+ expect(@klass.save(true)).to eql({ attr: [] })
end
it "saves the new value if it gets set" do
@klass.attr << "x"
- expect((saved = @klass.save)).to eql({ :attr => [ "x" ] })
+ expect((saved = @klass.save)).to eql({ attr: [ "x" ] })
@klass.reset
expect(@klass.attr).to eql([])
@klass.restore(saved)
@@ -404,11 +447,11 @@
it "saves the new value even if it is set to its default value" do
@klass.attr = []
- expect((saved = @klass.save)).to eql({ :attr => [] })
+ expect((saved = @klass.save)).to eql({ attr: [] })
@klass.reset
expect(@klass.save).to eql({})
@klass.restore(saved)
- expect(@klass.save).to eql({ :attr => [] })
+ expect(@klass.save).to eql({ attr: [] })
end
end
@@ -431,25 +474,25 @@
end
it "save with include_defaults should save all defaults" do
- expect(@klass.save(true)).to eql({ :attr => {} })
+ expect(@klass.save(true)).to eql({ attr: {} })
end
it "saves the new value if it gets set" do
@klass.attr[:hi] = "lo"
- expect((saved = @klass.save)).to eql({ :attr => { :hi => "lo" } })
+ expect((saved = @klass.save)).to eql({ attr: { hi: "lo" } })
@klass.reset
expect(@klass.attr).to eql({})
@klass.restore(saved)
- expect(@klass.save).to eql({ :attr => { :hi => "lo" } })
+ expect(@klass.save).to eql({ attr: { hi: "lo" } })
end
it "saves the new value even if it is set to its default value" do
@klass.attr = {}
- expect((saved = @klass.save)).to eql({ :attr => {} })
+ expect((saved = @klass.save)).to eql({ attr: {} })
@klass.reset
expect(@klass.save).to eql({})
@klass.restore(saved)
- expect(@klass.save).to eql({ :attr => {} })
+ expect(@klass.save).to eql({ attr: {} })
end
end
@@ -472,12 +515,12 @@
end
it "save with include_defaults should save all defaults" do
- expect(@klass.save(true)).to eql({ :attr => "hello" })
+ expect(@klass.save(true)).to eql({ attr: "hello" })
end
it "saves the new value if it gets set" do
@klass.attr << " world"
- expect((saved = @klass.save)).to eql({ :attr => "hello world" })
+ expect((saved = @klass.save)).to eql({ attr: "hello world" })
@klass.reset
expect(@klass.attr).to eql("hello")
@klass.restore(saved)
@@ -486,11 +529,11 @@
it "saves the new value even if it is set to its default value" do
@klass.attr "hello world"
- expect((saved = @klass.save)).to eql({ :attr => "hello world" })
+ expect((saved = @klass.save)).to eql({ attr: "hello world" })
@klass.reset
expect(@klass.save).to eql({})
@klass.restore(saved)
- expect(@klass.save).to eql({ :attr => "hello world" })
+ expect(@klass.save).to eql({ attr: "hello world" })
end
end
@@ -534,12 +577,12 @@
end
it "save with include_defaults should save all defaults" do
- expect(@klass.save(true)).to eql({ :attr => 4 })
+ expect(@klass.save(true)).to eql({ attr: 4 })
end
it "saves the new value if it gets set" do
@klass.attr 5
- expect((saved = @klass.save)).to eql({ :attr => 5 })
+ expect((saved = @klass.save)).to eql({ attr: 5 })
@klass.reset
expect(@klass.attr).to eql(4)
@klass.restore(saved)
@@ -548,11 +591,11 @@
it "saves the new value even if it is set to its default value" do
@klass.attr 4
- expect((saved = @klass.save)).to eql({ :attr => 4 })
+ expect((saved = @klass.save)).to eql({ attr: 4 })
@klass.reset
expect(@klass.save).to eql({})
@klass.restore(saved)
- expect(@klass.save).to eql({ :attr => 4 })
+ expect(@klass.save).to eql({ attr: 4 })
end
end
@@ -611,12 +654,12 @@
end
it "save with include_defaults should save all defaults" do
- expect(@klass.save(true)).to eql({ :attr => 4 })
+ expect(@klass.save(true)).to eql({ attr: 4 })
end
it "saves the new value if it gets set" do
@klass.attr 5
- expect((saved = @klass.save)).to eql({ :attr => 10 })
+ expect((saved = @klass.save)).to eql({ attr: 10 })
@klass.reset
expect(@klass.attr).to eql(4)
@klass.restore(saved)
@@ -625,11 +668,11 @@
it "saves the new value even if it is set to its default value" do
@klass.attr 4
- expect((saved = @klass.save)).to eql({ :attr => 8 })
+ expect((saved = @klass.save)).to eql({ attr: 8 })
@klass.reset
expect(@klass.save).to eql({})
@klass.restore(saved)
- expect(@klass.save).to eql({ :attr => 8 })
+ expect(@klass.save).to eql({ attr: 8 })
end
end
@@ -685,12 +728,12 @@
end
it "save with include_defaults should save all defaults" do
- expect(@klass.save(true)).to eql({ :attr => 4 })
+ expect(@klass.save(true)).to eql({ attr: 4 })
end
it "saves the new value if it gets set" do
@klass.attr 5
- expect((saved = @klass.save)).to eql({ :attr => 10 })
+ expect((saved = @klass.save)).to eql({ attr: 10 })
@klass.reset
expect(@klass.attr).to eql(4)
@klass.restore(saved)
@@ -699,11 +742,11 @@
it "saves the new value even if it is set to its default value" do
@klass.attr 2
- expect((saved = @klass.save)).to eql({ :attr => 4 })
+ expect((saved = @klass.save)).to eql({ attr: 4 })
@klass.reset
expect(@klass.save).to eql({})
@klass.restore(saved)
- expect(@klass.save).to eql({ :attr => 4 })
+ expect(@klass.save).to eql({ attr: 4 })
end
end
@@ -735,12 +778,12 @@
end
it "setting the entire context to a hash with default value overridden
sets the value" do
- @klass.blah = { :x => 10 }
+ @klass.blah = { x: 10 }
expect(@klass.blah.x).to eql(10)
end
it "setting the entire context to a hash sets non-default values" do
- @klass.blah = { :y => 10 }
+ @klass.blah = { y: 10 }
expect(@klass.blah.x).to eql(5)
expect(@klass.blah.y).to eql(10)
end
@@ -748,7 +791,7 @@
it "setting the entire context to a hash deletes any non-default values
and resets default values" do
@klass.blah.x = 10
@klass.blah.y = 10
- @klass.blah = { :z => 10 }
+ @klass.blah = { z: 10 }
expect(@klass.blah.x).to eql(5)
expect(@klass.blah.y).to be_nil
expect(@klass.blah.z).to eql(10)
@@ -759,8 +802,8 @@
x 10
y 20
end
- @klass.blah.x.should == 10
- @klass.blah.y.should == 20
+ expect(@klass.blah.x).to eq 10
+ expect(@klass.blah.y).to eq 20
end
it "setting the context values in a yielded block overrides the default
values" do
@@ -768,8 +811,8 @@
b.x = 10
b.y = 20
end
- @klass.blah.x.should == 10
- @klass.blah.y.should == 20
+ expect(@klass.blah.x).to eq 10
+ expect(@klass.blah.y).to eq 20
end
it "after reset of the parent class, children are reset" do
@@ -784,17 +827,17 @@
end
it "save with include_defaults should save all defaults" do
- expect(@klass.save(true)).to eql({ :blah => { :x => 5 } })
+ expect(@klass.save(true)).to eql({ blah: { x: 5 } })
end
it "saves any new values that are set in the context" do
@klass.blah.x = 10
- expect((saved = @klass.save)).to eql({ :blah => { :x => 10 } })
+ expect((saved = @klass.save)).to eql({ blah: { x: 10 } })
@klass.reset
expect(@klass.blah.x).to eql(5)
@klass.restore(saved)
expect(@klass.blah.x).to eql(10)
- expect(@klass.save).to eql({ :blah => { :x => 10 } })
+ expect(@klass.save).to eql({ blah: { x: 10 } })
end
# this tests existing (somewhat bizzare) behavior of mixlib-config where
testing to
@@ -860,37 +903,37 @@
end
it "save with include_defaults should save all defaults" do
- expect(@klass.save(true)).to eql({ :blah => { :yarr => { :x => 5, :y =>
6 } } })
+ expect(@klass.save(true)).to eql({ blah: { yarr: { x: 5, y: 6 } } })
end
it "saves any new values that are set in the context" do
@klass.blah.yarr.x = 10
@klass.blah.yarr.y = 11
- expect((saved = @klass.save)).to eql({ :blah => { :yarr => { :x => 10,
:y => 11 } } })
+ expect((saved = @klass.save)).to eql({ blah: { yarr: { x: 10, y: 11 } }
})
@klass.reset
expect(@klass.blah.yarr.x).to eql(5)
expect(@klass.blah.yarr.y).to eql(6)
@klass.restore(saved)
expect(@klass.blah.yarr.x).to eql(10)
expect(@klass.blah.yarr.y).to eql(11)
- expect(@klass.save).to eql({ :blah => { :yarr => { :x => 10, :y => 11 }
} })
+ expect(@klass.save).to eql({ blah: { yarr: { x: 10, y: 11 } } })
end
it "restores defaults not included in saved data" do
- @klass.restore( :blah => { :yarr => { :x => 10 } } )
+ @klass.restore( blah: { yarr: { x: 10 } } )
expect(@klass.blah.yarr.x).to eql(10)
expect(@klass.blah.yarr.y).to eql(6)
end
it "removes added properties not included in saved state" do
@klass.blah.yarr.z = 12
- @klass.restore( :blah => { :yarr => { :x => 10 } } )
+ @klass.restore( blah: { yarr: { x: 10 } } )
expect(@klass.blah.yarr.x).to eql(10)
expect(@klass.blah.yarr.z).to eql(nil)
end
it "can set a config context from another context" do
- @klass.blah.blyme = { :x => 7 }
+ @klass.blah.blyme = { x: 7 }
blyme = @klass.blah.blyme
@klass.blah.yarr.x = 12
@klass.blah.yarr = blyme
@@ -909,12 +952,20 @@
end
end
+ it "has_key? finds the subcontext" do
+ expect(@klass.has_key?(:blah)).to be true
+ end
+
+ it "key? finds the subcontext" do
+ expect(@klass.key?(:blah)).to be true
+ end
+
it "save does not save the hash for the config_context" do
expect(@klass.save).to eql({})
end
it "save with defaults saves the hash for the config_context" do
- expect(@klass.save(true)).to eql({ :blah => {} })
+ expect(@klass.save(true)).to eql({ blah: {} })
end
end
@@ -932,7 +983,7 @@
end
it "save with defaults saves the hash for the config_context" do
- expect(@klass.save(true)).to eql({ :blah => {} })
+ expect(@klass.save(true)).to eql({ blah: {} })
end
end
@@ -1186,7 +1237,7 @@
EOH
end
- it "turns YAML into method-style setting" do
+ it "turns JSON into method-style setting" do
allow(File).to receive(:exists?).and_return(true)
allow(File).to receive(:readable?).and_return(true)
allow(IO).to receive(:read).with("config.json").and_return(json)
@@ -1200,18 +1251,51 @@
end
end
+ describe ".from_toml" do
+ let(:toml) do
+ <<-EOH
+foo = ["bar", "baz", "matazz"]
+alpha = "beta"
+ EOH
+ end
+
+ it "turns TOML into method-style setting" do
+ allow(File).to receive(:exists?).and_return(true)
+ allow(File).to receive(:readable?).and_return(true)
+ allow(IO).to receive(:read).with("config.toml").and_return(toml)
+
+ expect(lambda do
+ ConfigIt.from_file("config.toml")
+ end).to_not raise_error
+
+ expect(ConfigIt.foo).to eql(%w{ bar baz matazz })
+ expect(ConfigIt.alpha).to eql("beta")
+ end
+ end
+
describe ".from_hash" do
let(:hash) do
{
"alpha" => "beta",
+ gamma: "delta",
"foo" => %w{ bar baz matazz},
+ "bar" => { "baz" => { "fizz" => "buzz" } },
+ "windows_path" => 'C:\Windows Has Awful\Paths',
}
end
- it "translates the Hash into method-style" do
+ it "configures the config object from a hash" do
+ ConfigIt.config_context :bar do
+ config_context :baz do
+ default :fizz, "quux"
+ end
+ end
ConfigIt.from_hash(hash)
expect(ConfigIt.foo).to eql(%w{ bar baz matazz })
expect(ConfigIt.alpha).to eql("beta")
+ expect(ConfigIt.gamma).to eql("delta")
+ expect(ConfigIt[:bar][:baz][:fizz]).to eql("buzz")
+ expect(ConfigIt.windows_path).to eql('C:\Windows Has Awful\Paths')
end
end
end
diff -urN '--exclude=CVS' '--exclude=.cvsignore' '--exclude=.svn'
'--exclude=.svnignore' old/spec/spec_helper.rb new/spec/spec_helper.rb
--- old/spec/spec_helper.rb 2018-02-09 19:25:02.000000000 +0100
+++ new/spec/spec_helper.rb 2018-07-11 23:14:00.000000000 +0200
@@ -9,7 +9,7 @@
end
RSpec.configure do |config|
- config.filter_run :focus => true
+ config.filter_run focus: true
config.run_all_when_everything_filtered = true
config.warnings = true
end