configarrr 0.1.1 → 0.1.2

Sign up to get free protection for your applications and to get access to all the features.
data/VERSION CHANGED
@@ -1 +1 @@
1
- 0.1.1
1
+ 0.1.2
@@ -4,4 +4,6 @@ module Configarrr
4
4
  class OptionError < StandardError; end
5
5
  end
6
6
 
7
+ require 'core_ext'
8
+
7
9
  %w( base simple yaml ).each { |lib| require "configarrr/#{lib}" }
@@ -16,9 +16,9 @@ module Configarrr
16
16
 
17
17
  def set_yaml
18
18
  if @parent
19
- @yaml.has_key?(@parent) ? set(defaults.merge(@yaml[@parent])) : raise(Configarrr::OptionError, "Please provide a valid parent value. #{@parent} does not exist.")
19
+ @yaml.has_key?(@parent) ? set(defaults.recursive_merge(@yaml[@parent])) : raise(Configarrr::OptionError, "Please provide a valid parent value. #{@parent} does not exist.")
20
20
  else
21
- set defaults.merge(@yaml)
21
+ set defaults.recursive_merge(@yaml)
22
22
  end
23
23
  end
24
24
 
@@ -0,0 +1 @@
1
+ require 'core_ext/hash/recursive_merge'
@@ -0,0 +1,24 @@
1
+ # From https://gist.github.com/raw/6391/a9de33bb917726d4983fa07971af21fb5c664f70/hash_recursive_merge.rb
2
+
3
+ module CoreExt
4
+ module Hash
5
+ module RecursiveMerge
6
+ def recursive_merge!(other_hash)
7
+ merge!(other_hash) do |key, _old, _new|
8
+ _old.class == self.class ? _old.recursive_merge!(_new) : _new
9
+ end
10
+ end
11
+
12
+ def recursive_merge(other_hash)
13
+ r = {}
14
+ merge(other_hash) do |key, _old, _new|
15
+ r[key] = _old.class == self.class ? _old.recursive_merge(_new) : _new
16
+ end
17
+ end
18
+ end
19
+ end
20
+ end
21
+
22
+ class Hash
23
+ include CoreExt::Hash::RecursiveMerge
24
+ end
@@ -2,7 +2,7 @@ require File.dirname(__FILE__) + '/../spec_helper'
2
2
 
3
3
  class YAMLWithDefaults < Configarrr::YAML
4
4
  def defaults
5
- { 'first_key' => 1234, 'third_key' => 1234 }
5
+ { 'first_key' => 1234, 'third_key' => 1234, 'parent' => { 'fourth_key' => 12345 } }
6
6
  end
7
7
  end
8
8
 
@@ -60,6 +60,10 @@ describe Configarrr::YAML do
60
60
  it "should provide setting if not provided" do
61
61
  @yaml_with_defaults.third_key.should == 1234
62
62
  end
63
+
64
+ it "should work with multidimensional hashes" do
65
+ @yaml_with_defaults.parent['fourth_key'].should == 12345
66
+ end
63
67
  end
64
68
 
65
69
  it_should_behave_like "a Configarrr implementation"
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: configarrr
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.1
4
+ version: 0.1.2
5
5
  platform: ruby
6
6
  authors:
7
7
  - Dylan Egan
@@ -9,7 +9,7 @@ autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
11
 
12
- date: 2009-09-30 00:00:00 +10:00
12
+ date: 2009-10-01 00:00:00 +10:00
13
13
  default_executable:
14
14
  dependencies: []
15
15
 
@@ -29,6 +29,8 @@ files:
29
29
  - lib/configarrr/base.rb
30
30
  - lib/configarrr/simple.rb
31
31
  - lib/configarrr/yaml.rb
32
+ - lib/core_ext.rb
33
+ - lib/core_ext/hash/recursive_merge.rb
32
34
  - spec/configarrr/base_spec.rb
33
35
  - spec/configarrr/yaml_spec.rb
34
36
  - spec/fixtures/config.yml