Skip to content

Commit

Permalink
Fix integer key bug the arises in latest ruby
Browse files Browse the repository at this point in the history
  • Loading branch information
buermann committed Jan 31, 2024
1 parent 843ac21 commit fa472b5
Show file tree
Hide file tree
Showing 5 changed files with 22 additions and 17 deletions.
26 changes: 13 additions & 13 deletions .rubocop.yml
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
AllCops:
TargetRubyVersion: 2.3
NewCops: enable
Exclude:
- 'spec/**/*'
- 'vendor/**/*'

Metrics/CyclomaticComplexity:
Max: 12

Style/PerlBackrefs:
Enabled: false

AllCops:
TargetRubyVersion: 2.3
NewCops: enable
Exclude:
- 'spec/**/*'
- 'vendor/**/*'

Metrics/CyclomaticComplexity:
Max: 12

Style/PerlBackrefs:
Enabled: false

2 changes: 1 addition & 1 deletion .ruby-version
Original file line number Diff line number Diff line change
@@ -1 +1 @@
3.0.1
3.3.0
5 changes: 5 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,8 @@
1.0.0 01/31/2024
================

Don't let integer hash keys raise your enemies up. Test against Ruby 3.3.0.

0.1.0 10/14/2022
================

Expand Down
4 changes: 2 additions & 2 deletions lib/camel_snake_keys.rb
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ def snake_keys(data)
when Array
data.map { |v| snake_keys(v) }
when Hash
hash = data.sort_by { |k, _v| k =~ /_/ ? 0 : 1 }.to_h { |k, v| [if_underscore(k), snake_keys(v)] }
hash = data.sort_by { |k, _v| k.to_s =~ /_/ ? 0 : 1 }.to_h { |k, v| [if_underscore(k), snake_keys(v)] }
data.instance_of?(Hash) ? hash : data.class.new(hash)
else
data
Expand All @@ -68,7 +68,7 @@ def camel_keys(data)
when Array
data.map { |v| camel_keys(v) }
when Hash
hash = data.sort_by { |k, _v| k =~ /_/ ? 1 : 0 }.to_h { |k, v| [if_camelize(k), camel_keys(v)] }
hash = data.sort_by { |k, _v| k.to_s =~ /_/ ? 1 : 0 }.to_h { |k, v| [if_camelize(k), camel_keys(v)] }
data.instance_of?(Hash) ? hash : data.class.new(hash)
else
data
Expand Down
2 changes: 1 addition & 1 deletion lib/version.rb
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

# Store the version of the gem here rather than the gemspec
module CamelSnakeKeys
VERSION = '0.1.0'
VERSION = '1.0.0'

def self.version
VERSION
Expand Down

0 comments on commit fa472b5

Please sign in to comment.