cistern 0.7.1 → 0.8.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 +4 -4
- data/lib/cistern/hash.rb +12 -1
- data/lib/cistern/version.rb +1 -1
- data/spec/cistern_hash_spec.rb +37 -0
- metadata +4 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 9d585ea5371e0aacb6be60961d9f84092f33e44b
|
4
|
+
data.tar.gz: 03cea31b26b0a9ffab12c9d5e676297fb671ed35
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: e968344a6b10ace08f87ba1222b5fdd8b8bacc5593733624ea53f818d9faef2d81822171d20ac12aa0163fd7778856b402078a3527bb3d5049be306b8f063a02
|
7
|
+
data.tar.gz: 99301cc7e296366fc8cab118e1c876e09f092218a8328df6936e37bcc50ccf08d39bca08f6eff9f70ce30556130584aa929566d47e03aec94128ed9dcbf5e54d
|
data/lib/cistern/hash.rb
CHANGED
@@ -1,7 +1,18 @@
|
|
1
1
|
class Cistern::Hash
|
2
2
|
def self.slice(hash, *keys)
|
3
3
|
{}.tap do |sliced|
|
4
|
-
keys.each{|k| sliced[k]= hash[k] if hash.key?(k)}
|
4
|
+
keys.each{ |k| sliced[k] = hash[k] if hash.key?(k) }
|
5
|
+
end
|
6
|
+
end
|
7
|
+
|
8
|
+
def self.stringify_keys(object)
|
9
|
+
case object
|
10
|
+
when Hash
|
11
|
+
object.inject({}){|r,(k,v)| r.merge(k.to_s => stringify_keys(v))}
|
12
|
+
when Array
|
13
|
+
object.map{|v| stringify_keys(v) }
|
14
|
+
else
|
15
|
+
object
|
5
16
|
end
|
6
17
|
end
|
7
18
|
end
|
data/lib/cistern/version.rb
CHANGED
@@ -0,0 +1,37 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
describe "cistern hashes" do
|
4
|
+
describe "#slice" do
|
5
|
+
let(:input) do
|
6
|
+
{ one: "one", two: "two", three: "three" }
|
7
|
+
end
|
8
|
+
|
9
|
+
it "returns a new hash with only the specified keys" do
|
10
|
+
expect(Cistern::Hash.slice(input, :one, :two)).to eq({ one: "one", two: "two" })
|
11
|
+
end
|
12
|
+
|
13
|
+
it "skips keys that aren't in the original hash" do
|
14
|
+
expect(Cistern::Hash.slice(input, :four)).to eq({})
|
15
|
+
end
|
16
|
+
end
|
17
|
+
|
18
|
+
describe "#stringify_keys" do
|
19
|
+
let(:input) do
|
20
|
+
{ one: "one", two: "two" }
|
21
|
+
end
|
22
|
+
|
23
|
+
it "returns a new hash with stringed keys" do
|
24
|
+
expect(Cistern::Hash.stringify_keys(input)).to eq({ "one" => "one", "two" => "two" })
|
25
|
+
end
|
26
|
+
|
27
|
+
context "with nested hashes or arrays" do
|
28
|
+
let(:input) do
|
29
|
+
{ hash: { one: "one" }, array: [{ two: "two" }] }
|
30
|
+
end
|
31
|
+
|
32
|
+
it "stringifies all of the keys" do
|
33
|
+
expect(Cistern::Hash.stringify_keys(input)).to eq({ "hash" => { "one" => "one" }, "array" => [{ "two" => "two" }]})
|
34
|
+
end
|
35
|
+
end
|
36
|
+
end
|
37
|
+
end
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: cistern
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.8.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Josh Lane
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2014-
|
11
|
+
date: 2014-06-13 00:00:00.000000000 Z
|
12
12
|
dependencies: []
|
13
13
|
description: API client framework extracted from Fog
|
14
14
|
email:
|
@@ -44,6 +44,7 @@ files:
|
|
44
44
|
- lib/cistern/timeout.rb
|
45
45
|
- lib/cistern/version.rb
|
46
46
|
- lib/cistern/wait_for.rb
|
47
|
+
- spec/cistern_hash_spec.rb
|
47
48
|
- spec/cistern_spec.rb
|
48
49
|
- spec/collection_spec.rb
|
49
50
|
- spec/mock_data_spec.rb
|
@@ -76,6 +77,7 @@ signing_key:
|
|
76
77
|
specification_version: 4
|
77
78
|
summary: API client framework
|
78
79
|
test_files:
|
80
|
+
- spec/cistern_hash_spec.rb
|
79
81
|
- spec/cistern_spec.rb
|
80
82
|
- spec/collection_spec.rb
|
81
83
|
- spec/mock_data_spec.rb
|