plissken 1.1.0 → 1.4.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +5 -5
- data/MIT-LICENSE +20 -0
- data/README.md +25 -15
- data/Rakefile +3 -1
- data/VERSION +1 -1
- data/lib/plissken.rb +5 -2
- data/lib/plissken/ext/array/to_snake_keys.rb +5 -0
- data/lib/plissken/ext/hash/to_snake_keys.rb +1 -43
- data/lib/plissken/methods.rb +51 -0
- data/lib/plissken/version.rb +4 -1
- metadata +103 -17
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
|
-
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
2
|
+
SHA256:
|
3
|
+
metadata.gz: 38db0a3758d33d97146f2356ad5b2ecc4727e4ebab65d15f7007d3c55bb745d9
|
4
|
+
data.tar.gz: d23380751b6ba823e77eeee5fb01dbc97bff480e5bce15f99caa76c6426f88bd
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 34db145fb5be603bd44fda24914e8e52b122ba1fd255860bcd141419217dfa005927265790298619c7f38299513520a7b7ba87c000b375c744210606ce15e783
|
7
|
+
data.tar.gz: 455d38c219493f54ee54589f0031e2505f063c19fc55bdaa9d006d78077cb3a1362e1a82e025e11239a742594d5dc21776e7dddcc166854b78718ecb48498521
|
data/MIT-LICENSE
ADDED
@@ -0,0 +1,20 @@
|
|
1
|
+
Copyright (c) 2021 Technical Panda Ltd
|
2
|
+
|
3
|
+
Permission is hereby granted, free of charge, to any person obtaining
|
4
|
+
a copy of this software and associated documentation files (the
|
5
|
+
"Software"), to deal in the Software without restriction, including
|
6
|
+
without limitation the rights to use, copy, modify, merge, publish,
|
7
|
+
distribute, sublicense, and/or sell copies of the Software, and to
|
8
|
+
permit persons to whom the Software is furnished to do so, subject to
|
9
|
+
the following conditions:
|
10
|
+
|
11
|
+
The above copyright notice and this permission notice shall be
|
12
|
+
included in all copies or substantial portions of the Software.
|
13
|
+
|
14
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
15
|
+
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
16
|
+
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
17
|
+
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
|
18
|
+
LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
|
19
|
+
OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
20
|
+
WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
data/README.md
CHANGED
@@ -1,10 +1,13 @@
|
|
1
1
|
# Plissken
|
2
2
|
|
3
|
+
[![Gem Version](https://badge.fury.io/rb/plissken.svg)](https://badge.fury.io/rb/plissken)
|
4
|
+
![CI](https://github.com/technicalpanda/plissken/workflows/CI/badge.svg)
|
5
|
+
|
3
6
|
Have you ever needed to automatically convert JSON-style `camelBack` or `CamelCase` hash keys into more Rubyish `snake_case`?
|
4
7
|
|
5
|
-
Plissken to the rescue
|
8
|
+
Plissken to the rescue!
|
6
9
|
|
7
|
-
This gem recursively converts all camelBack or CamelCase keys in a
|
10
|
+
This gem recursively converts all camelBack or CamelCase keys in either a Hash structure, or an Array of Hashes, to snake_case.
|
8
11
|
|
9
12
|
## Installation
|
10
13
|
|
@@ -22,10 +25,20 @@ gem install plissken
|
|
22
25
|
|
23
26
|
## Usage
|
24
27
|
|
28
|
+
On hashes:
|
29
|
+
|
25
30
|
```ruby
|
26
|
-
my_hash = {"firstKey" => 1, "fooBars" => [{"bazBaz" => "value"}, {"blahBlah" => "value"}]}
|
31
|
+
my_hash = { "firstKey" => 1, "fooBars" => [{ "bazBaz" => "value" }, { "blahBlah" => "value" }] }
|
27
32
|
snaked_hash = my_hash.to_snake_keys
|
28
|
-
# => {"first_key" => 1, "foo_bars" => [{"baz_baz" => "value"}, {"blah_blah" => "value"}]}
|
33
|
+
# => { "first_key" => 1, "foo_bars" => [{ "baz_baz" => "value" }, { "blah_blah" => "value" }] }
|
34
|
+
```
|
35
|
+
|
36
|
+
On arrays:
|
37
|
+
|
38
|
+
```ruby
|
39
|
+
my_array_of_hashes = [{ "firstKey" => 1, "fooBars" => [{ "bazBaz" => "value" }, { "blahBlah" => "value" }] }]
|
40
|
+
snaked_hash = my_array_of_hashes.to_snake_keys
|
41
|
+
# => [{"first_key" => 1, "foo_bars" => [{ "baz_baz" => "value" }, { "blah_blah" => "value" }] }]
|
29
42
|
```
|
30
43
|
|
31
44
|
Plissken works on either string keys or symbolized keys. It has no dependencies, as it has its own `underscore` method lifted out of ActiveSupport.
|
@@ -40,17 +53,14 @@ Plissken works on either string keys or symbolized keys. It has no dependencies,
|
|
40
53
|
If you've already got `snake_case` and need to `CamelCase` it, you are encouraged to try
|
41
54
|
the [Awrence](http://github.com/futurechimp/awrence) gem.
|
42
55
|
|
43
|
-
## Contributing
|
56
|
+
## Contributing
|
57
|
+
|
58
|
+
Bug reports and pull requests are welcome on GitHub at https://github.com/technicalpanda/plissken. 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.
|
59
|
+
|
60
|
+
## License
|
44
61
|
|
45
|
-
|
46
|
-
* Check out the issue tracker to make sure someone already hasn't requested it and/or contributed it.
|
47
|
-
* Fork the project.
|
48
|
-
* Start a feature/bugfix branch.
|
49
|
-
* Commit and push until you are happy with your contribution.
|
50
|
-
* Make sure to add tests for it. This is important so I don't break it in a future version unintentionally.
|
51
|
-
* 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.
|
62
|
+
The gem is available as open source under the terms of the [MIT License](https://opensource.org/licenses/MIT).
|
52
63
|
|
53
|
-
##
|
64
|
+
## Code of Conduct
|
54
65
|
|
55
|
-
|
56
|
-
further details.
|
66
|
+
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/plissken/blob/main/CODE_OF_CONDUCT.md).
|
data/Rakefile
CHANGED
@@ -1,3 +1,5 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
1
3
|
begin
|
2
4
|
require "bundler/setup"
|
3
5
|
rescue LoadError
|
@@ -8,7 +10,7 @@ require "rdoc/task"
|
|
8
10
|
|
9
11
|
RDoc::Task.new(:rdoc) do |rdoc|
|
10
12
|
rdoc.rdoc_dir = "rdoc"
|
11
|
-
rdoc.title = "
|
13
|
+
rdoc.title = "Plissken"
|
12
14
|
rdoc.options << "--line-numbers"
|
13
15
|
rdoc.rdoc_files.include("README.md")
|
14
16
|
rdoc.rdoc_files.include("lib/**/*.rb")
|
data/VERSION
CHANGED
@@ -1 +1 @@
|
|
1
|
-
1.1
|
1
|
+
1.4.1
|
data/lib/plissken.rb
CHANGED
@@ -1,5 +1,8 @@
|
|
1
|
-
|
1
|
+
# frozen_string_literal: true
|
2
2
|
|
3
|
-
|
3
|
+
require "plissken/methods"
|
4
|
+
require "plissken/ext/array/to_snake_keys"
|
5
|
+
require "plissken/ext/hash/to_snake_keys"
|
4
6
|
|
7
|
+
module Plissken
|
5
8
|
end
|
@@ -1,47 +1,5 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
2
|
|
3
|
-
# Hash.to_snake_keys
|
4
3
|
class Hash
|
5
|
-
|
6
|
-
# Rubyish snake_case, suitable for use during instantiation of Ruby
|
7
|
-
# model attributes.
|
8
|
-
#
|
9
|
-
def to_snake_keys(value = self)
|
10
|
-
case value
|
11
|
-
when Array
|
12
|
-
value.map { |v| to_snake_keys(v) }
|
13
|
-
when Hash
|
14
|
-
snake_hash(value)
|
15
|
-
else
|
16
|
-
value
|
17
|
-
end
|
18
|
-
end
|
19
|
-
|
20
|
-
private
|
21
|
-
|
22
|
-
def snake_hash(value)
|
23
|
-
Hash[value.map { |k, v| [underscore_key(k), to_snake_keys(v)] }]
|
24
|
-
end
|
25
|
-
|
26
|
-
def underscore_key(k)
|
27
|
-
if k.is_a? Symbol
|
28
|
-
underscore(k.to_s).to_sym
|
29
|
-
elsif k.is_a? String
|
30
|
-
underscore(k)
|
31
|
-
else
|
32
|
-
k # Plissken can't snakify anything except strings and symbols
|
33
|
-
end
|
34
|
-
end
|
35
|
-
|
36
|
-
def underscore(string)
|
37
|
-
@__memoize_underscore ||= {}
|
38
|
-
return @__memoize_underscore[string] if @__memoize_underscore[string]
|
39
|
-
@__memoize_underscore[string] =
|
40
|
-
string.tr('::', '/')
|
41
|
-
.gsub(/([A-Z]+)([A-Z][a-z])/, '\1_\2')
|
42
|
-
.gsub(/([a-z\d])([A-Z])/, '\1_\2')
|
43
|
-
.tr('-', '_')
|
44
|
-
.downcase
|
45
|
-
@__memoize_underscore[string]
|
46
|
-
end
|
4
|
+
include Plissken::Methods
|
47
5
|
end
|
@@ -0,0 +1,51 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module Plissken
|
4
|
+
module Methods
|
5
|
+
# Recursively converts CamelCase and camelBack JSON-style hash keys to
|
6
|
+
# Rubyish snake_case, suitable for use during instantiation of Ruby
|
7
|
+
# model attributes.
|
8
|
+
#
|
9
|
+
def to_snake_keys(value = self)
|
10
|
+
case value
|
11
|
+
when Array
|
12
|
+
value.map { |v| to_snake_keys(v) }
|
13
|
+
when Hash
|
14
|
+
snake_hash(value)
|
15
|
+
else
|
16
|
+
value
|
17
|
+
end
|
18
|
+
end
|
19
|
+
|
20
|
+
private
|
21
|
+
|
22
|
+
def snake_hash(value)
|
23
|
+
value.map { |k, v| [underscore_key(k), to_snake_keys(v)] }.to_h
|
24
|
+
end
|
25
|
+
|
26
|
+
def underscore_key(key)
|
27
|
+
case key
|
28
|
+
when Symbol
|
29
|
+
underscore(key.to_s).to_sym
|
30
|
+
when String
|
31
|
+
underscore(key)
|
32
|
+
else
|
33
|
+
key # Plissken can't snakify anything except strings and symbols
|
34
|
+
end
|
35
|
+
end
|
36
|
+
|
37
|
+
def underscore(string)
|
38
|
+
@__memoize_underscore ||= {}
|
39
|
+
|
40
|
+
return @__memoize_underscore[string] if @__memoize_underscore[string]
|
41
|
+
|
42
|
+
@__memoize_underscore[string] =
|
43
|
+
string.tr("::", "/")
|
44
|
+
.gsub(/([A-Z]+)([A-Z][a-z])/, '\1_\2')
|
45
|
+
.gsub(/([a-z\d])([A-Z])/, '\1_\2')
|
46
|
+
.tr("-", "_")
|
47
|
+
.downcase
|
48
|
+
@__memoize_underscore[string]
|
49
|
+
end
|
50
|
+
end
|
51
|
+
end
|
data/lib/plissken/version.rb
CHANGED
metadata
CHANGED
@@ -1,59 +1,142 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: plissken
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 1.1
|
4
|
+
version: 1.4.1
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Dave Hrycyszyn
|
8
|
-
- Michael Chrisco
|
9
8
|
- Stuart Chinery
|
10
|
-
autorequire:
|
9
|
+
autorequire:
|
11
10
|
bindir: bin
|
12
11
|
cert_chain: []
|
13
|
-
date:
|
12
|
+
date: 2021-02-18 00:00:00.000000000 Z
|
14
13
|
dependencies:
|
14
|
+
- !ruby/object:Gem::Dependency
|
15
|
+
name: byebug
|
16
|
+
requirement: !ruby/object:Gem::Requirement
|
17
|
+
requirements:
|
18
|
+
- - "~>"
|
19
|
+
- !ruby/object:Gem::Version
|
20
|
+
version: '11.1'
|
21
|
+
type: :development
|
22
|
+
prerelease: false
|
23
|
+
version_requirements: !ruby/object:Gem::Requirement
|
24
|
+
requirements:
|
25
|
+
- - "~>"
|
26
|
+
- !ruby/object:Gem::Version
|
27
|
+
version: '11.1'
|
15
28
|
- !ruby/object:Gem::Dependency
|
16
29
|
name: minitest
|
17
30
|
requirement: !ruby/object:Gem::Requirement
|
18
31
|
requirements:
|
19
32
|
- - "~>"
|
20
33
|
- !ruby/object:Gem::Version
|
21
|
-
version: '
|
34
|
+
version: '5.14'
|
35
|
+
type: :development
|
36
|
+
prerelease: false
|
37
|
+
version_requirements: !ruby/object:Gem::Requirement
|
38
|
+
requirements:
|
39
|
+
- - "~>"
|
40
|
+
- !ruby/object:Gem::Version
|
41
|
+
version: '5.14'
|
42
|
+
- !ruby/object:Gem::Dependency
|
43
|
+
name: minitest-fail-fast
|
44
|
+
requirement: !ruby/object:Gem::Requirement
|
45
|
+
requirements:
|
46
|
+
- - "~>"
|
47
|
+
- !ruby/object:Gem::Version
|
48
|
+
version: '0.1'
|
22
49
|
type: :development
|
23
50
|
prerelease: false
|
24
51
|
version_requirements: !ruby/object:Gem::Requirement
|
25
52
|
requirements:
|
26
53
|
- - "~>"
|
27
54
|
- !ruby/object:Gem::Version
|
28
|
-
version: '
|
55
|
+
version: '0.1'
|
56
|
+
- !ruby/object:Gem::Dependency
|
57
|
+
name: minitest-macos-notification
|
58
|
+
requirement: !ruby/object:Gem::Requirement
|
59
|
+
requirements:
|
60
|
+
- - "~>"
|
61
|
+
- !ruby/object:Gem::Version
|
62
|
+
version: '0.3'
|
63
|
+
type: :development
|
64
|
+
prerelease: false
|
65
|
+
version_requirements: !ruby/object:Gem::Requirement
|
66
|
+
requirements:
|
67
|
+
- - "~>"
|
68
|
+
- !ruby/object:Gem::Version
|
69
|
+
version: '0.3'
|
29
70
|
- !ruby/object:Gem::Dependency
|
30
71
|
name: minitest-reporters
|
31
72
|
requirement: !ruby/object:Gem::Requirement
|
32
73
|
requirements:
|
33
74
|
- - "~>"
|
34
75
|
- !ruby/object:Gem::Version
|
35
|
-
version: '
|
76
|
+
version: '1.4'
|
36
77
|
type: :development
|
37
78
|
prerelease: false
|
38
79
|
version_requirements: !ruby/object:Gem::Requirement
|
39
80
|
requirements:
|
40
81
|
- - "~>"
|
41
82
|
- !ruby/object:Gem::Version
|
42
|
-
version: '
|
83
|
+
version: '1.4'
|
43
84
|
- !ruby/object:Gem::Dependency
|
44
85
|
name: rake
|
45
86
|
requirement: !ruby/object:Gem::Requirement
|
46
87
|
requirements:
|
47
88
|
- - "~>"
|
48
89
|
- !ruby/object:Gem::Version
|
49
|
-
version: '
|
90
|
+
version: '13.0'
|
50
91
|
type: :development
|
51
92
|
prerelease: false
|
52
93
|
version_requirements: !ruby/object:Gem::Requirement
|
53
94
|
requirements:
|
54
95
|
- - "~>"
|
55
96
|
- !ruby/object:Gem::Version
|
56
|
-
version: '
|
97
|
+
version: '13.0'
|
98
|
+
- !ruby/object:Gem::Dependency
|
99
|
+
name: rubocop
|
100
|
+
requirement: !ruby/object:Gem::Requirement
|
101
|
+
requirements:
|
102
|
+
- - "~>"
|
103
|
+
- !ruby/object:Gem::Version
|
104
|
+
version: '1.7'
|
105
|
+
type: :development
|
106
|
+
prerelease: false
|
107
|
+
version_requirements: !ruby/object:Gem::Requirement
|
108
|
+
requirements:
|
109
|
+
- - "~>"
|
110
|
+
- !ruby/object:Gem::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'
|
57
140
|
description: |-
|
58
141
|
Have you ever needed to automatically convert JSON-style camelBack or CamelCase hash keys into more Rubyish snake_case?
|
59
142
|
|
@@ -61,22 +144,26 @@ description: |-
|
|
61
144
|
|
62
145
|
This gem recursively converts all camelBack or CamelCase keys in a hash structure to snake_case.
|
63
146
|
email:
|
64
|
-
-
|
147
|
+
- dave@constructiveproof.com
|
148
|
+
- code@technicalpanda.co.uk
|
65
149
|
executables: []
|
66
150
|
extensions: []
|
67
151
|
extra_rdoc_files: []
|
68
152
|
files:
|
153
|
+
- MIT-LICENSE
|
69
154
|
- README.md
|
70
155
|
- Rakefile
|
71
156
|
- VERSION
|
72
157
|
- lib/plissken.rb
|
158
|
+
- lib/plissken/ext/array/to_snake_keys.rb
|
73
159
|
- lib/plissken/ext/hash/to_snake_keys.rb
|
160
|
+
- lib/plissken/methods.rb
|
74
161
|
- lib/plissken/version.rb
|
75
|
-
homepage: https://github.com/
|
162
|
+
homepage: https://github.com/technicalpanda/plissken
|
76
163
|
licenses:
|
77
164
|
- MIT
|
78
165
|
metadata: {}
|
79
|
-
post_install_message:
|
166
|
+
post_install_message:
|
80
167
|
rdoc_options: []
|
81
168
|
require_paths:
|
82
169
|
- lib
|
@@ -84,16 +171,15 @@ required_ruby_version: !ruby/object:Gem::Requirement
|
|
84
171
|
requirements:
|
85
172
|
- - ">="
|
86
173
|
- !ruby/object:Gem::Version
|
87
|
-
version: '
|
174
|
+
version: '2.5'
|
88
175
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
89
176
|
requirements:
|
90
177
|
- - ">="
|
91
178
|
- !ruby/object:Gem::Version
|
92
179
|
version: '0'
|
93
180
|
requirements: []
|
94
|
-
|
95
|
-
|
96
|
-
signing_key:
|
181
|
+
rubygems_version: 3.1.4
|
182
|
+
signing_key:
|
97
183
|
specification_version: 4
|
98
184
|
summary: Snakify your camel keys when working with JSON APIs
|
99
185
|
test_files: []
|