camel_snake_keys 0.0.7 → 1.1.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
2
  SHA256:
3
- metadata.gz: 7969aad0c0f379d148318435d02673f72be7938e6cbb33a084df50a79261f11f
4
- data.tar.gz: a5841106f20246186321b692f612ee64d28cef2d8568589f769a5e8765badf0f
3
+ metadata.gz: 7a43ef9734380b43f45291290bb618394c59d90f5f4b4063971a43a3c3580fba
4
+ data.tar.gz: 23d0e08b903cf6ed0db29576f2f6fe9258b897ce93e9c2cea2c158bc0d93a142
5
5
  SHA512:
6
- metadata.gz: 7f154ed7f42d8c3061a71c708e6c9265ea965698f97c6ce367433ec7d0ec472d1ee52253b71b6c9b9e80d25cd4db0ab62d8a7027bb1688685d853655dc4b996f
7
- data.tar.gz: 7c97476f9e93bc057daf1e6d71f376fb681e50f12797d9862147ca8fcff8700872f641e3426e88c02c7fccc04e4d7aade342e67c1193ebf90f1ebf6ca697ca52
6
+ metadata.gz: a7bc99bde80faed7b2de698ade5e57b0141ad2b017f7c6d6b57f6cc038d3ca0128aded3712fd51ebb43b50debea74c8e208b167a0fa9a84f7d049881d2730f34
7
+ data.tar.gz: 3f8f91a41a00d89683b4309e771c788f6ff6ba6fc7a0d0faf7576b5ddfa6a13d23d813b03d6e856ddbe7e7dbbffa0fbadf4dd2ff374af9b519fbac1e15fb1519
@@ -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,44 @@
1
- 0.0.7 2/08/2022
2
- ==============
1
+ 1.0.0 01/31/2024
2
+ ================
3
+
4
+ Test against Ruby 3.3.0.
5
+
6
+ Don't let integer hash keys unleashed the bees.
7
+
8
+ Fix an introduced bug that produces leading underscores when snaking PascalCase.
9
+
10
+ 0.1.0 10/14/2022
11
+ ================
12
+
13
+ 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.
14
+
15
+ 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.
16
+
17
+ We are not re-implmenting ActiveSupport's acronym inflections. Yet.
18
+
19
+ Replace travis etc. with github actions.
20
+
21
+ 0.0.7 02/08/2022
22
+ ================
3
23
 
4
24
  Support Ruby 3+
5
25
 
6
- 0.0.6 4/07/2020
7
- ==============
26
+ 0.0.6 04/07/2020
27
+ ===============
8
28
 
9
29
  ### Bug fix
10
30
 
11
31
  Pass the indifferent access flag down the recursion.
12
32
 
13
- 0.0.3 5/11/2016
14
- ==============
33
+ 0.0.3 05/11/2016
34
+ ================
15
35
 
16
36
  ### Features
17
37
 
18
38
  Preserve any descendent of Hash that accepts a Hash in its initialize method, as with ActiveSupport::HashWithIndifferentAccess and Hashie::Mash
19
39
 
20
- 0.0.2 5/11/2016
21
- ==============
40
+ 0.0.2 05/11/2016
41
+ ================
22
42
 
23
43
  ### Features
24
44
 
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,41 @@
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[0] = string[0].downcase if string[0]
28
+ string.gsub!(/([A-Z])/) { "_#{$1}" }
29
+ string.downcase!
30
+ string
31
+ end
32
+
18
33
  def if_underscore(obj)
19
34
  case obj
20
35
  when Symbol
21
- obj.to_s.underscore.to_sym
36
+ snakecase(obj.to_s).to_sym
22
37
  when String
23
- obj.underscore
38
+ snakecase(obj)
24
39
  else
25
40
  obj
26
41
  end
@@ -29,34 +44,32 @@ module CamelSnakeKeys
29
44
  def if_camelize(obj)
30
45
  case obj
31
46
  when Symbol
32
- obj.to_s.camelize(:lower).to_sym
47
+ camelcase(obj.to_s).to_sym
33
48
  when String
34
- obj.camelize(:lower)
49
+ camelcase(obj)
35
50
  else
36
51
  obj
37
52
  end
38
53
  end
39
54
 
40
- def snake_keys(data, indifference=false)
55
+ def snake_keys(data)
41
56
  case data
42
57
  when Array
43
- data.map { |v| snake_keys(v, indifference) }
58
+ data.map { |v| snake_keys(v) }
44
59
  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
60
+ hash = data.sort_by { |k, _v| k.to_s =~ /_/ ? 0 : 1 }.to_h { |k, v| [if_underscore(k), snake_keys(v)] }
47
61
  data.instance_of?(Hash) ? hash : data.class.new(hash)
48
62
  else
49
63
  data
50
64
  end
51
65
  end
52
66
 
53
- def camel_keys(data, indifference=false)
67
+ def camel_keys(data)
54
68
  case data
55
69
  when Array
56
- data.map { |v| camel_keys(v, indifference) }
70
+ data.map { |v| camel_keys(v) }
57
71
  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
72
+ hash = data.sort_by { |k, _v| k.to_s =~ /_/ ? 1 : 0 }.to_h { |k, v| [if_camelize(k), camel_keys(v)] }
60
73
  data.instance_of?(Hash) ? hash : data.class.new(hash)
61
74
  else
62
75
  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.1.0'
3
6
 
4
7
  def self.version
5
8
  VERSION
@@ -1,136 +1,191 @@
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
+
37
+ it "handles pascal case (destructively)" do
38
+ CamelSnakeKeys.camelcase("pascal_case").should eq "pascalCase"
39
+ CamelSnakeKeys.snakecase("PascalCase").should eq "pascal_case"
40
+ end
41
+ end
42
+
43
+ context 'arrays' do
44
+ let(:snaked) do
45
+ [[{ true => false, 1 => 1.2, 1.2 => 1, nil => 2, :foo_bar => 1,
46
+ 'dark_matter' => [{ :dark_energy => 'aBc', 'baz_qux' => 'Frob.' }] }]]
47
+ end
48
+ let(:camelized) do
49
+ [[{ true => false, 1 => 1.2, 1.2 => 1, nil => 2, :fooBar => 1,
50
+ 'darkMatter' => [{ :darkEnergy => 'aBc', 'bazQux' => 'Frob.' }] }]]
51
+ end
11
52
 
12
- it "should snake case keys of hashes" do
53
+ it 'should snake case keys of hashes' do
13
54
  camelized.with_snake_keys.should eq snaked
14
55
  end
15
56
 
16
- it "should camel case keys of hashes" do
57
+ it 'should camel case keys of hashes' do
17
58
  snaked.with_camel_keys.should eq camelized
18
59
  end
19
-
20
60
  end
21
61
 
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."}]} }
62
+ context 'hashes' do
63
+ let(:snaked) do
64
+ { false => true, 1 => 1.2, 1.2 => 1, nil => 2, :foo_bar => 1,
65
+ 'dark_matter' => [{ :dark_energy => 'aBc', 'baz_qux' => 'Frob.' }] }
66
+ end
67
+ let(:camelized) do
68
+ { false => true, 1 => 1.2, 1.2 => 1, nil => 2, :fooBar => 1,
69
+ 'darkMatter' => [{ :darkEnergy => 'aBc', 'bazQux' => 'Frob.' }] }
70
+ end
25
71
 
26
- it "should snake case keys of hashes" do
72
+ it 'should snake case keys of hashes' do
27
73
  hash = camelized.with_snake_keys
28
74
  hash.class.should eq Hash
29
75
  hash.should eq snaked
30
76
  end
31
77
 
32
- it "should camel case keys of hashes" do
78
+ it 'should camel case keys of hashes' do
33
79
  hash = snaked.with_camel_keys
34
80
  hash.class.should eq Hash
35
81
  hash.should eq camelized
36
82
  end
37
83
 
38
- it "should preserve symbol keys" do
84
+ it 'should preserve symbol keys' do
39
85
  camelized.with_snake_keys[:foo_bar].should_not be_nil
40
86
  camelized.with_snake_keys['foo_bar'].should be_nil
41
87
  snaked.with_camel_keys[:fooBar].should be_present
42
88
  snaked.with_camel_keys['fooBar'].should be_nil
43
89
  end
44
90
 
45
- it "should preserve string keys" do
91
+ it 'should preserve string keys' do
46
92
  camelized.with_snake_keys['dark_matter'].should be_present
47
93
  camelized.with_snake_keys[:dark_matter].should be_nil
48
94
  snaked.with_camel_keys['darkMatter'].should be_present
49
95
  snaked.with_camel_keys[:darkMatter].should be_nil
50
96
  end
51
97
 
52
- it "should snake case keys of hashes with indifference" do
53
- hash = camelized.with_snake_keys(true)
98
+ it 'should snake case keys of hashes with indifference' do
99
+ hash = camelized.with_indifferent_access.with_snake_keys
54
100
  hash.class.should eq HashWithIndifferentAccess
55
101
  hash.should eq snaked.with_indifferent_access
56
- hash[:foo_bar].should eq hash["foo_bar"]
102
+ hash[:foo_bar].should eq hash['foo_bar']
57
103
  end
58
104
 
59
- it "should camel case keys of hashes with indifference" do
60
- hash = snaked.with_camel_keys(true)
105
+ it 'should camel case keys of hashes with indifference' do
106
+ hash = snaked.with_indifferent_access.with_camel_keys
61
107
  hash.class.should eq HashWithIndifferentAccess
62
108
  hash.should eq camelized.with_indifferent_access
63
- hash["fooBar"].should eq hash[:fooBar]
109
+ hash['fooBar'].should eq hash[:fooBar]
64
110
  end
65
-
66
111
  end
67
112
 
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 }
113
+ context 'hashes with indifferent access' do
114
+ let(:snaked) do
115
+ { 1.2 => 1, 1 => 1.2, nil => 2, :foo_bar => 1,
116
+ 'dark_matter' => [{ :dark_energy => 'aBc', 'baz_qux' => 'Frob.' }] }.with_indifferent_access
117
+ end
118
+ let(:camelized) do
119
+ { 1.2 => 1, 1 => 1.2, nil => 2, :fooBar => 1,
120
+ 'darkMatter' => [{ :darkEnergy => 'aBc', 'bazQux' => 'Frob.' }] }.with_indifferent_access
121
+ end
71
122
 
72
- it "should snake case keys of hashes" do
123
+ it 'should snake case keys of hashes' do
73
124
  hash = camelized.with_snake_keys
74
125
  hash.class.should eq HashWithIndifferentAccess
75
126
  hash.should eq snaked
76
127
  end
77
128
 
78
- it "should camel case keys of hashes" do
129
+ it 'should camel case keys of hashes' do
79
130
  hash = snaked.with_camel_keys
80
131
  hash.class.should eq HashWithIndifferentAccess
81
132
  hash.should eq camelized
82
133
  end
83
134
 
84
- it "should snake case keys of hashes with indifference" do
85
- hash = camelized.with_snake_keys(true)
135
+ it 'should snake case keys of hashes with indifference' do
136
+ hash = camelized.with_indifferent_access.with_snake_keys
86
137
  hash.class.should eq HashWithIndifferentAccess
87
138
  hash.should eq snaked
88
139
  end
89
140
 
90
- it "should camel case keys of hashes with indifference" do
91
- hash = snaked.with_camel_keys(true)
141
+ it 'should camel case keys of hashes with indifference' do
142
+ hash = snaked.with_indifferent_access.with_camel_keys
92
143
  hash.class.should eq HashWithIndifferentAccess
93
144
  hash.should eq camelized
94
145
  end
95
-
96
146
  end
97
147
 
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."}]}) }
148
+ context 'mashes' do
149
+ let(:snaked) do
150
+ Hashie::Mash.new({ 1.2 => 1, 1 => 1.2, nil => 2, :foo_bar => 1,
151
+ 'dark_matter' => [{ :dark_energy => 'aBc', 'baz_qux' => 'Frob.' }] })
152
+ end
153
+ let(:camelized) do
154
+ Hashie::Mash.new({ 1.2 => 1, 1 => 1.2, nil => 2, :fooBar => 1,
155
+ 'darkMatter' => [{ :darkEnergy => 'aBc', 'bazQux' => 'Frob.' }] })
156
+ end
101
157
 
102
- it "should snake case keys of hashes" do
158
+ it 'should snake case keys of hashes' do
103
159
  hash = camelized.with_snake_keys
104
160
  hash.class.should eq Hashie::Mash
105
161
  hash.should eq snaked
106
- hash["fooBar"].should eq hash[:fooBar]
162
+ hash['fooBar'].should eq hash[:fooBar]
107
163
  end
108
164
 
109
- it "should camel case keys of hashes" do
165
+ it 'should camel case keys of hashes' do
110
166
  hash = snaked.with_camel_keys
111
167
  hash.class.should eq Hashie::Mash
112
168
  hash.should eq camelized
113
- hash["foo_bar"].should eq hash[:foo_bar]
169
+ hash['foo_bar'].should eq hash[:foo_bar]
114
170
  end
115
171
 
116
- it "should snake case keys of hashes with redundant indifference" do
117
- hash = camelized.with_snake_keys(true)
172
+ it 'should snake case keys of hashes with redundant indifference' do
173
+ hash = Hashie::Mash.new(camelized.with_snake_keys.with_indifferent_access)
118
174
  hash.class.should eq Hashie::Mash
119
175
  hash.should eq snaked
120
- hash["foo_bar"].should eq hash[:foo_bar]
176
+ hash['foo_bar'].should eq hash[:foo_bar]
121
177
  end
122
178
 
123
- it "should camel case keys of hashes with redundant indifference" do
124
- hash = snaked.with_camel_keys(true)
179
+ it 'should camel case keys of hashes with redundant indifference' do
180
+ hash = Hashie::Mash.new(snaked.with_camel_keys.with_indifferent_access)
125
181
  hash.class.should eq Hashie::Mash
126
182
  hash.should eq camelized
127
- hash["foo_bar"].should eq hash[:foo_bar]
183
+ hash['foo_bar'].should eq hash[:foo_bar]
128
184
  end
129
-
130
185
  end
131
186
 
132
- context "hash merge conflicts should be resolved predictably" do
133
- it "should give camel case key values priority when snake casing" do
187
+ context 'hash merge conflicts should be resolved predictably' do
188
+ it 'should give camel case key values priority when snake casing' do
134
189
  hash = { foo_bar: 1, fooBar: 2 }
135
190
  result = { foo_bar: 2 }
136
191
  hash.with_snake_keys.should eq result
@@ -139,9 +194,10 @@ RSpec.describe Enumerable do
139
194
  hash.with_snake_keys.should eq result
140
195
  end
141
196
 
142
- it "should give snake case key values priority when camel casing" do
143
- hash = { foo_bar: 1, fooBar: 2 }
197
+ it 'should give snake case key values priority when camel casing' do
144
198
  result = { fooBar: 1 }
199
+
200
+ hash = { foo_bar: 1, fooBar: 2 }
145
201
  hash.with_camel_keys.should eq result
146
202
 
147
203
  hash = { fooBar: 2, foo_bar: 1 }
@@ -149,30 +205,29 @@ RSpec.describe Enumerable do
149
205
  end
150
206
  end
151
207
 
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)
208
+ context 'it should pass indifference down deeply nested structures' do
209
+ it 'camelizing an array of hashes' do
210
+ camelized = [a: { b: [{ c: :d }] }].with_camel_keys.map(&:with_indifferent_access)
155
211
  camelized.first[:a].is_a?(HashWithIndifferentAccess).should be_truthy
156
212
  camelized.first[:a][:b].first.is_a?(HashWithIndifferentAccess).should be_truthy
157
213
  end
158
214
 
159
- it "cazemlizing a hashes of arrays" do
160
- camelized = { a: [{b: {c: :d}}]}.with_camel_keys(true)
215
+ it 'cazemlizing a hashes of arrays' do
216
+ camelized = { a: [{ b: { c: :d } }] }.with_camel_keys.with_indifferent_access
161
217
  camelized.is_a?(HashWithIndifferentAccess).should be_truthy
162
218
  camelized[:a].first[:b].is_a?(HashWithIndifferentAccess).should be_truthy
163
219
  end
164
220
 
165
- it "snaking an array of hashes" do
166
- snaked = [ a: { b: [{c: :d}] } ].with_snake_keys(true)
221
+ it 'snaking an array of hashes' do
222
+ snaked = [a: { b: [{ c: :d }] }].with_snake_keys.map(&:with_indifferent_access)
167
223
  snaked.first[:a].is_a?(HashWithIndifferentAccess).should be_truthy
168
224
  snaked.first[:a][:b].first.is_a?(HashWithIndifferentAccess).should be_truthy
169
225
  end
170
226
 
171
- it "snaking a hashes of arrays" do
172
- snaked = { a: [{b: {c: :d}}]}.with_snake_keys(true)
227
+ it 'snaking a hashes of arrays' do
228
+ snaked = { a: [{ b: { c: :d } }] }.with_snake_keys.with_indifferent_access
173
229
  snaked.is_a?(HashWithIndifferentAccess).should be_truthy
174
230
  snaked[:a].first[:b].is_a?(HashWithIndifferentAccess).should be_truthy
175
231
  end
176
-
177
232
  end
178
233
  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.1.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