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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 67133b9825da574c91e2aee2abb4f3d95075bfc5
4
- data.tar.gz: ccc58c05bc58e0b1419b977ad81990051fde836b
3
+ metadata.gz: 9d585ea5371e0aacb6be60961d9f84092f33e44b
4
+ data.tar.gz: 03cea31b26b0a9ffab12c9d5e676297fb671ed35
5
5
  SHA512:
6
- metadata.gz: fbfdeb319884379d2396b471a601c227a6c76b95b257d4f0f91a5d9672e6a51ddb128a8b023d5d3d3e2cb91c7f875ff855a609405f7cd3119de231c9b45f1c73
7
- data.tar.gz: 87af628f6c06d0bda4e6bb90170ce454c2a224fb177e589efbaced7f999778124420366ed85cad7e0bd43f0df5da1c20d687cbae8fa33af32eb9540bb6e1917c
6
+ metadata.gz: e968344a6b10ace08f87ba1222b5fdd8b8bacc5593733624ea53f818d9faef2d81822171d20ac12aa0163fd7778856b402078a3527bb3d5049be306b8f063a02
7
+ data.tar.gz: 99301cc7e296366fc8cab118e1c876e09f092218a8328df6936e37bcc50ccf08d39bca08f6eff9f70ce30556130584aa929566d47e03aec94128ed9dcbf5e54d
@@ -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
@@ -1,3 +1,3 @@
1
1
  module Cistern
2
- VERSION = "0.7.1"
2
+ VERSION = "0.8.0"
3
3
  end
@@ -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.7.1
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-05-18 00:00:00.000000000 Z
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