camel_snake_keys 0.0.7 → 1.0.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 7969aad0c0f379d148318435d02673f72be7938e6cbb33a084df50a79261f11f
4
- data.tar.gz: a5841106f20246186321b692f612ee64d28cef2d8568589f769a5e8765badf0f
3
+ metadata.gz: 268c6e26a8ebda25948278bcd25fe09d95406e9a2d1fd2796fbf2477b162feca
4
+ data.tar.gz: 2a6ad369a5921fa673abf4b2852fbd0e442e604db94ae7599c35eeeccfe6d4f5
5
5
  SHA512:
6
- metadata.gz: 7f154ed7f42d8c3061a71c708e6c9265ea965698f97c6ce367433ec7d0ec472d1ee52253b71b6c9b9e80d25cd4db0ab62d8a7027bb1688685d853655dc4b996f
7
- data.tar.gz: 7c97476f9e93bc057daf1e6d71f376fb681e50f12797d9862147ca8fcff8700872f641e3426e88c02c7fccc04e4d7aade342e67c1193ebf90f1ebf6ca697ca52
6
+ metadata.gz: 629cd4305384afeb3c86d3ad586cc8e8743e8a311a0a342c758905c95fd0e7b92b7880747fdaea6d08f07d428bc6eb1c7f202997ec2df8ca7aaeb83659767f5c
7
+ data.tar.gz: cb6d7ce3cd4bf786fc1e336def80a781c2091f53a8ab761e62bb414cefb5b3da7445adfc41af8c0a778fb51d2d76b1e0352e12e2dd509428b2e9075148d0c8dc
@@ -0,0 +1,79 @@
1
+ name: Verify
2
+ on: push
3
+ jobs:
4
+ lint:
5
+ name: Lint
6
+ runs-on: ubuntu-latest
7
+ steps:
8
+ - name: Checkout Repository
9
+ uses: actions/checkout@v2
10
+ - name: Install dependencies for the Fog gem
11
+ run: |
12
+ sudo apt-get update
13
+ sudo apt-get install libcurl4-openssl-dev
14
+ - name: Set up Ruby
15
+ uses: ruby/setup-ruby@v1
16
+ with:
17
+ ruby-version: 2.7.3
18
+ - name: Cache Ruby Gems
19
+ uses: actions/cache@v2
20
+ with:
21
+ path: vendor/bundle
22
+ key: ${{ runner.os }}-gems-${{ hashFiles('**/Gemfile.lock') }}
23
+ restore-keys: |
24
+ ${{ runner.os }}-gems-
25
+ - name: Bundle Install
26
+ run: |
27
+ gem install bundler
28
+ bundle config path vendor/bundle
29
+ bundle install --jobs 4 --retry 3
30
+ - name: Formatting Checks
31
+ run: |
32
+ bundle exec rubocop
33
+ security:
34
+ name: Security
35
+ runs-on: ubuntu-latest
36
+ steps:
37
+ - name: Checkout Repository
38
+ uses: actions/checkout@v2
39
+ - name: Install dependencies for the Fog gem
40
+ run: |
41
+ sudo apt-get update
42
+ sudo apt-get install libcurl4-openssl-dev
43
+ - name: Set up Ruby
44
+ uses: ruby/setup-ruby@v1
45
+ with:
46
+ ruby-version: 2.7.3
47
+ - name: Cache Ruby Gems
48
+ uses: actions/cache@v2
49
+ with:
50
+ path: vendor/bundle
51
+ key: ${{ runner.os }}-gems-${{ hashFiles('**/Gemfile.lock') }}
52
+ restore-keys: |
53
+ ${{ runner.os }}-gems-
54
+ - name: Bundle Install
55
+ run: |
56
+ gem install bundler
57
+ bundle config path vendor/bundle
58
+ bundle install --jobs 4 --retry 3
59
+ - name: Security Checks
60
+ run: |
61
+ bundle exec brakeman -z --force
62
+ gem install bundle-audit
63
+ bundle-audit update
64
+ bundle-audit
65
+ tests:
66
+ name: Tests
67
+ runs-on: ubuntu-latest
68
+ steps:
69
+ - name: Checkout code
70
+ uses: actions/checkout@v2
71
+ - name: Setup Ruby and install gems
72
+ uses: ruby/setup-ruby@v1
73
+ with:
74
+ ruby-version: 2.7.3
75
+ bundler-cache: true
76
+ - name: Rspec
77
+ run: |
78
+ bundle exec rspec
79
+
data/.gitignore CHANGED
@@ -4,3 +4,4 @@ log/*.log
4
4
  Gemfile.lock
5
5
  pkg/
6
6
  .DS_Store
7
+ .byebug_history
data/.rubocop.yml CHANGED
@@ -1,96 +1,13 @@
1
1
  AllCops:
2
+ TargetRubyVersion: 2.3
2
3
  NewCops: enable
3
4
  Exclude:
4
5
  - 'spec/**/*'
5
- - 'db/**/*'
6
- - 'bin/*'
7
- - 'Gemfile'
8
6
  - 'vendor/**/*'
9
7
 
10
- Gemspec/OrderedDependencies:
11
- Enabled: false # I like to group them, so what?
12
-
13
- Metrics/BlockLength:
14
- Max: 30
15
- Exclude: # Grape's DSL rather expects large blocks
16
- - app/api/location_service/**/*
17
-
18
- Metrics/MethodLength:
19
- Max: 30
20
-
21
- Metrics/ClassLength:
22
- Max: 180
23
-
24
- Metrics/AbcSize:
25
- Max: 20
26
-
27
- Metrics/PerceivedComplexity:
28
- Max: 12
29
-
30
8
  Metrics/CyclomaticComplexity:
31
9
  Max: 12
32
10
 
33
- Layout/LineLength:
34
- Enabled: false
35
-
36
- Layout/EndOfLine:
37
- Enabled: false
38
-
39
- Layout/ExtraSpacing:
40
- Enabled: false
41
-
42
- Layout/HashAlignment:
43
- # I like to space repeated grammars out tabulated, defund these cops
44
- Enabled: false
45
-
46
- Layout/SpaceAroundEqualsInParameterDefault:
47
- Enabled: false
48
-
49
- Layout/EmptyLinesAroundExceptionHandlingKeywords:
50
- Enabled: false
51
-
52
- Layout/FirstHashElementIndentation:
53
- Enabled: false
54
-
55
- Layout/LeadingCommentSpace:
56
- Enabled: false
57
-
58
- Layout/MultilineOperationIndentation: # works very poorly
59
- Enabled: false
60
-
61
- Layout/MultilineMethodCallIndentation:
62
- Enabled: false
63
-
64
- Layout/SpaceInsideBlockBraces:
65
- Enabled: false
66
-
67
- Layout/SpaceInsideParens:
68
- Enabled: false
69
-
70
- Layout/SpaceAroundOperators:
71
- Enabled: false
72
-
73
- Layout/SpaceBeforeFirstArg:
74
- Enabled: false
75
-
76
- Style/BlockDelimiters:
77
- Enabled: false
78
-
79
- Style/FrozenStringLiteralComment:
80
- Enabled: false
81
-
82
- Style/Documentation:
83
- Enabled: false
84
-
85
- Style/ParallelAssignment:
86
- Enabled: false
87
-
88
- Style/PercentLiteralDelimiters:
89
- Enabled: false
90
-
91
- Style/RaiseArgs:
92
- Enabled: false
93
-
94
- Style/RedundantBegin:
11
+ Style/PerlBackrefs:
95
12
  Enabled: false
96
13
 
data/.ruby-version CHANGED
@@ -1 +1 @@
1
- 3.0.1
1
+ 3.3.0
data/CHANGELOG.md CHANGED
@@ -1,24 +1,40 @@
1
- 0.0.7 2/08/2022
2
- ==============
1
+ 1.0.0 01/31/2024
2
+ ================
3
+
4
+ Don't let integer hash keys raise your enemies up. Test against Ruby 3.3.0.
5
+
6
+ 0.1.0 10/14/2022
7
+ ================
8
+
9
+ ActiveSupport::Inflector's camelize and underscore methods convert "::" to "/" and "/" to "::", which might be useful in Rails' internals, but in the context of a Grape API it corrupts the swagger docs' "paths" objects.
10
+
11
+ Implement our own camel and snake case methods that leave "::" and "/" unmolested, rather than relying on ActiveSupport, in which case we'll drop that dependency altogether by removing the (trivially re-implemented) indifferent access functionality.
12
+
13
+ We are not re-implmenting ActiveSupport's acronym inflections. Yet.
14
+
15
+ Replace travis etc. with github actions.
16
+
17
+ 0.0.7 02/08/2022
18
+ ================
3
19
 
4
20
  Support Ruby 3+
5
21
 
6
- 0.0.6 4/07/2020
7
- ==============
22
+ 0.0.6 04/07/2020
23
+ ===============
8
24
 
9
25
  ### Bug fix
10
26
 
11
27
  Pass the indifferent access flag down the recursion.
12
28
 
13
- 0.0.3 5/11/2016
14
- ==============
29
+ 0.0.3 05/11/2016
30
+ ================
15
31
 
16
32
  ### Features
17
33
 
18
34
  Preserve any descendent of Hash that accepts a Hash in its initialize method, as with ActiveSupport::HashWithIndifferentAccess and Hashie::Mash
19
35
 
20
- 0.0.2 5/11/2016
21
- ==============
36
+ 0.0.2 05/11/2016
37
+ ================
22
38
 
23
39
  ### Features
24
40
 
data/Gemfile CHANGED
@@ -1,7 +1,13 @@
1
+ # frozen_string_literal: true
2
+
1
3
  source 'https://rubygems.org'
4
+ gemspec
2
5
  gem 'activesupport'
6
+ gem 'brakeman'
7
+ gem 'byebug'
3
8
  gem 'coveralls'
4
9
  gem 'hashie'
5
10
  gem 'rake'
6
11
  gem 'rspec'
7
12
  gem 'rspec-core'
13
+ gem 'rubocop'
data/README.md CHANGED
@@ -1,26 +1,15 @@
1
1
  # camel_snake_keys
2
2
 
3
3
  [![Gem Version][GV img]][Gem Version]
4
- [![Build Status][BS img]][Build Status]
5
- [![Coverage Status][CS img]][Coverage Status]
6
-
7
4
  [Gem Version]: https://rubygems.org/gems/camel_snake_keys
8
- [Build Status]: https://travis-ci.org/buermann/camel_snake_keys
9
- [travis pull requests]: https://travis-ci.org/buermann/camel_snake_keys/pull_requests
10
- [Coverage Status]: https://coveralls.io/r/buermann/camel_snake_keys
11
-
12
- [GV img]: https://badge.fury.io/rb/camel_snake_keys.png
13
- [BS img]: https://travis-ci.org/buermann/camel_snake_keys.png
14
- [CS img]: https://coveralls.io/repos/buermann/camel_snake_keys/badge.png?branch=master
15
-
16
5
 
17
6
  Add recursive with_snake_keys and with_camel_keys refinements to Array and Hash. Preserve strings and symbols and treat hash descendents such as ActiveSupport::HashWithIndifferentAccess and Hashie::Mash agnostically.
18
7
 
19
8
  ## Documentation
20
9
 
21
- Add `gem 'camel_snake_keys'` to your Gemfile or gem install camel_snake_keys. Where you want to add `with_snake_keys` and `with_camel_keys` to your objects invoke `using CamelSnakeKeys`, or invoke the class methods, `CamelSnakeKeys.camel_keys(object, with_indifference)` and `CamelSnakeKeys.snake_keys(object, with_indifference)`.
10
+ Add `gem 'camel_snake_keys'` to your Gemfile or "gem install camel_snake_keys".
22
11
 
23
- If with_indifference is set to a true value hashes will be returned as ActiveSupport's HashWithIndifferentAccess.
12
+ Where you want to add `with_snake_keys` and `with_camel_keys` to your objects invoke `using CamelSnakeKeys`, or invoke the class methods, `CamelSnakeKeys.camel_keys(object)` and `CamelSnakeKeys.snake_keys(object)`.
24
13
 
25
14
  ```
26
15
  require 'camel_snake_keys'
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
data/camel_snake.gemspec CHANGED
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  $LOAD_PATH.push File.expand_path('lib', __dir__)
2
4
 
3
5
  # Maintain your gem's version:
@@ -14,12 +16,14 @@ Gem::Specification.new do |s|
14
16
  s.description = ''
15
17
  s.license = 'MIT'
16
18
 
17
- s.files = `git ls-files`.split("\n").sort
18
- s.test_files = `git ls-files -- spec/*`.split("\n")
19
+ s.files = `git ls-files`.split("\n").sort
19
20
 
20
- s.required_ruby_version = '> 2.0'
21
+ s.required_ruby_version = '> 2.3'
21
22
  s.add_dependency 'activesupport'
22
23
 
23
- s.add_development_dependency 'rspec'
24
24
  s.add_development_dependency 'activesupport'
25
+ s.add_development_dependency 'brakeman'
26
+ s.add_development_dependency 'byebug'
27
+ s.add_development_dependency 'rspec'
28
+ s.metadata['rubygems_mfa_required'] = 'true'
25
29
  end
@@ -1,26 +1,40 @@
1
- require 'active_support'
2
- require 'active_support/core_ext'
1
+ # frozen_string_literal: true
3
2
 
3
+ # Convert the keys of hashes in nested structures to camel or snake case.
4
4
  module CamelSnakeKeys
5
5
  [Hash, Array].each do |klass|
6
6
  refine klass do
7
- def with_camel_keys(indifference=false)
8
- CamelSnakeKeys.camel_keys(self, indifference)
7
+ def with_camel_keys
8
+ CamelSnakeKeys.camel_keys(self)
9
9
  end
10
10
 
11
- def with_snake_keys(indifference=false)
12
- CamelSnakeKeys.snake_keys(self, indifference)
11
+ def with_snake_keys
12
+ CamelSnakeKeys.snake_keys(self)
13
13
  end
14
14
  end
15
15
  end
16
16
 
17
17
  class << self
18
+ def camelcase(obj)
19
+ string = +obj.to_s # unfreeze whatever it might be with a leading +
20
+ string.sub!(/^([A-Z])/) { $1.downcase }
21
+ string.gsub!(/_([a-z\d])/) { $1.capitalize }
22
+ string
23
+ end
24
+
25
+ def snakecase(obj)
26
+ string = +obj.to_s
27
+ string.gsub!(/([A-Z])/) { "_#{$1}" }
28
+ string.downcase!
29
+ string
30
+ end
31
+
18
32
  def if_underscore(obj)
19
33
  case obj
20
34
  when Symbol
21
- obj.to_s.underscore.to_sym
35
+ snakecase(obj.to_s).to_sym
22
36
  when String
23
- obj.underscore
37
+ snakecase(obj)
24
38
  else
25
39
  obj
26
40
  end
@@ -29,34 +43,32 @@ module CamelSnakeKeys
29
43
  def if_camelize(obj)
30
44
  case obj
31
45
  when Symbol
32
- obj.to_s.camelize(:lower).to_sym
46
+ camelcase(obj.to_s).to_sym
33
47
  when String
34
- obj.camelize(:lower)
48
+ camelcase(obj)
35
49
  else
36
50
  obj
37
51
  end
38
52
  end
39
53
 
40
- def snake_keys(data, indifference=false)
54
+ def snake_keys(data)
41
55
  case data
42
56
  when Array
43
- data.map { |v| snake_keys(v, indifference) }
57
+ data.map { |v| snake_keys(v) }
44
58
  when Hash
45
- hash = data.sort_by {|k, _v| k =~ /_/ ? 0 : 1 }.map {|k, v| [if_underscore(k), snake_keys(v, indifference)] }.to_h
46
- hash = hash.with_indifferent_access if indifference
59
+ hash = data.sort_by { |k, _v| k.to_s =~ /_/ ? 0 : 1 }.to_h { |k, v| [if_underscore(k), snake_keys(v)] }
47
60
  data.instance_of?(Hash) ? hash : data.class.new(hash)
48
61
  else
49
62
  data
50
63
  end
51
64
  end
52
65
 
53
- def camel_keys(data, indifference=false)
66
+ def camel_keys(data)
54
67
  case data
55
68
  when Array
56
- data.map { |v| camel_keys(v, indifference) }
69
+ data.map { |v| camel_keys(v) }
57
70
  when Hash
58
- hash = data.sort_by {|k, _v| k =~ /_/ ? 1 : 0 }.map {|k, v| [if_camelize(k), camel_keys(v, indifference)] }.to_h
59
- hash = hash.with_indifferent_access if indifference
71
+ hash = data.sort_by { |k, _v| k.to_s =~ /_/ ? 1 : 0 }.to_h { |k, v| [if_camelize(k), camel_keys(v)] }
60
72
  data.instance_of?(Hash) ? hash : data.class.new(hash)
61
73
  else
62
74
  data
data/lib/version.rb CHANGED
@@ -1,5 +1,8 @@
1
+ # frozen_string_literal: true
2
+
3
+ # Store the version of the gem here rather than the gemspec
1
4
  module CamelSnakeKeys
2
- VERSION = '0.0.7'.freeze
5
+ VERSION = '1.0.0'
3
6
 
4
7
  def self.version
5
8
  VERSION
@@ -1,136 +1,186 @@
1
1
  require 'test_helper'
2
+ require 'byebug'
2
3
  require 'hashie/mash'
4
+ require 'active_support/core_ext/hash/indifferent_access'
3
5
 
4
6
  using CamelSnakeKeys
5
7
 
6
8
  RSpec.describe Enumerable do
7
9
 
8
- context "arrays" do
9
- let(:snaked) { [[{true=>false, 1=>1.2, 1.2=>1, nil=>2, :foo_bar=>1, "dark_matter"=>[{:dark_energy=>"aBc", "baz_qux"=>"Frob."}]}]] }
10
- let(:camelized) { [[{true=>false, 1=>1.2, 1.2=>1, nil=>2, :fooBar=>1, "darkMatter"=>[{:darkEnergy=>"aBc", "bazQux"=>"Frob."}]}]] }
10
+ context 'camelize and underscore' do
11
+ let(:underscore_to_camel) {
12
+ {
13
+ "product" => "product",
14
+ "special_guest" => "specialGuest",
15
+ "application_controller" => "applicationController",
16
+ "area51_controller" => "area51Controller",
17
+ product: "product",
18
+ special_guest: "specialGuest",
19
+ application_controller: "applicationController",
20
+ area51_controller: "area51Controller",
21
+ "camel_snake/keys" => "camelSnake/keys",
22
+ "camel_snake::keys" => "camelSnake::keys"
23
+ }
24
+ }
25
+ it "converts strings and symbols to camel and snake case strings as expected" do
26
+ underscore_to_camel.each do |k,v|
27
+ CamelSnakeKeys.camelcase(k).should eq v.to_s
28
+ CamelSnakeKeys.snakecase(v).should eq k.to_s
29
+ end
30
+ end
31
+
32
+ it "handles nils gracefully" do
33
+ CamelSnakeKeys.camelcase(nil).should eq ""
34
+ CamelSnakeKeys.snakecase(nil).should eq ""
35
+ end
36
+ end
37
+
38
+ context 'arrays' do
39
+ let(:snaked) do
40
+ [[{ true => false, 1 => 1.2, 1.2 => 1, nil => 2, :foo_bar => 1,
41
+ 'dark_matter' => [{ :dark_energy => 'aBc', 'baz_qux' => 'Frob.' }] }]]
42
+ end
43
+ let(:camelized) do
44
+ [[{ true => false, 1 => 1.2, 1.2 => 1, nil => 2, :fooBar => 1,
45
+ 'darkMatter' => [{ :darkEnergy => 'aBc', 'bazQux' => 'Frob.' }] }]]
46
+ end
11
47
 
12
- it "should snake case keys of hashes" do
48
+ it 'should snake case keys of hashes' do
13
49
  camelized.with_snake_keys.should eq snaked
14
50
  end
15
51
 
16
- it "should camel case keys of hashes" do
52
+ it 'should camel case keys of hashes' do
17
53
  snaked.with_camel_keys.should eq camelized
18
54
  end
19
-
20
55
  end
21
56
 
22
- context "hashes" do
23
- let(:snaked) { {false=>true, 1=>1.2, 1.2=>1, nil=>2, :foo_bar=>1, "dark_matter"=>[{:dark_energy=>"aBc", "baz_qux"=>"Frob."}]} }
24
- let(:camelized) { {false=>true, 1=>1.2, 1.2=>1, nil=>2, :fooBar=>1, "darkMatter"=>[{:darkEnergy=>"aBc", "bazQux"=>"Frob."}]} }
57
+ context 'hashes' do
58
+ let(:snaked) do
59
+ { false => true, 1 => 1.2, 1.2 => 1, nil => 2, :foo_bar => 1,
60
+ 'dark_matter' => [{ :dark_energy => 'aBc', 'baz_qux' => 'Frob.' }] }
61
+ end
62
+ let(:camelized) do
63
+ { false => true, 1 => 1.2, 1.2 => 1, nil => 2, :fooBar => 1,
64
+ 'darkMatter' => [{ :darkEnergy => 'aBc', 'bazQux' => 'Frob.' }] }
65
+ end
25
66
 
26
- it "should snake case keys of hashes" do
67
+ it 'should snake case keys of hashes' do
27
68
  hash = camelized.with_snake_keys
28
69
  hash.class.should eq Hash
29
70
  hash.should eq snaked
30
71
  end
31
72
 
32
- it "should camel case keys of hashes" do
73
+ it 'should camel case keys of hashes' do
33
74
  hash = snaked.with_camel_keys
34
75
  hash.class.should eq Hash
35
76
  hash.should eq camelized
36
77
  end
37
78
 
38
- it "should preserve symbol keys" do
79
+ it 'should preserve symbol keys' do
39
80
  camelized.with_snake_keys[:foo_bar].should_not be_nil
40
81
  camelized.with_snake_keys['foo_bar'].should be_nil
41
82
  snaked.with_camel_keys[:fooBar].should be_present
42
83
  snaked.with_camel_keys['fooBar'].should be_nil
43
84
  end
44
85
 
45
- it "should preserve string keys" do
86
+ it 'should preserve string keys' do
46
87
  camelized.with_snake_keys['dark_matter'].should be_present
47
88
  camelized.with_snake_keys[:dark_matter].should be_nil
48
89
  snaked.with_camel_keys['darkMatter'].should be_present
49
90
  snaked.with_camel_keys[:darkMatter].should be_nil
50
91
  end
51
92
 
52
- it "should snake case keys of hashes with indifference" do
53
- hash = camelized.with_snake_keys(true)
93
+ it 'should snake case keys of hashes with indifference' do
94
+ hash = camelized.with_indifferent_access.with_snake_keys
54
95
  hash.class.should eq HashWithIndifferentAccess
55
96
  hash.should eq snaked.with_indifferent_access
56
- hash[:foo_bar].should eq hash["foo_bar"]
97
+ hash[:foo_bar].should eq hash['foo_bar']
57
98
  end
58
99
 
59
- it "should camel case keys of hashes with indifference" do
60
- hash = snaked.with_camel_keys(true)
100
+ it 'should camel case keys of hashes with indifference' do
101
+ hash = snaked.with_indifferent_access.with_camel_keys
61
102
  hash.class.should eq HashWithIndifferentAccess
62
103
  hash.should eq camelized.with_indifferent_access
63
- hash["fooBar"].should eq hash[:fooBar]
104
+ hash['fooBar'].should eq hash[:fooBar]
64
105
  end
65
-
66
106
  end
67
107
 
68
- context "hashes with indifferent access" do
69
- let(:snaked) { {1.2=>1, 1=>1.2, nil=>2, :foo_bar=>1, "dark_matter"=>[{:dark_energy=>"aBc", "baz_qux"=>"Frob."}]}.with_indifferent_access }
70
- let(:camelized) { { 1.2=>1, 1=>1.2, nil=>2, :fooBar=>1, "darkMatter"=>[{:darkEnergy=>"aBc", "bazQux"=>"Frob."}]}.with_indifferent_access }
108
+ context 'hashes with indifferent access' do
109
+ let(:snaked) do
110
+ { 1.2 => 1, 1 => 1.2, nil => 2, :foo_bar => 1,
111
+ 'dark_matter' => [{ :dark_energy => 'aBc', 'baz_qux' => 'Frob.' }] }.with_indifferent_access
112
+ end
113
+ let(:camelized) do
114
+ { 1.2 => 1, 1 => 1.2, nil => 2, :fooBar => 1,
115
+ 'darkMatter' => [{ :darkEnergy => 'aBc', 'bazQux' => 'Frob.' }] }.with_indifferent_access
116
+ end
71
117
 
72
- it "should snake case keys of hashes" do
118
+ it 'should snake case keys of hashes' do
73
119
  hash = camelized.with_snake_keys
74
120
  hash.class.should eq HashWithIndifferentAccess
75
121
  hash.should eq snaked
76
122
  end
77
123
 
78
- it "should camel case keys of hashes" do
124
+ it 'should camel case keys of hashes' do
79
125
  hash = snaked.with_camel_keys
80
126
  hash.class.should eq HashWithIndifferentAccess
81
127
  hash.should eq camelized
82
128
  end
83
129
 
84
- it "should snake case keys of hashes with indifference" do
85
- hash = camelized.with_snake_keys(true)
130
+ it 'should snake case keys of hashes with indifference' do
131
+ hash = camelized.with_indifferent_access.with_snake_keys
86
132
  hash.class.should eq HashWithIndifferentAccess
87
133
  hash.should eq snaked
88
134
  end
89
135
 
90
- it "should camel case keys of hashes with indifference" do
91
- hash = snaked.with_camel_keys(true)
136
+ it 'should camel case keys of hashes with indifference' do
137
+ hash = snaked.with_indifferent_access.with_camel_keys
92
138
  hash.class.should eq HashWithIndifferentAccess
93
139
  hash.should eq camelized
94
140
  end
95
-
96
141
  end
97
142
 
98
- context "mashes" do
99
- let(:snaked) { Hashie::Mash.new({1.2=>1, 1=>1.2, nil=>2, :foo_bar=>1, "dark_matter"=>[{:dark_energy=>"aBc", "baz_qux"=>"Frob."}]}) }
100
- let(:camelized) { Hashie::Mash.new({ 1.2=>1, 1=>1.2, nil=>2, :fooBar=>1, "darkMatter"=>[{:darkEnergy=>"aBc", "bazQux"=>"Frob."}]}) }
143
+ context 'mashes' do
144
+ let(:snaked) do
145
+ Hashie::Mash.new({ 1.2 => 1, 1 => 1.2, nil => 2, :foo_bar => 1,
146
+ 'dark_matter' => [{ :dark_energy => 'aBc', 'baz_qux' => 'Frob.' }] })
147
+ end
148
+ let(:camelized) do
149
+ Hashie::Mash.new({ 1.2 => 1, 1 => 1.2, nil => 2, :fooBar => 1,
150
+ 'darkMatter' => [{ :darkEnergy => 'aBc', 'bazQux' => 'Frob.' }] })
151
+ end
101
152
 
102
- it "should snake case keys of hashes" do
153
+ it 'should snake case keys of hashes' do
103
154
  hash = camelized.with_snake_keys
104
155
  hash.class.should eq Hashie::Mash
105
156
  hash.should eq snaked
106
- hash["fooBar"].should eq hash[:fooBar]
157
+ hash['fooBar'].should eq hash[:fooBar]
107
158
  end
108
159
 
109
- it "should camel case keys of hashes" do
160
+ it 'should camel case keys of hashes' do
110
161
  hash = snaked.with_camel_keys
111
162
  hash.class.should eq Hashie::Mash
112
163
  hash.should eq camelized
113
- hash["foo_bar"].should eq hash[:foo_bar]
164
+ hash['foo_bar'].should eq hash[:foo_bar]
114
165
  end
115
166
 
116
- it "should snake case keys of hashes with redundant indifference" do
117
- hash = camelized.with_snake_keys(true)
167
+ it 'should snake case keys of hashes with redundant indifference' do
168
+ hash = Hashie::Mash.new(camelized.with_snake_keys.with_indifferent_access)
118
169
  hash.class.should eq Hashie::Mash
119
170
  hash.should eq snaked
120
- hash["foo_bar"].should eq hash[:foo_bar]
171
+ hash['foo_bar'].should eq hash[:foo_bar]
121
172
  end
122
173
 
123
- it "should camel case keys of hashes with redundant indifference" do
124
- hash = snaked.with_camel_keys(true)
174
+ it 'should camel case keys of hashes with redundant indifference' do
175
+ hash = Hashie::Mash.new(snaked.with_camel_keys.with_indifferent_access)
125
176
  hash.class.should eq Hashie::Mash
126
177
  hash.should eq camelized
127
- hash["foo_bar"].should eq hash[:foo_bar]
178
+ hash['foo_bar'].should eq hash[:foo_bar]
128
179
  end
129
-
130
180
  end
131
181
 
132
- context "hash merge conflicts should be resolved predictably" do
133
- it "should give camel case key values priority when snake casing" do
182
+ context 'hash merge conflicts should be resolved predictably' do
183
+ it 'should give camel case key values priority when snake casing' do
134
184
  hash = { foo_bar: 1, fooBar: 2 }
135
185
  result = { foo_bar: 2 }
136
186
  hash.with_snake_keys.should eq result
@@ -139,9 +189,10 @@ RSpec.describe Enumerable do
139
189
  hash.with_snake_keys.should eq result
140
190
  end
141
191
 
142
- it "should give snake case key values priority when camel casing" do
143
- hash = { foo_bar: 1, fooBar: 2 }
192
+ it 'should give snake case key values priority when camel casing' do
144
193
  result = { fooBar: 1 }
194
+
195
+ hash = { foo_bar: 1, fooBar: 2 }
145
196
  hash.with_camel_keys.should eq result
146
197
 
147
198
  hash = { fooBar: 2, foo_bar: 1 }
@@ -149,30 +200,29 @@ RSpec.describe Enumerable do
149
200
  end
150
201
  end
151
202
 
152
- context "it should pass indifference down deeply nested structures" do
153
- it "camelizing an array of hashes" do
154
- camelized = [ a: { b: [{c: :d}] } ].with_camel_keys(true)
203
+ context 'it should pass indifference down deeply nested structures' do
204
+ it 'camelizing an array of hashes' do
205
+ camelized = [a: { b: [{ c: :d }] }].with_camel_keys.map(&:with_indifferent_access)
155
206
  camelized.first[:a].is_a?(HashWithIndifferentAccess).should be_truthy
156
207
  camelized.first[:a][:b].first.is_a?(HashWithIndifferentAccess).should be_truthy
157
208
  end
158
209
 
159
- it "cazemlizing a hashes of arrays" do
160
- camelized = { a: [{b: {c: :d}}]}.with_camel_keys(true)
210
+ it 'cazemlizing a hashes of arrays' do
211
+ camelized = { a: [{ b: { c: :d } }] }.with_camel_keys.with_indifferent_access
161
212
  camelized.is_a?(HashWithIndifferentAccess).should be_truthy
162
213
  camelized[:a].first[:b].is_a?(HashWithIndifferentAccess).should be_truthy
163
214
  end
164
215
 
165
- it "snaking an array of hashes" do
166
- snaked = [ a: { b: [{c: :d}] } ].with_snake_keys(true)
216
+ it 'snaking an array of hashes' do
217
+ snaked = [a: { b: [{ c: :d }] }].with_snake_keys.map(&:with_indifferent_access)
167
218
  snaked.first[:a].is_a?(HashWithIndifferentAccess).should be_truthy
168
219
  snaked.first[:a][:b].first.is_a?(HashWithIndifferentAccess).should be_truthy
169
220
  end
170
221
 
171
- it "snaking a hashes of arrays" do
172
- snaked = { a: [{b: {c: :d}}]}.with_snake_keys(true)
222
+ it 'snaking a hashes of arrays' do
223
+ snaked = { a: [{ b: { c: :d } }] }.with_snake_keys.with_indifferent_access
173
224
  snaked.is_a?(HashWithIndifferentAccess).should be_truthy
174
225
  snaked[:a].first[:b].is_a?(HashWithIndifferentAccess).should be_truthy
175
226
  end
176
-
177
227
  end
178
228
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: camel_snake_keys
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.7
4
+ version: 1.0.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Josh Buermann
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2022-02-08 00:00:00.000000000 Z
11
+ date: 2024-01-31 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: activesupport
@@ -25,7 +25,7 @@ dependencies:
25
25
  - !ruby/object:Gem::Version
26
26
  version: '0'
27
27
  - !ruby/object:Gem::Dependency
28
- name: rspec
28
+ name: activesupport
29
29
  requirement: !ruby/object:Gem::Requirement
30
30
  requirements:
31
31
  - - ">="
@@ -39,7 +39,35 @@ dependencies:
39
39
  - !ruby/object:Gem::Version
40
40
  version: '0'
41
41
  - !ruby/object:Gem::Dependency
42
- name: activesupport
42
+ name: brakeman
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - ">="
46
+ - !ruby/object:Gem::Version
47
+ version: '0'
48
+ type: :development
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - ">="
53
+ - !ruby/object:Gem::Version
54
+ version: '0'
55
+ - !ruby/object:Gem::Dependency
56
+ name: byebug
57
+ requirement: !ruby/object:Gem::Requirement
58
+ requirements:
59
+ - - ">="
60
+ - !ruby/object:Gem::Version
61
+ version: '0'
62
+ type: :development
63
+ prerelease: false
64
+ version_requirements: !ruby/object:Gem::Requirement
65
+ requirements:
66
+ - - ">="
67
+ - !ruby/object:Gem::Version
68
+ version: '0'
69
+ - !ruby/object:Gem::Dependency
70
+ name: rspec
43
71
  requirement: !ruby/object:Gem::Requirement
44
72
  requirements:
45
73
  - - ">="
@@ -60,10 +88,10 @@ extensions: []
60
88
  extra_rdoc_files: []
61
89
  files:
62
90
  - ".coveralls.yml"
91
+ - ".github/workflows/main.yml"
63
92
  - ".gitignore"
64
93
  - ".rubocop.yml"
65
94
  - ".ruby-version"
66
- - ".travis.yml"
67
95
  - CHANGELOG.md
68
96
  - Gemfile
69
97
  - README.md
@@ -76,7 +104,8 @@ files:
76
104
  homepage: https://github.com/buermann/camel_snake_keys
77
105
  licenses:
78
106
  - MIT
79
- metadata: {}
107
+ metadata:
108
+ rubygems_mfa_required: 'true'
80
109
  post_install_message:
81
110
  rdoc_options: []
82
111
  require_paths:
@@ -85,17 +114,15 @@ required_ruby_version: !ruby/object:Gem::Requirement
85
114
  requirements:
86
115
  - - ">"
87
116
  - !ruby/object:Gem::Version
88
- version: '2.0'
117
+ version: '2.3'
89
118
  required_rubygems_version: !ruby/object:Gem::Requirement
90
119
  requirements:
91
120
  - - ">="
92
121
  - !ruby/object:Gem::Version
93
122
  version: '0'
94
123
  requirements: []
95
- rubygems_version: 3.2.15
124
+ rubygems_version: 3.5.3
96
125
  signing_key:
97
126
  specification_version: 4
98
127
  summary: Convert nested data structure hash keys between camel and snake case.
99
- test_files:
100
- - spec/lib/camel_snake_keys_spec.rb
101
- - spec/test_helper.rb
128
+ test_files: []
data/.travis.yml DELETED
@@ -1,31 +0,0 @@
1
- language: ruby
2
- before_install:
3
- - gem install bundler -v 1.17.3
4
- - gem install rspec
5
- install: bundle install --jobs=1 --retry=1
6
- script:
7
- - bundle install
8
- - bundle exec rspec
9
-
10
- rvm:
11
- - 2.3.1
12
- # - 2.4.0
13
- # - 2.5.0
14
- # - ruby-head
15
- # - jruby-head
16
-
17
- matrix:
18
- allow_failures:
19
- - rvm: ruby-head
20
- - rvm: jruby-head
21
-
22
- env:
23
- global:
24
- - JRUBY_OPTS="-J-Xmx1024m --debug"
25
-
26
- notifications:
27
- email:
28
- recipients:
29
- - buermann@gmail.com
30
- on_success: change
31
- on_failure: always