pandarus 0.6.0 → 0.6.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.
- checksums.yaml +4 -4
- data/lib/pandarus/api_base.rb +2 -2
- data/lib/pandarus/version.rb +1 -1
- data/spec/api_base_spec.rb +16 -2
- metadata +1 -1
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: eb117275ee83932fa8690bc9cb80edf68f1ef28e
|
4
|
+
data.tar.gz: f4e7c0c6be59acb8aa08826119f55a6a020945d1
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: c0870023cd3e7553079dce84eb953dfddf76e9cb06540c62aae7a1c4bdd9ef1038e9e17a3d2671ae68e783dd73f1f8e114a4acece3b89bce5bf27d9d2ede4a22
|
7
|
+
data.tar.gz: 0b123de59fa0cecd0fd0f222d28118806b001a86d72657f49ff6d3db7f242c446da5c095b81a07101fc40238476b5451928cce0fb78ec484eb6a7449fe963bd6
|
data/lib/pandarus/api_base.rb
CHANGED
@@ -65,7 +65,7 @@ module Pandarus
|
|
65
65
|
end
|
66
66
|
|
67
67
|
def dot_flatten_hash(hash)
|
68
|
-
Hash[
|
68
|
+
Hash[dot_flatten_recur(hash)]
|
69
69
|
end
|
70
70
|
|
71
71
|
def dot_flatten_recur(hash)
|
@@ -73,7 +73,7 @@ module Pandarus
|
|
73
73
|
if v1.is_a?(Hash)
|
74
74
|
dot_flatten_recur(v1).map do |k2, v2|
|
75
75
|
["#{k1}.#{k2}", v2]
|
76
|
-
end.flatten
|
76
|
+
end.flatten(1)
|
77
77
|
else
|
78
78
|
[k1, v1]
|
79
79
|
end
|
data/lib/pandarus/version.rb
CHANGED
data/spec/api_base_spec.rb
CHANGED
@@ -2,13 +2,13 @@ require_relative 'spec_helper'
|
|
2
2
|
require 'pandarus'
|
3
3
|
|
4
4
|
describe Pandarus::APIBase do
|
5
|
+
let(:base) { Pandarus::APIBase.new }
|
6
|
+
|
5
7
|
context "underscores_to_square_brackets" do
|
6
8
|
def u2sb(string)
|
7
9
|
base.send(:underscores_to_square_brackets, string)
|
8
10
|
end
|
9
11
|
|
10
|
-
let(:base) { Pandarus::APIBase.new }
|
11
|
-
|
12
12
|
it "converts surrounding double underscores" do
|
13
13
|
u2sb("prefix__inside__").should == :"prefix[inside]"
|
14
14
|
end
|
@@ -22,4 +22,18 @@ describe Pandarus::APIBase do
|
|
22
22
|
:"prefix[alpha][beta_gamma]"
|
23
23
|
end
|
24
24
|
end
|
25
|
+
|
26
|
+
context "dot_flatten_hash" do
|
27
|
+
it "turns a hash into dot notation" do
|
28
|
+
sample = { :user => { :name => "me" } }
|
29
|
+
result = base.send(:dot_flatten_hash, sample)
|
30
|
+
expect( result ).to eq({"user.name" => "me"})
|
31
|
+
end
|
32
|
+
|
33
|
+
it "turns a hash with array values into a hash" do
|
34
|
+
sample = { :user => { :ids => [1, 2, 3] }, :z => { :ids => [:a, :b] } }
|
35
|
+
result = base.send(:dot_flatten_hash, sample)
|
36
|
+
expect( result ).to eq({"user.ids" => [1, 2, 3], "z.ids" => [:a, :b]})
|
37
|
+
end
|
38
|
+
end
|
25
39
|
end
|