snake-eyes 0.0.6 → 0.0.7
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/README.md +21 -1
- data/lib/snake-eyes/interface_changes.rb +16 -19
- data/lib/snake-eyes/version.rb +1 -1
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 608b97ebdffcc0a5e2c79262979b570ea455963f
|
4
|
+
data.tar.gz: 622937869fcafdccbf955b96d682b0472731c615
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: f1b4e57dbe7aa3fcb3c627bdd7792d9053661f19119773515cd0122eb3115dab84f6f17be9e53f89b52e379b329ce2511cc16dee63f1c8ede5434d8983db2bd8
|
7
|
+
data.tar.gz: 2d8da38d611a261a32011bf6a9d59de6e161fc4766e5c6acd6ddf0679e349e1ac1f7f44ba1ef83c9d8a2ce7bebb1656caecdb9a813e69981cb43f751fff0f3e3
|
data/README.md
CHANGED
@@ -8,6 +8,8 @@ Automatically convert between camel case APIs to snake case for your Rails code
|
|
8
8
|
|
9
9
|
If you are using a version below `0.0.4`, please upgrade to avoid [potentially logging sensitive user information](https://github.com/greena13/snake-eyes/issues/1)
|
10
10
|
|
11
|
+
🚧🚧🚧🚧🚧🚧🚧🚧🚧🚧🚧🚧🚧🚧🚧🚧🚧🚧🚧
|
12
|
+
|
11
13
|
## Installation
|
12
14
|
|
13
15
|
Add this line to your application's Gemfile:
|
@@ -27,7 +29,7 @@ class JsonController < ApplicationController
|
|
27
29
|
snake_eyes_params
|
28
30
|
|
29
31
|
def show
|
30
|
-
#reference the params
|
32
|
+
#reference the params method as normal
|
31
33
|
end
|
32
34
|
end
|
33
35
|
```
|
@@ -90,6 +92,24 @@ To specify nested objects that should not have the `_attributes` suffix (but con
|
|
90
92
|
end
|
91
93
|
```
|
92
94
|
|
95
|
+
## Limitations
|
96
|
+
|
97
|
+
SnakeEyes does *not* currently handle the following aspects of converting a JSON API to a Rails-compatible one:
|
98
|
+
|
99
|
+
**Converting arrays of objects to hashes, keyed by item indexes**
|
100
|
+
|
101
|
+
Fox example:
|
102
|
+
|
103
|
+
```JSON
|
104
|
+
{
|
105
|
+
"a": [
|
106
|
+
{ "b": 1 },
|
107
|
+
{ "b": 2 },
|
108
|
+
{ "b": 3 }
|
109
|
+
]
|
110
|
+
}
|
111
|
+
```
|
112
|
+
|
93
113
|
## Configuration
|
94
114
|
|
95
115
|
By default SnakeEyes logs the snake case parameters to the Rails console. You can prevent this behaviour by configuring the gem:
|
@@ -24,7 +24,7 @@ module SnakeEyes
|
|
24
24
|
|
25
25
|
@previous_params ||= { }
|
26
26
|
|
27
|
-
return @previous_params[nested_schema] if @previous_params[nested_schema]
|
27
|
+
# return @previous_params[nested_schema] if @previous_params[nested_schema]
|
28
28
|
|
29
29
|
# Similar to original_params_sub_trees, a list of subtrees used to maintain
|
30
30
|
# the traversal position of nested_schema. This is kept in sync with the
|
@@ -36,8 +36,18 @@ module SnakeEyes
|
|
36
36
|
]
|
37
37
|
|
38
38
|
transformed_params = original_params.deep_transform_keys do |original_key|
|
39
|
-
#
|
40
|
-
|
39
|
+
# Synchronise the original params sub-tree with the current key being
|
40
|
+
# transformed. We can detect that the sub-tree is stale because the key
|
41
|
+
# being transformed does not appear amongst its own. When the sub-tree is
|
42
|
+
# indeed stale, move the position to its parent for the original params
|
43
|
+
# sub-tree and the nested schema sub-tree and repeat the check.
|
44
|
+
|
45
|
+
while original_params_sub_trees.length > 1 && original_params_sub_trees.last[original_key].nil?
|
46
|
+
original_params_sub_trees.pop
|
47
|
+
nested_schema_sub_trees.pop
|
48
|
+
end
|
49
|
+
|
50
|
+
original_params_sub_tree = original_params_sub_trees.last[original_key]
|
41
51
|
|
42
52
|
# Append the '_attributes' suffix if the original params key has the
|
43
53
|
# same name and is nested in the same place as one mentioned in the
|
@@ -46,31 +56,18 @@ module SnakeEyes
|
|
46
56
|
transformed_key_base = original_key.underscore
|
47
57
|
|
48
58
|
transformed_key =
|
49
|
-
if
|
59
|
+
if nested_schema_sub_trees.last[transformed_key_base]
|
50
60
|
transformed_key_base + '_attributes'
|
51
61
|
else
|
52
62
|
transformed_key_base
|
53
63
|
end
|
54
64
|
|
55
|
-
# Synchronise the original params sub-tree with the current key being
|
56
|
-
# transformed. We can detect that the sub-tree is stale because the key
|
57
|
-
# being transformed does not appear amongst its own. When the sub-tree is
|
58
|
-
# indeed stale, move the position to its parent for the original params
|
59
|
-
# sub-tree and the nested schema sub-tree and repeat the check.
|
60
|
-
|
61
|
-
while original_params_sub_trees.length > 1 && original_params_sub_trees.last[original_key].nil?
|
62
|
-
original_params_sub_trees.pop
|
63
|
-
nested_schema_sub_trees.pop
|
64
|
-
end
|
65
|
-
|
66
|
-
original_params_sub_tree = original_params_sub_trees.last[transformed_key_base]
|
67
|
-
|
68
65
|
if original_params_sub_tree.kind_of?(Hash)
|
69
66
|
original_params_sub_trees.push(original_params_sub_tree)
|
70
67
|
|
71
68
|
nested_schema_sub_trees.push(
|
72
|
-
|
73
|
-
|
69
|
+
nested_schema_sub_trees.last[transformed_key_base] ||
|
70
|
+
nested_schema_sub_trees.last['_' + transformed_key_base] ||
|
74
71
|
{}
|
75
72
|
)
|
76
73
|
end
|
data/lib/snake-eyes/version.rb
CHANGED
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: snake-eyes
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0.
|
4
|
+
version: 0.0.7
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Aleck Greenham
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2017-07-
|
11
|
+
date: 2017-07-31 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: bundler
|