squire 1.2.0 → 1.2.1

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.
data/CHANGELOG.md ADDED
@@ -0,0 +1,15 @@
1
+ ### 1.2.1
2
+
3
+ * Fix minor bug with ActiveSupport Hash#deep_merge! omitting block for false keys.
4
+ More: https://github.com/rails/rails/pull/12072 (Waiting for merge and release in new ActiveSupport version).
5
+ Fix is temporararly included in squire/core_ext/hash/deep_merge.rb
6
+
7
+ *Samuel Molnár*
8
+
9
+ ### 1.2.0
10
+
11
+ * Full support for YAML, Hash
12
+ * DSL for Base class, config key delegation via method missing.
13
+ * Support for Settingslogic-like API via Squire::Base.
14
+
15
+ *Samuel Molnár*
@@ -0,0 +1,30 @@
1
+ # TODO: Wait for this pull to be merged and released in new version of ActiveSupport.
2
+ # https://github.com/rails/rails/pull/12072
3
+
4
+ class Hash
5
+ # Returns a new hash with +self+ and +other_hash+ merged recursively.
6
+ #
7
+ # h1 = {x: {y: [4,5,6]}, z: [7,8,9]}
8
+ # h2 = {x: {y: [7,8,9]}, z: "xyz"}
9
+ #
10
+ # h1.deep_merge(h2) #=> {:x => {:y => [7, 8, 9]}, :z => "xyz"}
11
+ # h2.deep_merge(h1) #=> {:x => {:y => [4, 5, 6]}, :z => [7, 8, 9]}
12
+ # h1.deep_merge(h2) { |key, old, new| Array.wrap(old) + Array.wrap(new) }
13
+ # #=> {:x => {:y => [4, 5, 6, 7, 8, 9]}, :z => [7, 8, 9, "xyz"]}
14
+ def deep_merge(other_hash, &block)
15
+ dup.deep_merge!(other_hash, &block)
16
+ end
17
+
18
+ # Same as +deep_merge+, but modifies +self+.
19
+ def deep_merge!(other_hash, &block)
20
+ other_hash.each_pair do |k,v|
21
+ tv = self[k]
22
+ if tv.is_a?(Hash) && v.is_a?(Hash)
23
+ self[k] = tv.deep_merge(v, &block)
24
+ else
25
+ self[k] = block && !tv.nil? ? block.call(k, tv, v) : v
26
+ end
27
+ end
28
+ self
29
+ end
30
+ end
@@ -61,7 +61,7 @@ module Squire
61
61
  else
62
62
  value = get_value(key)
63
63
 
64
- unless value
64
+ if value.nil?
65
65
  raise MissingSettingError.new("Missing setting in '#{key}' in '#{@path}'.")
66
66
  end
67
67
 
@@ -80,7 +80,7 @@ module Squire
80
80
  # settings.nested.a
81
81
  # it returns +settings.a+.
82
82
  def get_value(key)
83
- return @table[key] if @table[key]
83
+ return @table[key] unless @table[key].nil?
84
84
  return @parent.get_value(key) if @parent
85
85
  end
86
86
 
@@ -1,3 +1,3 @@
1
1
  module Squire
2
- VERSION = '1.2.0'
2
+ VERSION = '1.2.1'
3
3
  end
data/lib/squire.rb CHANGED
@@ -1,6 +1,7 @@
1
1
  require 'active_support/concern'
2
2
  require 'active_support/core_ext/hash/keys'
3
- require 'active_support/core_ext/hash/deep_merge'
3
+ # require 'active_support/core_ext/hash/deep_merge'
4
+ require 'squire/core_ext/hash/deep_merge'
4
5
  require 'active_support/core_ext/hash/except'
5
6
  require 'squire/version'
6
7
  require 'squire/exceptions'
@@ -8,13 +8,15 @@ describe Squire::Configuration do
8
8
  defaults: {
9
9
  nested: {
10
10
  b: 3,
11
- c: 4
11
+ c: 4,
12
+ d: true
12
13
  }
13
14
  },
14
15
  development: {
15
16
  a: 1,
16
17
  nested: {
17
- b: 2
18
+ b: 2,
19
+ d: false
18
20
  }
19
21
  },
20
22
  production: {
@@ -66,6 +68,7 @@ describe Squire::Configuration do
66
68
 
67
69
  subject.settings.a.should eql(1)
68
70
  subject.settings.nested.b.should eql(2) # from development.nested.b
71
+ subject.settings.nested.d.should be_false # from development.nested.d
69
72
  subject.settings.nested.c.should eql(4) # from defaults.nested.c
70
73
  end
71
74
  end
@@ -0,0 +1,20 @@
1
+ require 'spec_helper'
2
+
3
+ describe Hash do
4
+ describe '#deep_merge' do
5
+ let(:a) {{ a: 1, b: 2, c: 3, nested: { a: 1 }}}
6
+ let(:b) {{ a: 1, c: 3, d: 4, nested: { a: 2, b: 3 }}}
7
+
8
+ it 'should merge hashes deeply' do
9
+ merge = { a: 1, b: 2, c: 3, d: 4, nested: { a: 2, b: 3 }}
10
+
11
+ a.deep_merge(b).should eql(merge)
12
+ end
13
+
14
+ it 'should merge hashes deeply with block' do
15
+ merge = { a: [:a, 1, 1], b: 2, c: [:c, 3, 3], d: 4, nested: { a: [:a, 1, 2], b: 3 }}
16
+
17
+ (a.deep_merge(b) { |key, old, new| [key, old, new] }).should eql(merge)
18
+ end
19
+ end
20
+ end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: squire
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.2.0
4
+ version: 1.2.1
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -9,7 +9,7 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2013-08-29 00:00:00.000000000 Z
12
+ date: 2013-08-30 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: activesupport
@@ -132,6 +132,7 @@ extra_rdoc_files: []
132
132
  files:
133
133
  - .gitignore
134
134
  - .rspec
135
+ - CHANGELOG.md
135
136
  - Gemfile
136
137
  - LICENSE.txt
137
138
  - README.md
@@ -140,6 +141,7 @@ files:
140
141
  - lib/squire.rb
141
142
  - lib/squire/base.rb
142
143
  - lib/squire/configuration.rb
144
+ - lib/squire/core_ext/hash/deep_merge.rb
143
145
  - lib/squire/exceptions.rb
144
146
  - lib/squire/parser.rb
145
147
  - lib/squire/parser/hash.rb
@@ -151,6 +153,7 @@ files:
151
153
  - spec/spec_helper.rb
152
154
  - spec/squire/base_spec.rb
153
155
  - spec/squire/configuration_spec.rb
156
+ - spec/squire/core_ext/hash/deep_merge_spec.rb
154
157
  - spec/squire/parser/hash_spec.rb
155
158
  - spec/squire/parser/yaml_spec.rb
156
159
  - spec/squire/proxy_spec.rb
@@ -188,6 +191,7 @@ test_files:
188
191
  - spec/spec_helper.rb
189
192
  - spec/squire/base_spec.rb
190
193
  - spec/squire/configuration_spec.rb
194
+ - spec/squire/core_ext/hash/deep_merge_spec.rb
191
195
  - spec/squire/parser/hash_spec.rb
192
196
  - spec/squire/parser/yaml_spec.rb
193
197
  - spec/squire/proxy_spec.rb