camel_snake_keys 0.0.4 → 0.0.5
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.rubocop.yml +14 -5
- data/.travis.yml +2 -1
- data/Gemfile +4 -4
- data/README.md +4 -9
- data/camel_snake.gemspec +1 -0
- data/lib/camel_snake_keys.rb +14 -10
- data/lib/version.rb +1 -1
- data/spec/lib/camel_snake_keys_spec.rb +2 -0
- metadata +17 -3
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: b21140710746cd5e5d82b5f063b4654126df61f9
|
4
|
+
data.tar.gz: e1714386e270c31d3dd6054fb3f923d74138eeca
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 239f2025330fe5ed5a4bc0d4359905009e9dee60dfe4124ceafefa05f4fa193aa507d89558667925f9bcaf3358e9618bf211c13297b0c37ebf2e54e4ab9a4716
|
7
|
+
data.tar.gz: 31f4b8bf86703c297e0675898d9ed66a7e1a1f2fba4000f0fe4e9c785ffa90b8afc29574877cb5e1371c7484bf1a547b5a47eef47eae8919437dd9594ea21686
|
data/.rubocop.yml
CHANGED
@@ -536,10 +536,10 @@ Style/DefWithParentheses:
|
|
536
536
|
StyleGuide: 'https://github.com/bbatsov/ruby-style-guide#method-parens'
|
537
537
|
Enabled: false
|
538
538
|
|
539
|
-
Style/DeprecatedHashMethods:
|
540
|
-
Description: 'Checks for use of deprecated Hash methods.'
|
541
|
-
StyleGuide: 'https://github.com/bbatsov/ruby-style-guide#hash-key'
|
542
|
-
Enabled: false
|
539
|
+
#Style/DeprecatedHashMethods:
|
540
|
+
# Description: 'Checks for use of deprecated Hash methods.'
|
541
|
+
# StyleGuide: 'https://github.com/bbatsov/ruby-style-guide#hash-key'
|
542
|
+
# Enabled: false
|
543
543
|
|
544
544
|
Style/Documentation:
|
545
545
|
Description: 'Document classes and non-namespace modules.'
|
@@ -724,7 +724,7 @@ Style/LineEndConcatenation:
|
|
724
724
|
line end.
|
725
725
|
Enabled: false
|
726
726
|
|
727
|
-
Style/
|
727
|
+
Style/MethodCallWithoutArgsParentheses:
|
728
728
|
Description: 'Do not use parentheses for method calls with no arguments.'
|
729
729
|
StyleGuide: 'https://github.com/bbatsov/ruby-style-guide#no-args-no-parens'
|
730
730
|
Enabled: false
|
@@ -810,6 +810,10 @@ Style/Not:
|
|
810
810
|
StyleGuide: 'https://github.com/bbatsov/ruby-style-guide#bang-not-not'
|
811
811
|
Enabled: false
|
812
812
|
|
813
|
+
Style/NumericPredicate:
|
814
|
+
Exclude:
|
815
|
+
- 'spec/**/*'
|
816
|
+
|
813
817
|
Style/NumericLiterals:
|
814
818
|
Description: >-
|
815
819
|
Add underscores to large numeric literals to improve their
|
@@ -1162,3 +1166,8 @@ Style/WordArray:
|
|
1162
1166
|
Description: 'Use %w or %W for arrays of words.'
|
1163
1167
|
StyleGuide: 'https://github.com/bbatsov/ruby-style-guide#percent-w'
|
1164
1168
|
Enabled: false
|
1169
|
+
|
1170
|
+
Style/BlockLength:
|
1171
|
+
Exclude:
|
1172
|
+
- '*.gemspec'
|
1173
|
+
- 'spec/**/*'
|
data/.travis.yml
CHANGED
@@ -7,6 +7,7 @@ script:
|
|
7
7
|
- bundle exec rspec
|
8
8
|
|
9
9
|
rvm:
|
10
|
+
- 2.3.0
|
10
11
|
- 2.2
|
11
12
|
- 2.1
|
12
13
|
- 2.0.0
|
@@ -23,7 +24,7 @@ env:
|
|
23
24
|
matrix:
|
24
25
|
- RAILS=3.2.22
|
25
26
|
- RAILS=4.1.13
|
26
|
-
- RAILS=4.2.
|
27
|
+
- RAILS=4.2.7.1
|
27
28
|
- RAILS=master
|
28
29
|
global:
|
29
30
|
- JRUBY_OPTS="-J-Xmx1024m --debug"
|
data/Gemfile
CHANGED
data/README.md
CHANGED
@@ -17,24 +17,19 @@
|
|
17
17
|
[CS img]: https://coveralls.io/repos/buermann/camel_snake_keys/badge.png?branch=master
|
18
18
|
|
19
19
|
|
20
|
-
Add recursive with_snake_keys and with_camel_keys to
|
20
|
+
Add recursive with_snake_keys and with_camel_keys refinements to Array and Hash. Preserve strings and symbols and treat hash descendents such as ActiveSupport::HashWithIndifferentAccess and Hashie::Mash agnostically.
|
21
21
|
|
22
22
|
## Documentation
|
23
23
|
|
24
|
-
Add `gem 'camel_snake_keys'` to your Gemfile or gem install camel_snake_keys.
|
25
|
-
|
26
|
-
Enumerables will be monkey patched the following methods:
|
27
|
-
|
28
|
-
```
|
29
|
-
with_snake_keys(with_indifferent=false)
|
30
|
-
with_camel_keys(with_indifferent=false)
|
31
|
-
```
|
24
|
+
Add `gem 'camel_snake_keys'` to your Gemfile or gem install camel_snake_keys. Where you want to add `with_snake_keys` and `with_camel_keys` to your objects invoke `using CamelSnakeKeys`, or invoke the class methods, `CamelSnakeKeys.camel_keys(object, with_indifference)` and `CamelSnakeKeys.snake_keys(object, with_indifference)`.
|
32
25
|
|
33
26
|
If with_indifference is set to a true value hashes will be returned as ActiveSupport's HashWithIndifferentAccess.
|
34
27
|
|
35
28
|
```
|
36
29
|
require 'camel_snake_keys'
|
37
30
|
|
31
|
+
using CamelSnakeKeys
|
32
|
+
|
38
33
|
{fooBar: "Frob"}.with_snake_keys
|
39
34
|
=> {:foo_bar=>"Frob"}
|
40
35
|
|
data/camel_snake.gemspec
CHANGED
data/lib/camel_snake_keys.rb
CHANGED
@@ -2,6 +2,18 @@ require 'active_support/core_ext/hash'
|
|
2
2
|
require 'active_support/core_ext/string/inflections'
|
3
3
|
|
4
4
|
module CamelSnakeKeys
|
5
|
+
[Hash,Array].each do |klass|
|
6
|
+
refine klass do
|
7
|
+
def with_camel_keys(indifference=false)
|
8
|
+
CamelSnakeKeys.camel_keys(self, indifference)
|
9
|
+
end
|
10
|
+
|
11
|
+
def with_snake_keys(indifference=false)
|
12
|
+
CamelSnakeKeys.snake_keys(self, indifference)
|
13
|
+
end
|
14
|
+
end
|
15
|
+
end
|
16
|
+
|
5
17
|
class << self
|
6
18
|
def if_underscore(v)
|
7
19
|
if v.is_a? Symbol
|
@@ -27,7 +39,7 @@ module CamelSnakeKeys
|
|
27
39
|
if data.kind_of? Array
|
28
40
|
data.map { |v| snake_keys(v) }
|
29
41
|
elsif data.kind_of? Hash
|
30
|
-
hash = Hash[data.sort_by {|k,
|
42
|
+
hash = Hash[data.sort_by {|k,_v| k =~ /_/ ? 0 : 1 }.map {|k, v| [if_underscore(k), snake_keys(v)] }]
|
31
43
|
hash = hash.with_indifferent_access if indifference
|
32
44
|
data.class == Hash ? hash : data.class.new(hash)
|
33
45
|
else
|
@@ -39,7 +51,7 @@ module CamelSnakeKeys
|
|
39
51
|
if data.kind_of? Array
|
40
52
|
data.map { |v| camel_keys(v) }
|
41
53
|
elsif data.kind_of? Hash
|
42
|
-
hash = Hash[data.sort_by {|k,
|
54
|
+
hash = Hash[data.sort_by {|k,_v| k =~ /_/ ? 1 : 0 }.map {|k, v| [if_camelize(k), camel_keys(v)] }]
|
43
55
|
hash = hash.with_indifferent_access if indifference
|
44
56
|
data.class == Hash ? hash : data.class.new(hash)
|
45
57
|
else
|
@@ -49,12 +61,4 @@ module CamelSnakeKeys
|
|
49
61
|
end
|
50
62
|
end
|
51
63
|
|
52
|
-
module Enumerable
|
53
|
-
def with_camel_keys(indifference=false)
|
54
|
-
CamelSnakeKeys.camel_keys(self, indifference)
|
55
|
-
end
|
56
64
|
|
57
|
-
def with_snake_keys(indifference=false)
|
58
|
-
CamelSnakeKeys.snake_keys(self, indifference)
|
59
|
-
end
|
60
|
-
end
|
data/lib/version.rb
CHANGED
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: camel_snake_keys
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0.
|
4
|
+
version: 0.0.5
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Josh Buermann
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date:
|
11
|
+
date: 2017-04-06 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: activesupport
|
@@ -38,6 +38,20 @@ dependencies:
|
|
38
38
|
- - ">="
|
39
39
|
- !ruby/object:Gem::Version
|
40
40
|
version: '3.0'
|
41
|
+
- !ruby/object:Gem::Dependency
|
42
|
+
name: activesupport
|
43
|
+
requirement: !ruby/object:Gem::Requirement
|
44
|
+
requirements:
|
45
|
+
- - "~>"
|
46
|
+
- !ruby/object:Gem::Version
|
47
|
+
version: '4.2'
|
48
|
+
type: :development
|
49
|
+
prerelease: false
|
50
|
+
version_requirements: !ruby/object:Gem::Requirement
|
51
|
+
requirements:
|
52
|
+
- - "~>"
|
53
|
+
- !ruby/object:Gem::Version
|
54
|
+
version: '4.2'
|
41
55
|
description: ''
|
42
56
|
email:
|
43
57
|
- buermann@gmail.com
|
@@ -78,7 +92,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
78
92
|
version: '0'
|
79
93
|
requirements: []
|
80
94
|
rubyforge_project:
|
81
|
-
rubygems_version: 2.
|
95
|
+
rubygems_version: 2.6.10
|
82
96
|
signing_key:
|
83
97
|
specification_version: 4
|
84
98
|
summary: Convert nested data structure hash keys between camel and snake case.
|