awrence 1.0.0 → 1.1.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +5 -5
- data/README.md +3 -4
- data/VERSION +1 -1
- data/lib/awrence.rb +2 -1
- data/lib/awrence/ext/array/to_camel_keys.rb +2 -2
- data/lib/awrence/ext/hash/to_camel_keys.rb +2 -2
- data/lib/awrence/methods.rb +29 -22
- data/lib/awrence/version.rb +4 -1
- metadata +21 -8
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
|
-
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
2
|
+
SHA256:
|
3
|
+
metadata.gz: d5ed1bafd204d0f5d584f47dbb0ef8f4c211031eda888920078104141823dfbd
|
4
|
+
data.tar.gz: d29a22a0c9f9f5e18a6b78de602b50ef4ac24a86b20c3512accc56ec55b6ab9d
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 4ca478ed67cf46ca895af7f75e41ce4639e945bea155a330730586625df465cced767d995dcdcedd223021ddd049f031b94b1c412c6c9b4de7a3f1e69c792f2a
|
7
|
+
data.tar.gz: 566e6cbf587fee37134913359821856021d1254a07e258594d25cac63885fcb9d458850bd7701e430ec6a04df54ea96948305939556d1a49a965ed34aef0a945
|
data/README.md
CHANGED
@@ -67,7 +67,7 @@ camel_hash = my_hash.to_camelback_keys
|
|
67
67
|
|
68
68
|
## Limitations
|
69
69
|
|
70
|
-
*
|
70
|
+
* There is no `Hash#to_camel_keys!` form.
|
71
71
|
|
72
72
|
# Going the other way
|
73
73
|
|
@@ -84,7 +84,6 @@ the [Plissken](http://github.com/futurechimp/plissken) gem.
|
|
84
84
|
* Make sure to add tests for it. This is important so I don't break it in a future version unintentionally.
|
85
85
|
* Please try not to mess with the Rakefile, version, or history. If you want to have your own version, or is otherwise necessary, that is fine, but please isolate to its own commit so I can cherry-pick around it.
|
86
86
|
|
87
|
-
|
87
|
+
# Copyright
|
88
88
|
|
89
|
-
Copyright (c) 2017 Dave Hrycyszyn. See LICENSE.txt for
|
90
|
-
further details.
|
89
|
+
Copyright (c) 2017 Dave Hrycyszyn. See LICENSE.txt for further details.
|
data/VERSION
CHANGED
@@ -1 +1 @@
|
|
1
|
-
1.
|
1
|
+
1.1.0
|
data/lib/awrence.rb
CHANGED
data/lib/awrence/methods.rb
CHANGED
@@ -2,18 +2,17 @@
|
|
2
2
|
|
3
3
|
module Awrence
|
4
4
|
module Methods
|
5
|
-
|
6
5
|
# Recursively converts Rubyish snake_case hash keys to camelBack JSON-style
|
7
6
|
# hash keys suitable for use with a JSON API.
|
8
7
|
#
|
9
8
|
def to_camelback_keys(value = self)
|
10
9
|
case value
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
|
10
|
+
when Array
|
11
|
+
value.map { |v| to_camelback_keys(v) }
|
12
|
+
when Hash
|
13
|
+
Hash[value.map { |k, v| [camelize_key(k, false), to_camelback_keys(v)] }]
|
14
|
+
else
|
15
|
+
value
|
17
16
|
end
|
18
17
|
end
|
19
18
|
|
@@ -22,32 +21,33 @@ module Awrence
|
|
22
21
|
#
|
23
22
|
def to_camel_keys(value = self)
|
24
23
|
case value
|
25
|
-
|
26
|
-
|
27
|
-
|
28
|
-
|
29
|
-
|
30
|
-
|
24
|
+
when Array
|
25
|
+
value.map { |v| to_camel_keys(v) }
|
26
|
+
when Hash
|
27
|
+
Hash[value.map { |k, v| [camelize_key(k), to_camel_keys(v)] }]
|
28
|
+
else
|
29
|
+
value
|
31
30
|
end
|
32
31
|
end
|
33
32
|
|
34
33
|
private
|
35
34
|
|
36
|
-
def camelize_key(
|
37
|
-
if
|
38
|
-
camelize(
|
39
|
-
elsif
|
40
|
-
camelize(
|
35
|
+
def camelize_key(key, first_upper = true)
|
36
|
+
if key.is_a? Symbol
|
37
|
+
camelize(key.to_s, first_upper).to_sym
|
38
|
+
elsif key.is_a? String
|
39
|
+
camelize(key, first_upper)
|
41
40
|
else
|
42
|
-
|
41
|
+
key # Awrence can't camelize anything except strings and symbols
|
43
42
|
end
|
44
43
|
end
|
45
44
|
|
46
45
|
def camelize(snake_word, first_upper = true)
|
47
46
|
if first_upper
|
48
|
-
snake_word.to_s
|
49
|
-
|
50
|
-
|
47
|
+
str = snake_word.to_s
|
48
|
+
str = gsubbed(str, /(?:^|_)([^_\s]+)/)
|
49
|
+
str = gsubbed(str, %r{/([^/]*)}, "::")
|
50
|
+
str
|
51
51
|
else
|
52
52
|
parts = snake_word.split("_", 2)
|
53
53
|
parts[0] << camelize(parts[1]) if parts.size > 1
|
@@ -55,5 +55,12 @@ module Awrence
|
|
55
55
|
end
|
56
56
|
end
|
57
57
|
|
58
|
+
def gsubbed(str, pattern, extra = "")
|
59
|
+
str = str.gsub(pattern) do
|
60
|
+
extra + (Awrence.acronyms[Regexp.last_match(1)] || Regexp.last_match(1).capitalize)
|
61
|
+
end
|
62
|
+
|
63
|
+
str
|
64
|
+
end
|
58
65
|
end
|
59
66
|
end
|
data/lib/awrence/version.rb
CHANGED
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: awrence
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 1.
|
4
|
+
version: 1.1.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Dave Hrycyszyn
|
@@ -9,7 +9,7 @@ authors:
|
|
9
9
|
autorequire:
|
10
10
|
bindir: bin
|
11
11
|
cert_chain: []
|
12
|
-
date:
|
12
|
+
date: 2019-01-14 00:00:00.000000000 Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: minitest
|
@@ -17,28 +17,42 @@ dependencies:
|
|
17
17
|
requirements:
|
18
18
|
- - "~>"
|
19
19
|
- !ruby/object:Gem::Version
|
20
|
-
version: '
|
20
|
+
version: '5.0'
|
21
21
|
type: :development
|
22
22
|
prerelease: false
|
23
23
|
version_requirements: !ruby/object:Gem::Requirement
|
24
24
|
requirements:
|
25
25
|
- - "~>"
|
26
26
|
- !ruby/object:Gem::Version
|
27
|
-
version: '
|
27
|
+
version: '5.0'
|
28
|
+
- !ruby/object:Gem::Dependency
|
29
|
+
name: minitest-fail-fast
|
30
|
+
requirement: !ruby/object:Gem::Requirement
|
31
|
+
requirements:
|
32
|
+
- - "~>"
|
33
|
+
- !ruby/object:Gem::Version
|
34
|
+
version: '0.1'
|
35
|
+
type: :development
|
36
|
+
prerelease: false
|
37
|
+
version_requirements: !ruby/object:Gem::Requirement
|
38
|
+
requirements:
|
39
|
+
- - "~>"
|
40
|
+
- !ruby/object:Gem::Version
|
41
|
+
version: '0.1'
|
28
42
|
- !ruby/object:Gem::Dependency
|
29
43
|
name: minitest-reporters
|
30
44
|
requirement: !ruby/object:Gem::Requirement
|
31
45
|
requirements:
|
32
46
|
- - "~>"
|
33
47
|
- !ruby/object:Gem::Version
|
34
|
-
version: '
|
48
|
+
version: '1.3'
|
35
49
|
type: :development
|
36
50
|
prerelease: false
|
37
51
|
version_requirements: !ruby/object:Gem::Requirement
|
38
52
|
requirements:
|
39
53
|
- - "~>"
|
40
54
|
- !ruby/object:Gem::Version
|
41
|
-
version: '
|
55
|
+
version: '1.3'
|
42
56
|
- !ruby/object:Gem::Dependency
|
43
57
|
name: rake
|
44
58
|
requirement: !ruby/object:Gem::Requirement
|
@@ -92,8 +106,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
92
106
|
- !ruby/object:Gem::Version
|
93
107
|
version: '0'
|
94
108
|
requirements: []
|
95
|
-
|
96
|
-
rubygems_version: 2.6.11
|
109
|
+
rubygems_version: 3.0.1
|
97
110
|
signing_key:
|
98
111
|
specification_version: 4
|
99
112
|
summary: Camelize your snake keys when working with JSON APIs
|