complex_config 0.2.3 → 0.3.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: a2ddd63fa3baff35f04957e3a84840ac417a83e0
4
- data.tar.gz: 5cf7b7610df168f0b90c052ed97074c35c57f5b0
3
+ metadata.gz: 5e4e0620c33cd0efa7e74a00baedee019c521119
4
+ data.tar.gz: e06d717a659587ebeb40c417c7f0e2af49f29c6b
5
5
  SHA512:
6
- metadata.gz: 109d842367862e0cbdee94a26221d47e9b4e4150f540b2cf801738bf6a9da5d0eff50426e567dd7f84ac4c204a69d2dec41131090798ef7aece88a9deacfbb0c
7
- data.tar.gz: 6f824ff2f1314a8c5bf0d6014afd20239ba4629ed06d099f2d184b85cdd8cb63f66e2295e4b1dc63dce02ca7f173df8677de9a223d5967087f81193d47036394
6
+ metadata.gz: adb8a5f25523b30d50c059836ef86b392c975f3339e891f0655a007a620177fc83645562b8ef3973a6a210b4ac67f7cafec24351210aeac7b3472bcd99c61b47
7
+ data.tar.gz: 8c9739828e4054a81c0700f9126fa3dba68c43518984149bdf7307f5494397bac6c140f71cb9227ba58b7099eebad40efb95b63076734a60ba29bdb4f4d70d58
data/VERSION CHANGED
@@ -1 +1 @@
1
- 0.2.3
1
+ 0.3.0
@@ -1,14 +1,14 @@
1
1
  # -*- encoding: utf-8 -*-
2
- # stub: complex_config 0.2.3 ruby lib
2
+ # stub: complex_config 0.3.0 ruby lib
3
3
 
4
4
  Gem::Specification.new do |s|
5
5
  s.name = "complex_config"
6
- s.version = "0.2.3"
6
+ s.version = "0.3.0"
7
7
 
8
8
  s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
9
9
  s.require_paths = ["lib"]
10
10
  s.authors = ["Florian Frank"]
11
- s.date = "2015-03-24"
11
+ s.date = "2015-04-28"
12
12
  s.description = "This library allows you to access configuration files via a simple interface"
13
13
  s.email = "flori@ping.de"
14
14
  s.extra_rdoc_files = ["README.md", "lib/complex_config.rb", "lib/complex_config/errors.rb", "lib/complex_config/plugins.rb", "lib/complex_config/plugins/enable.rb", "lib/complex_config/plugins/money.rb", "lib/complex_config/plugins/uri.rb", "lib/complex_config/provider.rb", "lib/complex_config/rude.rb", "lib/complex_config/settings.rb", "lib/complex_config/shortcuts.rb", "lib/complex_config/version.rb"]
@@ -16,7 +16,7 @@ Gem::Specification.new do |s|
16
16
  s.homepage = "https://github.com/flori/complex_config"
17
17
  s.licenses = ["Apache-2.0"]
18
18
  s.rdoc_options = ["--title", "ComplexConfig -- configuration library", "--main", "README.md"]
19
- s.rubygems_version = "2.4.5"
19
+ s.rubygems_version = "2.4.6"
20
20
  s.summary = "configuration library"
21
21
  s.test_files = ["spec/complex_config/plugins_spec.rb", "spec/complex_config/provider_spec.rb", "spec/complex_config/settings_spec.rb", "spec/complex_config/shortcuts_spec.rb", "spec/spec_helper.rb"]
22
22
 
@@ -24,20 +24,20 @@ Gem::Specification.new do |s|
24
24
  s.specification_version = 4
25
25
 
26
26
  if Gem::Version.new(Gem::VERSION) >= Gem::Version.new('1.2.0') then
27
- s.add_development_dependency(%q<gem_hadar>, ["~> 1.0.0"])
27
+ s.add_development_dependency(%q<gem_hadar>, ["~> 1.2.1"])
28
28
  s.add_development_dependency(%q<rake>, [">= 0"])
29
29
  s.add_development_dependency(%q<simplecov>, [">= 0"])
30
30
  s.add_development_dependency(%q<rspec>, [">= 0"])
31
31
  s.add_runtime_dependency(%q<json>, [">= 0"])
32
32
  else
33
- s.add_dependency(%q<gem_hadar>, ["~> 1.0.0"])
33
+ s.add_dependency(%q<gem_hadar>, ["~> 1.2.1"])
34
34
  s.add_dependency(%q<rake>, [">= 0"])
35
35
  s.add_dependency(%q<simplecov>, [">= 0"])
36
36
  s.add_dependency(%q<rspec>, [">= 0"])
37
37
  s.add_dependency(%q<json>, [">= 0"])
38
38
  end
39
39
  else
40
- s.add_dependency(%q<gem_hadar>, ["~> 1.0.0"])
40
+ s.add_dependency(%q<gem_hadar>, ["~> 1.2.1"])
41
41
  s.add_dependency(%q<rake>, [">= 0"])
42
42
  s.add_dependency(%q<simplecov>, [">= 0"])
43
43
  s.add_dependency(%q<rspec>, [">= 0"])
@@ -1,4 +1,5 @@
1
1
  begin
2
+ require 'forwardable' # XXX monetize forgets to require this
2
3
  require 'monetize'
3
4
  rescue LoadError
4
5
  if $DEBUG
@@ -31,10 +31,45 @@ class ComplexConfig::Settings < JSON::GenericObject
31
31
  end
32
32
  end
33
33
 
34
- def to_s
35
- to_h.to_yaml
34
+ def to_s(pair_sep: ' = ', path_sep: ?.)
35
+ pathes(path_sep: path_sep).inject('') do |result, (path, value)|
36
+ result << "#{path}#{pair_sep}#{value.inspect}\n"
37
+ end
38
+ end
39
+
40
+ def pathes(hash = table, path_sep: ?., prefix: '', result: {})
41
+ hash.each do |key, value|
42
+ path = prefix.empty? ? key.to_s : "#{prefix}#{path_sep}#{key}"
43
+ case value
44
+ when ComplexConfig::Settings
45
+ pathes(
46
+ value,
47
+ path_sep: path_sep,
48
+ prefix: path,
49
+ result: result
50
+ )
51
+ when Array
52
+ value.each_with_index do |v, i|
53
+ sub_path = path + "[#{i}]"
54
+ if ComplexConfig::Settings === v
55
+ pathes(
56
+ v,
57
+ path_sep: path_sep,
58
+ prefix: sub_path,
59
+ result: result
60
+ )
61
+ else
62
+ result[sub_path] = v
63
+ end
64
+ end
65
+ else
66
+ result[path] = value
67
+ end
68
+ end
69
+ result
36
70
  end
37
71
 
72
+
38
73
  def to_ary(*a, &b)
39
74
  table_enumerator.__send__(:to_a, *a, &b)
40
75
  end
@@ -1,6 +1,6 @@
1
1
  module ComplexConfig
2
2
  # ComplexConfig version
3
- VERSION = '0.2.3'
3
+ VERSION = '0.3.0'
4
4
  VERSION_ARRAY = VERSION.split('.').map(&:to_i) # :nodoc:
5
5
  VERSION_MAJOR = VERSION_ARRAY[0] # :nodoc:
6
6
  VERSION_MINOR = VERSION_ARRAY[1] # :nodoc:
@@ -39,13 +39,28 @@ RSpec.describe ComplexConfig::Settings do
39
39
  expect(settings.foo.to_h).to eq(bar: { baz: true }, qux: 'quux')
40
40
  end
41
41
 
42
+ it 'can return a hash with pathes as keys' do
43
+ expect(settings.pathes(path_sep: ?:)).to eq(
44
+ 'foo:bar:baz' => true,
45
+ 'foo:qux' => "quux"
46
+ )
47
+ end
48
+
42
49
  it 'can be represented as a string' do
50
+ expect(settings.to_s(pair_sep: ' → ', path_sep: ?/)).to eq <<EOT
51
+ foo/bar/baz → true
52
+ foo/qux → "quux"
53
+ EOT
54
+ end
55
+
56
+ it 'can be represented as a string if it has arrays' do
57
+ settings[:ary] = ComplexConfig::Settings[ [ 1, { nested: 2 }, 3 ] ]
43
58
  expect(settings.to_s).to eq <<EOT
44
- ---
45
- :foo:
46
- :bar:
47
- :baz: true
48
- :qux: quux
59
+ foo.bar.baz = true
60
+ foo.qux = "quux"
61
+ ary[0] = 1
62
+ ary[1].nested = 2
63
+ ary[2] = 3
49
64
  EOT
50
65
  end
51
66
 
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: complex_config
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.2.3
4
+ version: 0.3.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Florian Frank
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2015-03-24 00:00:00.000000000 Z
11
+ date: 2015-04-28 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: gem_hadar
@@ -16,14 +16,14 @@ dependencies:
16
16
  requirements:
17
17
  - - "~>"
18
18
  - !ruby/object:Gem::Version
19
- version: 1.0.0
19
+ version: 1.2.1
20
20
  type: :development
21
21
  prerelease: false
22
22
  version_requirements: !ruby/object:Gem::Requirement
23
23
  requirements:
24
24
  - - "~>"
25
25
  - !ruby/object:Gem::Version
26
- version: 1.0.0
26
+ version: 1.2.1
27
27
  - !ruby/object:Gem::Dependency
28
28
  name: rake
29
29
  requirement: !ruby/object:Gem::Requirement
@@ -151,7 +151,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
151
151
  version: '0'
152
152
  requirements: []
153
153
  rubyforge_project:
154
- rubygems_version: 2.4.5
154
+ rubygems_version: 2.4.6
155
155
  signing_key:
156
156
  specification_version: 4
157
157
  summary: configuration library