settingable 0.4.0 → 0.5.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: d23f961440042e2c622735edff5558bf9045797f
4
- data.tar.gz: 2d96914b228c7d641891c9476ed0de6a131a1b08
3
+ metadata.gz: 3314a1c9c8645eb3fedf8a478134e4c373b19030
4
+ data.tar.gz: 142e2b082c6d331cccb0cc9908a94cf636a21cfc
5
5
  SHA512:
6
- metadata.gz: 9b3e714e2800ce6f7225f382c1f472dbf61a8a02ab2495e76aa9e6225a74d453ba8fe80f743a0ed9365626814cd59f747ffe6fd6650b1d387122069effb799b3
7
- data.tar.gz: 0ba5b49728b7bf8de05ae2b18e50817a71e899d4d854aa9b6ed52233af517c79355bf6cd97565647c79fb4e5564fd94421c10b9a674af5b6554b8d6c6f1860e7
6
+ metadata.gz: a52f69616659d7bb3839678135e057d489b9131894d7df88bc40c4933dad4cebb172d2d8b1eeef8ff2b39a26114fe5e001cb888a4621ca63460159464eb4874d
7
+ data.tar.gz: 6b3ede167ad83aa224cc1bf2a33151fa4147cc3d7b5c8ee8f658ef28476ffd5896ad77922679cba05d0b29db2afbc4e5619ed115e8162251af80d587b7997939
@@ -89,6 +89,20 @@ module Settingable
89
89
  end
90
90
  end
91
91
 
92
+ # Converts this hash into a normal hash. Since we recursively
93
+ # converted every hash value into a {Settingable::Hash}, we have
94
+ # to undo that for the new hash.
95
+ #
96
+ # @return [::Hash]
97
+ def to_h
98
+ out = {}
99
+ each do |key, value|
100
+ out[key] = convert(value, true)
101
+ end
102
+
103
+ out
104
+ end
105
+
92
106
  private
93
107
 
94
108
  # Converts the value to a {Settingable::Hash}, if it is a regular
@@ -96,9 +110,9 @@ module Settingable
96
110
  #
97
111
  # @param value [Hash, Object]
98
112
  # @return [Settingable::Hash, Object]
99
- def convert(value)
113
+ def convert(value, invert = false)
100
114
  if value.is_a?(::Hash)
101
- Settingable::Hash.new(value)
115
+ invert ? value.to_h : Settingable::Hash.new(value)
102
116
  else
103
117
  value
104
118
  end
@@ -3,5 +3,5 @@
3
3
  # :nodoc:
4
4
  module Settingable
5
5
  # settingable version
6
- VERSION = "0.4.0"
6
+ VERSION = "0.5.0"
7
7
  end
@@ -21,6 +21,16 @@ RSpec.describe Settingable::Hash do
21
21
  end
22
22
  end
23
23
 
24
+ describe "#to_h" do
25
+ it "gives a regular hash" do
26
+ expect(subject.to_h).to be_a ::Hash
27
+ end
28
+
29
+ it "has regular hash values" do
30
+ expect(subject.to_h[:foo]).to be_a ::Hash
31
+ end
32
+ end
33
+
24
34
  describe "#[]=" do
25
35
  it "converts hash values" do
26
36
  subject[:hello] = { foo: { bar: "baz" } }
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: settingable
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.4.0
4
+ version: 0.5.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Jeremy Rodi