awrence 1.1.1 → 1.2.1
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 +11 -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: 6ea9ffe08685c4d1f7d302efaf13077b4cf86908fce25dd6dac706e9f832b39e
|
4
|
+
data.tar.gz: a9c44ac2fd6134e5063c30eb924fdbf2a44a6652d956b467a8324bd4065034f1
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 9da5f704603f55dbf0220554da57c448bedff741751b66836e22a69bbdef9498938cc7149dbbcb036c2808b650024e6ad90875510986f4c675b0b482ec2aae56
|
7
|
+
data.tar.gz: 4b97555cb25181c0dadd271b3c2c4b22fd0cf2c5f06b826f7f87f9282b1f7afb3f78c3c7465ede8ec3e1e48084458b4e99a4a6bed3e026c1ff6942f1b5b8e05e
|
data/MIT-LICENSE
CHANGED
data/README.md
CHANGED
@@ -1,10 +1,11 @@
|
|
1
1
|
# Awrence
|
2
2
|
|
3
3
|
[![Gem Version](https://badge.fury.io/rb/awrence.svg)](https://badge.fury.io/rb/awrence)
|
4
|
+
![CI](https://github.com/technicalpanda/awrence/workflows/CI/badge.svg)
|
4
5
|
|
5
|
-
Have you ever needed to automatically convert Rubyish `snake_case` to JSON-style `camelBack` or `CamelCase` hash keys?
|
6
|
+
Have you ever needed to automatically convert Rubyish `snake_case` to JSON-style `camelBack` or `CamelCase` hash keys?
|
6
7
|
|
7
|
-
Awrence to the rescue
|
8
|
+
Awrence to the rescue!
|
8
9
|
|
9
10
|
This gem recursively converts all snake_case keys in a hash structure to camelBack or CamelCase.
|
10
11
|
|
@@ -74,16 +75,14 @@ camel_hash = my_hash.to_camelback_keys
|
|
74
75
|
If you've already got `CamelCase` and need to `snake_case` it, you are encouraged to try
|
75
76
|
the [Plissken](http://github.com/futurechimp/plissken) gem.
|
76
77
|
|
77
|
-
## Contributing
|
78
|
+
## Contributing
|
78
79
|
|
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.
|
80
|
+
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
81
|
|
87
|
-
|
82
|
+
## License
|
88
83
|
|
89
|
-
|
84
|
+
The gem is available as open source under the terms of the [MIT License](https://opensource.org/licenses/MIT).
|
85
|
+
|
86
|
+
## Code of Conduct
|
87
|
+
|
88
|
+
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.1
|
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
|
+
value.map { |k, v| [camelize_key(k, first_upper: first_upper), send(method, v)] }.to_h
|
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.1
|
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-18 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: []
|