awrence 1.1.1 → 1.2.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/MIT-LICENSE +1 -1
- data/README.md +10 -12
- data/VERSION +1 -1
- data/lib/awrence/methods.rb +21 -26
- metadata +40 -12
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: f49788d1e0e12c23a9e0046b28a26b6205e9f5e1876073588d31c019c62bd4ba
|
4
|
+
data.tar.gz: 3eb67e0bcfdaa0d83789b7ffc84107c127ebbc79bb1dcdce6be13e66ee6e8d27
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 8fba35e04b34b8e45e10d33cde3b349433df9d6b85d8fc25228b485c91d46a32cdb1d1f114447bb9b59b789f617506c33984d5290e52a482e04fde538a15bd19
|
7
|
+
data.tar.gz: 1e781631f2a222d5856b1bd63f8853091ff0cada7bbec643307f2bf0a3a28cfc1bc0256e6b72ed23426b3828702853b6cc2f9af7c844f805561fe3c36424ade4
|
data/MIT-LICENSE
CHANGED
data/README.md
CHANGED
@@ -2,9 +2,9 @@
|
|
2
2
|
|
3
3
|
[![Gem Version](https://badge.fury.io/rb/awrence.svg)](https://badge.fury.io/rb/awrence)
|
4
4
|
|
5
|
-
Have you ever needed to automatically convert Rubyish `snake_case` to JSON-style `camelBack` or `CamelCase` hash keys?
|
5
|
+
Have you ever needed to automatically convert Rubyish `snake_case` to JSON-style `camelBack` or `CamelCase` hash keys?
|
6
6
|
|
7
|
-
Awrence to the rescue
|
7
|
+
Awrence to the rescue!
|
8
8
|
|
9
9
|
This gem recursively converts all snake_case keys in a hash structure to camelBack or CamelCase.
|
10
10
|
|
@@ -74,16 +74,14 @@ camel_hash = my_hash.to_camelback_keys
|
|
74
74
|
If you've already got `CamelCase` and need to `snake_case` it, you are encouraged to try
|
75
75
|
the [Plissken](http://github.com/futurechimp/plissken) gem.
|
76
76
|
|
77
|
-
## Contributing
|
77
|
+
## Contributing
|
78
78
|
|
79
|
-
|
80
|
-
* Check out the issue tracker to make sure someone already hasn't requested it and/or contributed it.
|
81
|
-
* Fork the project.
|
82
|
-
* Start a feature/bugfix branch.
|
83
|
-
* Commit and push until you are happy with your contribution.
|
84
|
-
* Make sure to add tests for it. This is important so I don't break it in a future version unintentionally.
|
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.
|
79
|
+
Bug reports and pull requests are welcome on GitHub at https://github.com/technicalpanda/awrence. This project is intended to be a safe, welcoming space for collaboration, and contributors are expected to adhere to the [Contributor Covenant](http://contributor-covenant.org) code of conduct.
|
86
80
|
|
87
|
-
|
81
|
+
## License
|
88
82
|
|
89
|
-
|
83
|
+
The gem is available as open source under the terms of the [MIT License](https://opensource.org/licenses/MIT).
|
84
|
+
|
85
|
+
## Code of Conduct
|
86
|
+
|
87
|
+
Everyone interacting with this project’s codebases, issue trackers, chat rooms and mailing lists is expected to follow the [code of conduct](https://github.com/technicalpanda/awrence/blob/main/CODE_OF_CONDUCT.md).
|
data/VERSION
CHANGED
@@ -1 +1 @@
|
|
1
|
-
1.
|
1
|
+
1.2.0
|
data/lib/awrence/methods.rb
CHANGED
@@ -6,48 +6,34 @@ module Awrence
|
|
6
6
|
# hash keys suitable for use with a JSON API.
|
7
7
|
#
|
8
8
|
def to_camelback_keys(value = self)
|
9
|
-
|
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
|
16
|
-
end
|
9
|
+
process_value(:to_camelback_keys, value, first_upper: false)
|
17
10
|
end
|
18
11
|
|
19
12
|
# Recursively converts Rubyish snake_case hash keys to CamelCase JSON-style
|
20
13
|
# hash keys suitable for use with a JSON API.
|
21
14
|
#
|
22
15
|
def to_camel_keys(value = self)
|
23
|
-
|
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
|
30
|
-
end
|
16
|
+
process_value(:to_camel_keys, value, first_upper: true)
|
31
17
|
end
|
32
18
|
|
33
19
|
private
|
34
20
|
|
35
|
-
def camelize_key(key, first_upper
|
36
|
-
|
37
|
-
|
38
|
-
|
39
|
-
|
21
|
+
def camelize_key(key, first_upper: true)
|
22
|
+
case key
|
23
|
+
when Symbol
|
24
|
+
camelize(key.to_s, first_upper: first_upper).to_sym
|
25
|
+
when String
|
26
|
+
camelize(key, first_upper: first_upper)
|
40
27
|
else
|
41
28
|
key # Awrence can't camelize anything except strings and symbols
|
42
29
|
end
|
43
30
|
end
|
44
31
|
|
45
|
-
def camelize(snake_word, first_upper
|
32
|
+
def camelize(snake_word, first_upper: true)
|
46
33
|
if first_upper
|
47
34
|
str = snake_word.to_s
|
48
35
|
str = gsubbed(str, /(?:^|_)([^_\s]+)/)
|
49
|
-
|
50
|
-
str
|
36
|
+
gsubbed(str, %r{/([^/]*)}, "::")
|
51
37
|
else
|
52
38
|
parts = snake_word.split("_", 2)
|
53
39
|
parts[0] << camelize(parts[1]) if parts.size > 1
|
@@ -56,11 +42,20 @@ module Awrence
|
|
56
42
|
end
|
57
43
|
|
58
44
|
def gsubbed(str, pattern, extra = "")
|
59
|
-
str
|
45
|
+
str.gsub(pattern) do
|
60
46
|
extra + (Awrence.acronyms[Regexp.last_match(1)] || Regexp.last_match(1).capitalize)
|
61
47
|
end
|
48
|
+
end
|
62
49
|
|
63
|
-
|
50
|
+
def process_value(method, value, first_upper: true)
|
51
|
+
case value
|
52
|
+
when Array
|
53
|
+
value.map { |v| send(method, v) }
|
54
|
+
when Hash
|
55
|
+
Hash[value.map { |k, v| [camelize_key(k, first_upper: first_upper), send(method, v)] }]
|
56
|
+
else
|
57
|
+
value
|
58
|
+
end
|
64
59
|
end
|
65
60
|
end
|
66
61
|
end
|
metadata
CHANGED
@@ -1,15 +1,15 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: awrence
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 1.
|
4
|
+
version: 1.2.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Dave Hrycyszyn
|
8
8
|
- Stuart Chinery
|
9
|
-
autorequire:
|
9
|
+
autorequire:
|
10
10
|
bindir: bin
|
11
11
|
cert_chain: []
|
12
|
-
date:
|
12
|
+
date: 2021-02-01 00:00:00.000000000 Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: byebug
|
@@ -101,14 +101,42 @@ dependencies:
|
|
101
101
|
requirements:
|
102
102
|
- - "~>"
|
103
103
|
- !ruby/object:Gem::Version
|
104
|
-
version: '
|
104
|
+
version: '1.7'
|
105
105
|
type: :development
|
106
106
|
prerelease: false
|
107
107
|
version_requirements: !ruby/object:Gem::Requirement
|
108
108
|
requirements:
|
109
109
|
- - "~>"
|
110
110
|
- !ruby/object:Gem::Version
|
111
|
-
version: '
|
111
|
+
version: '1.7'
|
112
|
+
- !ruby/object:Gem::Dependency
|
113
|
+
name: rubocop-minitest
|
114
|
+
requirement: !ruby/object:Gem::Requirement
|
115
|
+
requirements:
|
116
|
+
- - "~>"
|
117
|
+
- !ruby/object:Gem::Version
|
118
|
+
version: '0.10'
|
119
|
+
type: :development
|
120
|
+
prerelease: false
|
121
|
+
version_requirements: !ruby/object:Gem::Requirement
|
122
|
+
requirements:
|
123
|
+
- - "~>"
|
124
|
+
- !ruby/object:Gem::Version
|
125
|
+
version: '0.10'
|
126
|
+
- !ruby/object:Gem::Dependency
|
127
|
+
name: rubocop-rake
|
128
|
+
requirement: !ruby/object:Gem::Requirement
|
129
|
+
requirements:
|
130
|
+
- - "~>"
|
131
|
+
- !ruby/object:Gem::Version
|
132
|
+
version: '0.5'
|
133
|
+
type: :development
|
134
|
+
prerelease: false
|
135
|
+
version_requirements: !ruby/object:Gem::Requirement
|
136
|
+
requirements:
|
137
|
+
- - "~>"
|
138
|
+
- !ruby/object:Gem::Version
|
139
|
+
version: '0.5'
|
112
140
|
description: |-
|
113
141
|
Have you ever needed to automatically convert Ruby-style snake_case to CamelCase or camelBack hash keys?
|
114
142
|
|
@@ -116,8 +144,8 @@ description: |-
|
|
116
144
|
|
117
145
|
This gem recursively converts all snake_case keys in a hash structure to camelBack.
|
118
146
|
email:
|
119
|
-
-
|
120
|
-
-
|
147
|
+
- dave@constructiveproof.com
|
148
|
+
- code@technicalpanda.co.uk
|
121
149
|
executables: []
|
122
150
|
extensions: []
|
123
151
|
extra_rdoc_files: []
|
@@ -131,11 +159,11 @@ files:
|
|
131
159
|
- lib/awrence/ext/hash/to_camel_keys.rb
|
132
160
|
- lib/awrence/methods.rb
|
133
161
|
- lib/awrence/version.rb
|
134
|
-
homepage: https://github.com/
|
162
|
+
homepage: https://github.com/technicalpanda/awrence
|
135
163
|
licenses:
|
136
164
|
- MIT
|
137
165
|
metadata: {}
|
138
|
-
post_install_message:
|
166
|
+
post_install_message:
|
139
167
|
rdoc_options: []
|
140
168
|
require_paths:
|
141
169
|
- lib
|
@@ -143,15 +171,15 @@ required_ruby_version: !ruby/object:Gem::Requirement
|
|
143
171
|
requirements:
|
144
172
|
- - ">="
|
145
173
|
- !ruby/object:Gem::Version
|
146
|
-
version: '
|
174
|
+
version: '2.5'
|
147
175
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
148
176
|
requirements:
|
149
177
|
- - ">="
|
150
178
|
- !ruby/object:Gem::Version
|
151
179
|
version: '0'
|
152
180
|
requirements: []
|
153
|
-
rubygems_version: 3.1.
|
154
|
-
signing_key:
|
181
|
+
rubygems_version: 3.1.4
|
182
|
+
signing_key:
|
155
183
|
specification_version: 4
|
156
184
|
summary: Camelize your snake keys when working with JSON APIs
|
157
185
|
test_files: []
|