plissken 1.0.0 → 1.4.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
- SHA1:
3
- metadata.gz: 0c822d80cd3724459bbf8a259f3850be1f920ba1
4
- data.tar.gz: 8e03901e74f47d5743e5b785670d2d7b6eea6505
2
+ SHA256:
3
+ metadata.gz: c5ff63e09b861a02ccc0734c23999234daba77310ebd638bca81c2da112f1c8f
4
+ data.tar.gz: 2cdd62542f8db520346e20102c807b6bb88fbb0e3608d8d82874bb96d8910d62
5
5
  SHA512:
6
- metadata.gz: 4d2b4516e6263c6c677aeeef01e1cab7cc1ebaee0ef61bd20268c7eeebbc394b17faef58edab4c7731fd138f8e1805946f95d6797f507bf19f0e2efa5ff82f98
7
- data.tar.gz: 98a25014463f7946e5aa3eb33f92bf18d93fa625ff2084ba331563fff00b2eb27b3806eda40d87bcbd7875b2e660029d1df2358ed5a254189cc84a5eed4ac1e7
6
+ metadata.gz: cdedabe47563eb7a6dfe59f7be9ed67dc77dbc33e987dc72d7c66343634d62425e46505066b4e187f37d71a635987573916d58c6b86d0f4078561562f67e4bc1
7
+ data.tar.gz: 610ae89854d9d880de23971acd0b199f38b59f31a4718f12555b202de7ad41b8c2c272639ed38f4b4f207ec3a377b68984d5b91a5bb5fbf519ec25a21a989201
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,12 @@
1
1
  # Plissken
2
2
 
3
+ [![Gem Version](https://badge.fury.io/rb/plissken.svg)](https://badge.fury.io/rb/plissken)
4
+
3
5
  Have you ever needed to automatically convert JSON-style `camelBack` or `CamelCase` hash keys into more Rubyish `snake_case`?
4
6
 
5
- Plissken to the rescue.
7
+ Plissken to the rescue!
6
8
 
7
- This gem recursively converts all camelBack or CamelCase keys in a hash structure to snake_case.
9
+ This gem recursively converts all camelBack or CamelCase keys in either a Hash structure, or an Array of Hashes, to snake_case.
8
10
 
9
11
  ## Installation
10
12
 
@@ -22,10 +24,20 @@ gem install plissken
22
24
 
23
25
  ## Usage
24
26
 
27
+ On hashes:
28
+
25
29
  ```ruby
26
- my_hash = {"firstKey" => 1, "fooBars" => [{"bazBaz" => "value"}, {"blahBlah" => "value"}]}
30
+ my_hash = { "firstKey" => 1, "fooBars" => [{ "bazBaz" => "value" }, { "blahBlah" => "value" }] }
27
31
  snaked_hash = my_hash.to_snake_keys
28
- # => {"first_key" => 1, "foo_bars" => [{"baz_baz" => "value"}, {"blah_blah" => "value"}]}
32
+ # => { "first_key" => 1, "foo_bars" => [{ "baz_baz" => "value" }, { "blah_blah" => "value" }] }
33
+ ```
34
+
35
+ On arrays:
36
+
37
+ ```ruby
38
+ my_array_of_hashes = [{ "firstKey" => 1, "fooBars" => [{ "bazBaz" => "value" }, { "blahBlah" => "value" }] }]
39
+ snaked_hash = my_array_of_hashes.to_snake_keys
40
+ # => [{"first_key" => 1, "foo_bars" => [{ "baz_baz" => "value" }, { "blah_blah" => "value" }] }]
29
41
  ```
30
42
 
31
43
  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 +52,14 @@ Plissken works on either string keys or symbolized keys. It has no dependencies,
40
52
  If you've already got `snake_case` and need to `CamelCase` it, you are encouraged to try
41
53
  the [Awrence](http://github.com/futurechimp/awrence) gem.
42
54
 
43
- ## Contributing to plissken
55
+ ## Contributing
56
+
57
+ 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.
58
+
59
+ ## License
44
60
 
45
- * Check out the latest master to make sure the feature hasn't been implemented or the bug hasn't been fixed yet.
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.
61
+ The gem is available as open source under the terms of the [MIT License](https://opensource.org/licenses/MIT).
52
62
 
53
- ## Copyright
63
+ ## Code of Conduct
54
64
 
55
- Copyright (c) 2013 Dave Hrycyszyn. See LICENSE.txt for
56
- further details.
65
+ 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 = "Filta"
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.0.0
1
+ 1.4.0
data/lib/plissken.rb CHANGED
@@ -1,5 +1,8 @@
1
- require File.dirname(__FILE__) + '/plissken/ext/hash/to_snake_keys'
1
+ # frozen_string_literal: true
2
2
 
3
- module Plissken
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
@@ -0,0 +1,5 @@
1
+ # frozen_string_literal: true
2
+
3
+ class Array
4
+ include Plissken::Methods
5
+ end
@@ -1,45 +1,5 @@
1
- # Hash.to_snake_keys
2
- class Hash
3
- # Recursively converts CamelCase and camelBack JSON-style hash keys to
4
- # Rubyish snake_case, suitable for use during instantiation of Ruby
5
- # model attributes.
6
- #
7
- def to_snake_keys(value = self)
8
- case value
9
- when Array
10
- value.map { |v| to_snake_keys(v) }
11
- when Hash
12
- snake_hash(value)
13
- else
14
- value
15
- end
16
- end
17
-
18
- private
19
-
20
- def snake_hash(value)
21
- Hash[value.map { |k, v| [underscore_key(k), to_snake_keys(v)] }]
22
- end
1
+ # frozen_string_literal: true
23
2
 
24
- def underscore_key(k)
25
- if k.is_a? Symbol
26
- underscore(k.to_s).to_sym
27
- elsif k.is_a? String
28
- underscore(k)
29
- else
30
- k # Plissken can't snakify anything except strings and symbols
31
- end
32
- end
33
-
34
- def underscore(string)
35
- @__memoize_underscore ||= {}
36
- return @__memoize_underscore[string] if @__memoize_underscore[string]
37
- @__memoize_underscore[string] =
38
- string.gsub(/::/, '/')
39
- .gsub(/([A-Z]+)([A-Z][a-z])/, '\1_\2')
40
- .gsub(/([a-z\d])([A-Z])/, '\1_\2')
41
- .tr('-', '_')
42
- .downcase
43
- @__memoize_underscore[string]
44
- end
3
+ class Hash
4
+ include Plissken::Methods
45
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
+ Hash[value.map { |k, v| [underscore_key(k), to_snake_keys(v)] }]
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
@@ -1,3 +1,6 @@
1
+ # frozen_string_literal: true
2
+
1
3
  module Plissken
2
- VERSION = File.read("VERSION").split("\n").first
4
+ version_file = File.join(File.dirname(__FILE__), "../../VERSION")
5
+ VERSION = File.read(version_file).split("\n").first
3
6
  end
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.0.0
4
+ version: 1.4.0
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: 2017-07-19 00:00:00.000000000 Z
12
+ date: 2021-02-01 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: '3.0'
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: '3.0'
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: '0.14'
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: '0.14'
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: '12.0'
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: '12.0'
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
- - dhrycyszyn@zonedigital.com
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/futurechimp/plissken
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: '0'
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
- rubyforge_project:
95
- rubygems_version: 2.6.11
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: []