plissken 0.3.0 → 1.0.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
  SHA1:
3
- metadata.gz: e77d7951d8d19a1f90b7f3a5567f9e3d6f5eb78c
4
- data.tar.gz: 4e72105f678443e1867ef93ca24720a0a9a1797b
3
+ metadata.gz: 0c822d80cd3724459bbf8a259f3850be1f920ba1
4
+ data.tar.gz: 8e03901e74f47d5743e5b785670d2d7b6eea6505
5
5
  SHA512:
6
- metadata.gz: d04ca9cb862e04899a42a9962069b42ea70e2ec3bc5858cac508b924c1f3192b9741fcfdc9f7fe3f20f342c416666497aabf54ca0682c886e51fcfa0d716d90e
7
- data.tar.gz: 04fbabf6b14945665375dfaa517c80817adea09b92f60c2d9f15beb912b7cf5b43864baf1b8130ac60318c02a398aede366612ff74fc562a3ff4101b515a7cd0
6
+ metadata.gz: 4d2b4516e6263c6c677aeeef01e1cab7cc1ebaee0ef61bd20268c7eeebbc394b17faef58edab4c7731fd138f8e1805946f95d6797f507bf19f0e2efa5ff82f98
7
+ data.tar.gz: 98a25014463f7946e5aa3eb33f92bf18d93fa625ff2084ba331563fff00b2eb27b3806eda40d87bcbd7875b2e660029d1df2358ed5a254189cc84a5eed4ac1e7
data/README.md CHANGED
@@ -1,6 +1,4 @@
1
- =======
2
- plissken
3
- ========
1
+ # Plissken
4
2
 
5
3
  Have you ever needed to automatically convert JSON-style `camelBack` or `CamelCase` hash keys into more Rubyish `snake_case`?
6
4
 
@@ -8,10 +6,23 @@ Plissken to the rescue.
8
6
 
9
7
  This gem recursively converts all camelBack or CamelCase keys in a hash structure to snake_case.
10
8
 
9
+ ## Installation
10
+
11
+ Add this to your Gemfile:
12
+
13
+ ```ruby
14
+ gem "plissken"
15
+ ```
16
+
17
+ Or install it yourself as:
18
+
19
+ ```bash
20
+ gem install plissken
21
+ ```
22
+
11
23
  ## Usage
12
24
 
13
25
  ```ruby
14
- gem 'plissken'
15
26
  my_hash = {"firstKey" => 1, "fooBars" => [{"bazBaz" => "value"}, {"blahBlah" => "value"}]}
16
27
  snaked_hash = my_hash.to_snake_keys
17
28
  # => {"first_key" => 1, "foo_bars" => [{"baz_baz" => "value"}, {"blah_blah" => "value"}]}
@@ -39,8 +50,7 @@ the [Awrence](http://github.com/futurechimp/awrence) gem.
39
50
  * Make sure to add tests for it. This is important so I don't break it in a future version unintentionally.
40
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.
41
52
 
42
- == Copyright
53
+ ## Copyright
43
54
 
44
55
  Copyright (c) 2013 Dave Hrycyszyn. See LICENSE.txt for
45
56
  further details.
46
-
data/Rakefile CHANGED
@@ -1,56 +1,28 @@
1
- # encoding: utf-8
2
-
3
- require 'rubygems'
4
- require 'bundler'
5
- require 'rspec/core/rake_task'
6
- RSpec::Core::RakeTask.new('spec')
7
-
8
1
  begin
9
- Bundler.setup(:default, :development)
10
- rescue Bundler::BundlerError => e
11
- $stderr.puts e.message
12
- $stderr.puts "Run `bundle install` to install missing gems"
13
- exit e.status_code
2
+ require "bundler/setup"
3
+ rescue LoadError
4
+ puts "You must `gem install bundler` and `bundle install` to run rake tasks"
14
5
  end
15
- require 'rake'
16
-
17
- require 'jeweler'
18
- Jeweler::Tasks.new do |gem|
19
- # gem is a Gem::Specification... see http://docs.rubygems.org/read/chapter/20 for more options
20
- gem.name = "plissken"
21
- gem.homepage = "http://github.com/futurechimp/plissken"
22
- gem.license = "MIT"
23
- gem.summary = %Q{Snakify your camel keys when working with JSON APIs}
24
- gem.description = %Q{
25
- Have you ever needed to automatically convert JSON-style camelBack or
26
- CamelCase hash keys into more Rubyish snake_case?
27
6
 
28
- Plissken to the rescue.
7
+ require "rdoc/task"
29
8
 
30
- This gem recursively converts all camelBack or CamelCase keys in a hash
31
- structure to snake_case.
32
- }
33
- gem.email = "dave.hrycyszyn@headlondon.com"
34
- gem.authors = ["Dave Hrycyszyn", "Michael Chrisco"]
35
- # dependencies defined in Gemfile
9
+ RDoc::Task.new(:rdoc) do |rdoc|
10
+ rdoc.rdoc_dir = "rdoc"
11
+ rdoc.title = "Filta"
12
+ rdoc.options << "--line-numbers"
13
+ rdoc.rdoc_files.include("README.md")
14
+ rdoc.rdoc_files.include("lib/**/*.rb")
36
15
  end
37
- Jeweler::RubygemsDotOrgTasks.new
38
16
 
39
- require 'rake/testtask'
40
- Rake::TestTask.new(:test) do |test|
41
- test.libs << 'lib' << 'test'
42
- test.pattern = 'test/**/test_*.rb'
43
- test.verbose = true
44
- end
45
-
46
- task :default => :spec
17
+ require "bundler/gem_tasks"
47
18
 
48
- require 'rdoc/task'
49
- Rake::RDocTask.new do |rdoc|
50
- version = File.exist?('VERSION') ? File.read('VERSION') : ""
19
+ require "rake/testtask"
51
20
 
52
- rdoc.rdoc_dir = 'rdoc'
53
- rdoc.title = "plissken #{version}"
54
- rdoc.rdoc_files.include('README*')
55
- rdoc.rdoc_files.include('lib/**/*.rb')
21
+ Rake::TestTask.new(:test) do |t|
22
+ t.libs << "lib"
23
+ t.libs << "test"
24
+ t.pattern = "test/**/*_test.rb"
25
+ t.verbose = false
56
26
  end
27
+
28
+ task default: :test
data/VERSION CHANGED
@@ -1 +1 @@
1
- 0.3.0
1
+ 1.0.0
@@ -1 +1,5 @@
1
1
  require File.dirname(__FILE__) + '/plissken/ext/hash/to_snake_keys'
2
+
3
+ module Plissken
4
+
5
+ end
@@ -18,7 +18,7 @@ class Hash
18
18
  private
19
19
 
20
20
  def snake_hash(value)
21
- Hash[value.map { |k, v| [underscore_key(k).to_sym, to_snake_keys(v)] }]
21
+ Hash[value.map { |k, v| [underscore_key(k), to_snake_keys(v)] }]
22
22
  end
23
23
 
24
24
  def underscore_key(k)
@@ -0,0 +1,3 @@
1
+ module Plissken
2
+ VERSION = File.read("VERSION").split("\n").first
3
+ end
metadata CHANGED
@@ -1,115 +1,78 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: plissken
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.3.0
4
+ version: 1.0.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Dave Hrycyszyn
8
8
  - Michael Chrisco
9
+ - Stuart Chinery
9
10
  autorequire:
10
11
  bindir: bin
11
12
  cert_chain: []
12
- date: 2017-01-13 00:00:00.000000000 Z
13
+ date: 2017-07-19 00:00:00.000000000 Z
13
14
  dependencies:
14
15
  - !ruby/object:Gem::Dependency
15
- name: symbolize
16
+ name: minitest
16
17
  requirement: !ruby/object:Gem::Requirement
17
18
  requirements:
18
19
  - - "~>"
19
20
  - !ruby/object:Gem::Version
20
- version: '4.2'
21
- type: :runtime
22
- prerelease: false
23
- version_requirements: !ruby/object:Gem::Requirement
24
- requirements:
25
- - - "~>"
26
- - !ruby/object:Gem::Version
27
- version: '4.2'
28
- - !ruby/object:Gem::Dependency
29
- name: rspec
30
- requirement: !ruby/object:Gem::Requirement
31
- requirements:
32
- - - "~>"
33
- - !ruby/object:Gem::Version
34
- version: '3.1'
35
- type: :development
36
- prerelease: false
37
- version_requirements: !ruby/object:Gem::Requirement
38
- requirements:
39
- - - "~>"
40
- - !ruby/object:Gem::Version
41
- version: '3.1'
42
- - !ruby/object:Gem::Dependency
43
- name: rdoc
44
- requirement: !ruby/object:Gem::Requirement
45
- requirements:
46
- - - "~>"
47
- - !ruby/object:Gem::Version
48
- version: '4.2'
21
+ version: '3.0'
49
22
  type: :development
50
23
  prerelease: false
51
24
  version_requirements: !ruby/object:Gem::Requirement
52
25
  requirements:
53
26
  - - "~>"
54
27
  - !ruby/object:Gem::Version
55
- version: '4.2'
28
+ version: '3.0'
56
29
  - !ruby/object:Gem::Dependency
57
- name: bundler
30
+ name: minitest-reporters
58
31
  requirement: !ruby/object:Gem::Requirement
59
32
  requirements:
60
33
  - - "~>"
61
34
  - !ruby/object:Gem::Version
62
- version: '1.6'
35
+ version: '0.14'
63
36
  type: :development
64
37
  prerelease: false
65
38
  version_requirements: !ruby/object:Gem::Requirement
66
39
  requirements:
67
40
  - - "~>"
68
41
  - !ruby/object:Gem::Version
69
- version: '1.6'
42
+ version: '0.14'
70
43
  - !ruby/object:Gem::Dependency
71
- name: jeweler
44
+ name: rake
72
45
  requirement: !ruby/object:Gem::Requirement
73
46
  requirements:
74
47
  - - "~>"
75
48
  - !ruby/object:Gem::Version
76
- version: '2.3'
49
+ version: '12.0'
77
50
  type: :development
78
51
  prerelease: false
79
52
  version_requirements: !ruby/object:Gem::Requirement
80
53
  requirements:
81
54
  - - "~>"
82
55
  - !ruby/object:Gem::Version
83
- version: '2.3'
84
- description: "\n Have you ever needed to automatically convert JSON-style camelBack
85
- or\n CamelCase hash keys into more Rubyish snake_case?\n\n Plissken to the
86
- rescue.\n\n This gem recursively converts all camelBack or CamelCase keys in
87
- a hash\n structure to snake_case.\n "
88
- email: dave.hrycyszyn@headlondon.com
56
+ version: '12.0'
57
+ description: |-
58
+ Have you ever needed to automatically convert JSON-style camelBack or CamelCase hash keys into more Rubyish snake_case?
59
+
60
+ Plissken to the rescue.
61
+
62
+ This gem recursively converts all camelBack or CamelCase keys in a hash structure to snake_case.
63
+ email:
64
+ - dhrycyszyn@zonedigital.com
89
65
  executables: []
90
66
  extensions: []
91
- extra_rdoc_files:
92
- - LICENSE.txt
93
- - README.md
67
+ extra_rdoc_files: []
94
68
  files:
95
- - ".document"
96
- - ".rspec"
97
- - ".rubocop.yml"
98
- - Gemfile
99
- - Gemfile.lock
100
- - LICENSE.txt
101
69
  - README.md
102
70
  - Rakefile
103
71
  - VERSION
104
72
  - lib/plissken.rb
105
73
  - lib/plissken/ext/hash/to_snake_keys.rb
106
- - plissken.gemspec
107
- - spec/lib/to_snake_keys_spec.rb
108
- - spec/spec_helper.rb
109
- - test/helper.rb
110
- - test/plissken/ext/hash/to_snake_keys_test.rb
111
- - test/test_plissken.rb
112
- homepage: http://github.com/futurechimp/plissken
74
+ - lib/plissken/version.rb
75
+ homepage: https://github.com/futurechimp/plissken
113
76
  licenses:
114
77
  - MIT
115
78
  metadata: {}
@@ -129,7 +92,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
129
92
  version: '0'
130
93
  requirements: []
131
94
  rubyforge_project:
132
- rubygems_version: 2.5.1
95
+ rubygems_version: 2.6.11
133
96
  signing_key:
134
97
  specification_version: 4
135
98
  summary: Snakify your camel keys when working with JSON APIs
data/.document DELETED
@@ -1,5 +0,0 @@
1
- lib/**/*.rb
2
- bin/*
3
- -
4
- features/**/*.feature
5
- LICENSE.txt
data/.rspec DELETED
@@ -1,2 +0,0 @@
1
- --color
2
- --require spec_helper
@@ -1,11 +0,0 @@
1
- Style/HashSyntax:
2
- EnforcedStyle: hash_rockets
3
- SupportedStyles:
4
- - ruby19
5
- - hash_rockets
6
-
7
- AllCops:
8
- Exclude:
9
- - plissken.gemspec
10
- - Rakefile
11
- - test/helper.rb
data/Gemfile DELETED
@@ -1,15 +0,0 @@
1
- source 'http://rubygems.org'
2
- gem 'symbolize', '~> 4.2'
3
- # Add dependencies required to use your gem here.
4
- # Example:
5
- # gem "activesupport", ">= 2.3.5"
6
-
7
- # Add dependencies to develop your gem here.
8
- # Include everything needed to run rake, tests, features, etc.
9
- group :development do
10
- # gem 'debugger'
11
- gem 'rspec', '~> 3.1'
12
- gem 'rdoc', '~> 4.2'
13
- gem 'bundler', '~> 1.6'
14
- gem 'jeweler', '~> 2.3'
15
- end
@@ -1,97 +0,0 @@
1
- GEM
2
- remote: http://rubygems.org/
3
- specs:
4
- activemodel (4.2.7.1)
5
- activesupport (= 4.2.7.1)
6
- builder (~> 3.1)
7
- activesupport (4.2.7.1)
8
- i18n (~> 0.7)
9
- json (~> 1.7, >= 1.7.7)
10
- minitest (~> 5.1)
11
- thread_safe (~> 0.3, >= 0.3.4)
12
- tzinfo (~> 1.1)
13
- addressable (2.5.0)
14
- public_suffix (~> 2.0, >= 2.0.2)
15
- builder (3.2.2)
16
- descendants_tracker (0.0.4)
17
- thread_safe (~> 0.3, >= 0.3.1)
18
- diff-lcs (1.2.5)
19
- faraday (0.9.2)
20
- multipart-post (>= 1.2, < 3)
21
- git (1.3.0)
22
- github_api (0.11.3)
23
- addressable (~> 2.3)
24
- descendants_tracker (~> 0.0.1)
25
- faraday (~> 0.8, < 0.10)
26
- hashie (>= 1.2)
27
- multi_json (>= 1.7.5, < 2.0)
28
- nokogiri (~> 1.6.0)
29
- oauth2
30
- hashie (3.4.6)
31
- highline (1.7.8)
32
- i18n (0.7.0)
33
- jeweler (2.3.2)
34
- builder
35
- bundler (>= 1.0)
36
- git (>= 1.2.5)
37
- github_api (~> 0.11.0)
38
- highline (>= 1.6.15)
39
- nokogiri (>= 1.5.10)
40
- psych (~> 2.2)
41
- rake
42
- rdoc
43
- semver2
44
- json (1.8.6)
45
- jwt (1.5.6)
46
- mini_portile2 (2.1.0)
47
- minitest (5.10.1)
48
- multi_json (1.12.1)
49
- multi_xml (0.6.0)
50
- multipart-post (2.0.0)
51
- nokogiri (1.6.8.1)
52
- mini_portile2 (~> 2.1.0)
53
- oauth2 (1.3.0)
54
- faraday (>= 0.8, < 0.11)
55
- jwt (~> 1.0)
56
- multi_json (~> 1.3)
57
- multi_xml (~> 0.5)
58
- rack (>= 1.2, < 3)
59
- psych (2.2.2)
60
- public_suffix (2.0.5)
61
- rack (2.0.1)
62
- rake (12.0.0)
63
- rdoc (4.3.0)
64
- rspec (3.5.0)
65
- rspec-core (~> 3.5.0)
66
- rspec-expectations (~> 3.5.0)
67
- rspec-mocks (~> 3.5.0)
68
- rspec-core (3.5.4)
69
- rspec-support (~> 3.5.0)
70
- rspec-expectations (3.5.0)
71
- diff-lcs (>= 1.2.0, < 2.0)
72
- rspec-support (~> 3.5.0)
73
- rspec-mocks (3.5.0)
74
- diff-lcs (>= 1.2.0, < 2.0)
75
- rspec-support (~> 3.5.0)
76
- rspec-support (3.5.0)
77
- semver2 (3.4.2)
78
- symbolize (4.5.2)
79
- activemodel (>= 3.2, < 5)
80
- activesupport (>= 3.2, < 5)
81
- i18n
82
- thread_safe (0.3.5)
83
- tzinfo (1.2.2)
84
- thread_safe (~> 0.1)
85
-
86
- PLATFORMS
87
- ruby
88
-
89
- DEPENDENCIES
90
- bundler (~> 1.6)
91
- jeweler (~> 2.3)
92
- rdoc (~> 4.2)
93
- rspec (~> 3.1)
94
- symbolize (~> 4.2)
95
-
96
- BUNDLED WITH
97
- 1.13.6
@@ -1,20 +0,0 @@
1
- Copyright (c) 2013 Dave Hrycyszyn
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.
@@ -1,69 +0,0 @@
1
- # Generated by jeweler
2
- # DO NOT EDIT THIS FILE DIRECTLY
3
- # Instead, edit Jeweler::Tasks in Rakefile, and run 'rake gemspec'
4
- # -*- encoding: utf-8 -*-
5
- # stub: plissken 0.3.0 ruby lib
6
-
7
- Gem::Specification.new do |s|
8
- s.name = "plissken"
9
- s.version = "0.3.0"
10
-
11
- s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
12
- s.require_paths = ["lib"]
13
- s.authors = ["Dave Hrycyszyn", "Michael Chrisco"]
14
- s.date = "2017-01-13"
15
- s.description = "\n Have you ever needed to automatically convert JSON-style camelBack or\n CamelCase hash keys into more Rubyish snake_case?\n\n Plissken to the rescue.\n\n This gem recursively converts all camelBack or CamelCase keys in a hash\n structure to snake_case.\n "
16
- s.email = "dave.hrycyszyn@headlondon.com"
17
- s.extra_rdoc_files = [
18
- "LICENSE.txt",
19
- "README.md"
20
- ]
21
- s.files = [
22
- ".document",
23
- ".rspec",
24
- ".rubocop.yml",
25
- "Gemfile",
26
- "Gemfile.lock",
27
- "LICENSE.txt",
28
- "README.md",
29
- "Rakefile",
30
- "VERSION",
31
- "lib/plissken.rb",
32
- "lib/plissken/ext/hash/to_snake_keys.rb",
33
- "plissken.gemspec",
34
- "spec/lib/to_snake_keys_spec.rb",
35
- "spec/spec_helper.rb",
36
- "test/helper.rb",
37
- "test/plissken/ext/hash/to_snake_keys_test.rb",
38
- "test/test_plissken.rb"
39
- ]
40
- s.homepage = "http://github.com/futurechimp/plissken"
41
- s.licenses = ["MIT"]
42
- s.rubygems_version = "2.5.1"
43
- s.summary = "Snakify your camel keys when working with JSON APIs"
44
-
45
- if s.respond_to? :specification_version then
46
- s.specification_version = 4
47
-
48
- if Gem::Version.new(Gem::VERSION) >= Gem::Version.new('1.2.0') then
49
- s.add_runtime_dependency(%q<symbolize>, ["~> 4.2"])
50
- s.add_development_dependency(%q<rspec>, ["~> 3.1"])
51
- s.add_development_dependency(%q<rdoc>, ["~> 4.2"])
52
- s.add_development_dependency(%q<bundler>, ["~> 1.6"])
53
- s.add_development_dependency(%q<jeweler>, ["~> 2.3"])
54
- else
55
- s.add_dependency(%q<symbolize>, ["~> 4.2"])
56
- s.add_dependency(%q<rspec>, ["~> 3.1"])
57
- s.add_dependency(%q<rdoc>, ["~> 4.2"])
58
- s.add_dependency(%q<bundler>, ["~> 1.6"])
59
- s.add_dependency(%q<jeweler>, ["~> 2.3"])
60
- end
61
- else
62
- s.add_dependency(%q<symbolize>, ["~> 4.2"])
63
- s.add_dependency(%q<rspec>, ["~> 3.1"])
64
- s.add_dependency(%q<rdoc>, ["~> 4.2"])
65
- s.add_dependency(%q<bundler>, ["~> 1.6"])
66
- s.add_dependency(%q<jeweler>, ["~> 2.3"])
67
- end
68
- end
69
-
@@ -1,177 +0,0 @@
1
- require 'spec_helper'
2
-
3
- require File.expand_path(File.dirname(__FILE__) + '/../../lib/plissken')
4
-
5
- RSpec.describe 'A Hash' do
6
- describe 'with camelBack keys' do
7
- describe 'which are JSON-style strings' do
8
- describe 'in the simplest case' do
9
- let(:hash) { [{ 'firstKey' => 'fooBar' }] }
10
-
11
- describe 'non-destructive snakification' do
12
- let(:snaked) { hash.map(&:to_snake_keys) }
13
- it 'snakifies the key' do
14
- expect(snaked.first).to have_key(:first_key)
15
- end
16
-
17
- it 'leaves the key as a string' do
18
- expect(snaked.first.keys).to eq([:first_key])
19
- end
20
-
21
- it 'leaves the value untouched' do
22
- expect(hash.first.values).to eq(['fooBar'])
23
- end
24
-
25
- it 'leaves the original hash untouched' do
26
- expect(hash.first.keys).to eq(['firstKey'])
27
- end
28
- end
29
- end
30
-
31
- describe 'containing an array of other hashes' do
32
- let(:hash) do
33
- {
34
- 'appleType' => 'Granny Smith',
35
- 'vegetableTypes' => [
36
- { 'potatoType' => 'Golden delicious' },
37
- { 'otherTuberType' => 'peanut' },
38
- { 'peanutNamesAndSpouses' => [
39
- { 'billThePeanut' => 'sallyPeanut' },
40
- { 'sammyThePeanut' => 'jillPeanut' }
41
- ] }
42
- ] }
43
- end
44
-
45
- describe 'non-destructive snakification' do
46
- subject(:snaked) { hash.to_snake_keys }
47
- #
48
- it 'recursively snakifies the keys on the top level of the hash' do
49
- expect(snaked.include?(:apple_type)).to be_truthy
50
- expect(snaked.include?(:vegetable_types)).to be_truthy
51
- end
52
-
53
- it 'leaves the values on the top level alone' do
54
- expect(snaked[:apple_type]).to eq('Granny Smith')
55
- end
56
-
57
- it 'converts second-level keys' do
58
- expect(snaked[:vegetable_types].first)
59
- .to have_key(:potato_type)
60
- end
61
-
62
- it 'leaves second-level values alone' do
63
- expect(snaked[:vegetable_types].first)
64
- .to have_value('Golden delicious')
65
- end
66
-
67
- it 'converts third-level keys' do
68
- expect(snaked[:vegetable_types].last[:peanut_names_and_spouses]
69
- .last).to have_value('jillPeanut')
70
- expect(snaked[:vegetable_types]
71
- .last[:peanut_names_and_spouses]
72
- .last).to have_key(:sammy_the_peanut)
73
- end
74
-
75
- it 'leaves third-level values alone' do
76
- expect(snaked[:vegetable_types]
77
- .last[:peanut_names_and_spouses]
78
- .first[:bill_the_peanut]).to eq('sallyPeanut')
79
- expect(snaked[:vegetable_types]
80
- .last[:peanut_names_and_spouses]
81
- .last[:sammy_the_peanut]).to eq('jillPeanut')
82
- end
83
- end
84
- end
85
- end
86
-
87
- describe 'which are symbols' do
88
- describe 'in the simplest case' do
89
- let(:hash) { { :firstKey => 'fooBar' } }
90
-
91
- describe 'non-destructive snakification' do
92
- subject(:snaked) { hash.to_snake_keys }
93
-
94
- it 'snakifies the key' do
95
- expect(snaked).to have_key(:first_key)
96
- end
97
-
98
- it 'leaves the key as a symbol' do
99
- expect(:first_key).to eq(snaked.keys.first)
100
- end
101
-
102
- it 'leaves the value untouched' do
103
- expect(snaked.values.first).to eq('fooBar')
104
- end
105
-
106
- it 'leaves the original hash untouched' do
107
- expect(hash).to have_key(:firstKey)
108
- end
109
- end
110
- end
111
- #
112
- describe 'containing an array of other hashes' do
113
- let(:hash) do
114
- {
115
- :appleType => 'Granny Smith',
116
- :vegetableTypes => [
117
- { :potatoType => 'Golden delicious' },
118
- { :otherTuberType => 'peanut' },
119
- { :peanutNamesAndSpouses => [
120
- { :billThePeanut => 'sallyPeanut' },
121
- { :sammyThePeanut => 'jillPeanut' }
122
- ] }
123
- ] }
124
- end
125
- #
126
- describe 'non-destructive snakification' do
127
- subject(:snaked) { hash.to_snake_keys }
128
- #
129
- it 'recursively snakifies the keys on the top level of the hash' do
130
- expect(snaked.include?(:apple_type)).to be_truthy
131
- expect(snaked.include?(:vegetable_types)).to be_truthy
132
- end
133
-
134
- it 'leaves the values on the top level alone' do
135
- expect(snaked[:apple_type]).to eq('Granny Smith')
136
- end
137
-
138
- it 'converts second-level keys' do
139
- expect(snaked[:vegetable_types].first)
140
- .to have_key(:potato_type)
141
- end
142
-
143
- it 'leaves second-level values alone' do
144
- expect(snaked[:vegetable_types].first)
145
- .to have_value('Golden delicious')
146
- end
147
-
148
- it 'converts third-level keys' do
149
- expect(snaked[:vegetable_types].last[:peanut_names_and_spouses]
150
- .last).to have_value('jillPeanut')
151
- expect(snaked[:vegetable_types]
152
- .last[:peanut_names_and_spouses]
153
- .last).to have_key(:sammy_the_peanut)
154
- end
155
-
156
- it 'leaves third-level values alone' do
157
- expect(snaked[:vegetable_types]
158
- .last[:peanut_names_and_spouses]
159
- .first[:bill_the_peanut]).to eq('sallyPeanut')
160
- expect(snaked[:vegetable_types]
161
- .last[:peanut_names_and_spouses]
162
- .last[:sammy_the_peanut]).to eq('jillPeanut')
163
- end
164
- end
165
- end
166
- end
167
- end
168
-
169
- describe 'strings with spaces in them' do
170
- let(:hash) { { 'With Spaces' => 'FooBar' } }
171
- subject { hash.to_snake_keys }
172
-
173
- it "doesn't get snaked, although it does get downcased" do
174
- is_expected.to have_key(:'with spaces')
175
- end
176
- end
177
- end
@@ -1,90 +0,0 @@
1
- # This file was generated by the `rspec --init` command. Conventionally, all
2
- # specs live under a `spec` directory, which RSpec adds to the `$LOAD_PATH`.
3
- # The generated `.rspec` file contains `--require spec_helper`
4
- # which will cause this file to always be loaded,
5
- # without a need to explicitly require it in any files.
6
- #
7
- # Given that it is always loaded, you are encouraged to keep this file as
8
- # light-weight as possible. Requiring heavyweight dependencies from this file
9
- # will add to the boot time of your test suite on EVERY test run, even for an
10
- # individual file that may not need all of that loaded. Instead, consider making
11
- # a separate helper file that requires the additional dependencies and performs
12
- # the additional setup, and require it from the spec
13
- # files that actually need it.
14
- #
15
- # The `.rspec` file also contains a few flags that are not defaults but that
16
- # users commonly want.
17
- #
18
- # See http://rubydoc.info/gems/rspec-core/RSpec/Core/Configuration
19
- RSpec.configure do |config|
20
- # rspec-expectations config goes here. You can use an alternate
21
- # assertion/expectation library such as wrong or the stdlib/minitest
22
- # assertions if you prefer.
23
- config.expect_with :rspec do |expectations|
24
- # This option will default to `true` in RSpec 4. It makes the `description`
25
- # and `failure_message` of custom matchers include text for helper methods
26
- # defined using `chain`, e.g.:
27
- # be_bigger_than(2).and_smaller_than(4).description
28
- # # => "be bigger than 2 and smaller than 4"
29
- # ...rather than:
30
- # # => "be bigger than 2"
31
- expectations.include_chain_clauses_in_custom_matcher_descriptions = true
32
- end
33
-
34
- # rspec-mocks config goes here. You can use an alternate test double
35
- # library (such as bogus or mocha) by changing the `mock_with` option here.
36
- config.mock_with :rspec do |mocks|
37
- # Prevents you from mocking or stubbing a method that does not exist on
38
- # a real object. This is generally recommended, and will default to
39
- # `true` in RSpec 4.
40
- mocks.verify_partial_doubles = true
41
- end
42
-
43
- # The settings below are suggested to provide a good initial experience
44
- # with RSpec, but feel free to customize to your heart's content.
45
- # # These two settings work together to allow you to limit a spec run
46
- # # to individual examples or groups you care about by tagging them with
47
- # # `:focus` metadata. When nothing is tagged with `:focus`, all examples
48
- # # get run.
49
- # config.filter_run :focus
50
- # config.run_all_when_everything_filtered = true
51
- #
52
- # # Limits the available syntax to the non-monkey
53
- # patched syntax that is recommended.
54
- # # For more details, see:
55
- #
56
- # config.disable_monkey_patching!
57
- #
58
- # # This setting enables warnings. It's recommended, but in some cases may
59
- # # be too noisy due to issues in dependencies.
60
- # config.warnings = true
61
- #
62
- # # Many RSpec users commonly either run the entire suite or an individual
63
- # # file, and it's useful to allow more verbose output when running an
64
- # # individual spec file.
65
- # if config.files_to_run.one?
66
- # # Use the documentation formatter for detailed output,
67
- # # unless a formatter has already been configured
68
- # # (e.g. via a command-line flag).
69
- # config.default_formatter = 'doc'
70
- # end
71
- #
72
- # # Print the 10 slowest examples and example groups at the
73
- # # end of the spec run, to help surface which specs are running
74
- # # particularly slow.
75
- # config.profile_examples = 10
76
- #
77
- # # Run specs in random order to surface order dependencies. If you find an
78
- # # order dependency and want to debug it,
79
- # you can fix the order by providing
80
- # # the seed, which is printed after each run.
81
- # # --seed 1234
82
- # config.order = :random
83
- #
84
- # # Seed global randomization in this process using the `--seed` CLI option.
85
- # # Setting this allows you to use `--seed` to deterministically reproduce
86
- # # test failures related to randomization by
87
- # # passing the same `--seed` value
88
- # # as the one that triggered the failure.
89
- # Kernel.srand config.seed
90
- end
@@ -1,20 +0,0 @@
1
- require 'rubygems'
2
- require 'bundler'
3
- begin
4
- Bundler.setup(:default, :development)
5
- rescue Bundler::BundlerError => e
6
- $stderr.puts e.message
7
- $stderr.puts 'Run `bundle install` to install missing gems'
8
- exit e.status_code
9
- end
10
- require 'minitest/spec'
11
- # require 'debugger'
12
-
13
- $LOAD_PATH.unshift(File.dirname(__FILE__))
14
- $LOAD_PATH.unshift(File.join(File.dirname(__FILE__), '..', 'lib'))
15
- require 'plissken'
16
-
17
- class MiniTest::Unit::TestCase
18
- end
19
-
20
- MiniTest::Unit.autorun
@@ -1,184 +0,0 @@
1
- require File.expand_path(File.dirname(__FILE__) + '/../../../test_plissken.rb')
2
-
3
- describe 'A Hash' do
4
- describe 'with camelBack keys' do
5
- describe 'which are JSON-style strings' do
6
- describe 'in the simplest case' do
7
- before do
8
- @hash = { 'firstKey' => 'fooBar' }
9
- end
10
-
11
- describe 'non-destructive snakification' do
12
- before do
13
- @snaked = @hash.to_snake_keys
14
- end
15
-
16
- it 'snakifies the key' do
17
- assert_equal(@snaked.keys.first, 'first_key')
18
- end
19
-
20
- it 'leaves the key as a string' do
21
- assert_equal('first_key', @snaked.keys.first)
22
- end
23
-
24
- it 'leaves the value untouched' do
25
- assert_equal(@snaked.values.first, 'fooBar')
26
- end
27
-
28
- it 'leaves the original hash untouched' do
29
- assert_equal(@hash.keys.first, 'firstKey')
30
- end
31
- end
32
- end
33
-
34
- describe 'containing an array of other hashes' do
35
- before do
36
- @hash = {
37
- 'appleType' => 'Granny Smith',
38
- 'vegetableTypes' => [
39
- { 'potatoType' => 'Golden delicious' },
40
- { 'otherTuberType' => 'peanut' },
41
- { 'peanutNamesAndSpouses' => [
42
- { 'billThePeanut' => 'sallyPeanut' },
43
- { 'sammyThePeanut' => 'jillPeanut' }
44
- ] }
45
- ] }
46
- end
47
-
48
- describe 'non-destructive snakification' do
49
- before do
50
- @snaked = @hash.to_snake_keys
51
- end
52
-
53
- it 'recursively snakifies the keys on the top level of the hash' do
54
- assert @snaked.keys.include?('apple_type')
55
- assert @snaked.keys.include?('vegetable_types')
56
- end
57
-
58
- it 'leaves the values on the top level alone' do
59
- assert_equal(@snaked['apple_type'], 'Granny Smith')
60
- end
61
-
62
- it 'converts second-level keys' do
63
- assert @snaked['vegetable_types'].first.key? 'potato_type'
64
- end
65
-
66
- it 'leaves second-level values alone' do
67
- assert @snaked['vegetable_types'].first.value? 'Golden delicious'
68
- end
69
-
70
- it 'converts third-level keys' do
71
- assert @snaked['vegetable_types'].last['peanut_names_and_spouses']
72
- .first.key?('bill_the_peanut')
73
- assert @snaked['vegetable_types'].last['peanut_names_and_spouses']
74
- .last.key?('sammy_the_peanut')
75
- end
76
-
77
- it 'leaves third-level values alone' do
78
- assert_equal 'sallyPeanut', @snaked['vegetable_types']
79
- .last['peanut_names_and_spouses']
80
- .first['bill_the_peanut']
81
- assert_equal 'jillPeanut', @snaked['vegetable_types']
82
- .last['peanut_names_and_spouses']
83
- .last['sammy_the_peanut']
84
- end
85
- end
86
- end
87
- end
88
-
89
- describe 'which are symbols' do
90
- describe 'in the simplest case' do
91
- before do
92
- @hash = { :firstKey => 'fooBar' }
93
- end
94
-
95
- describe 'non-destructive snakification' do
96
- before do
97
- @snaked = @hash.to_snake_keys
98
- end
99
-
100
- it 'snakifies the key' do
101
- assert_equal(@snaked.keys.first, :first_key)
102
- end
103
-
104
- it 'leaves the key as a symbol' do
105
- assert_equal(:first_key, @snaked.keys.first)
106
- end
107
-
108
- it 'leaves the value untouched' do
109
- assert_equal(@snaked.values.first, 'fooBar')
110
- end
111
-
112
- it 'leaves the original hash untouched' do
113
- assert_equal(@hash.keys.first, :firstKey)
114
- end
115
- end
116
- end
117
-
118
- describe 'containing an array of other hashes' do
119
- before do
120
- @hash = {
121
- :appleType => 'Granny Smith',
122
- :vegetableTypes => [
123
- { :potatoType => 'Golden delicious' },
124
- { :otherTuberType => 'peanut' },
125
- { :peanutNamesAndSpouses => [
126
- { :billThePeanut => 'sallyPeanut' },
127
- { :sammyThePeanut => 'jillPeanut' }
128
- ] }
129
- ] }
130
- end
131
-
132
- describe 'non-destructive snakification' do
133
- before do
134
- @snaked = @hash.to_snake_keys
135
- end
136
-
137
- it 'recursively snakifies the keys on the top level of the hash' do
138
- assert @snaked.keys.include?(:apple_type)
139
- assert @snaked.keys.include?(:vegetable_types)
140
- end
141
-
142
- it 'leaves the values on the top level alone' do
143
- assert_equal(@snaked[:apple_type], 'Granny Smith')
144
- end
145
-
146
- it 'converts second-level keys' do
147
- assert @snaked[:vegetable_types].first.key? :potato_type
148
- end
149
-
150
- it 'leaves second-level values alone' do
151
- assert @snaked[:vegetable_types].first.value? 'Golden delicious'
152
- end
153
-
154
- it 'converts third-level keys' do
155
- assert @snaked[:vegetable_types].last[:peanut_names_and_spouses]
156
- .first.key?(:bill_the_peanut)
157
- assert @snaked[:vegetable_types].last[:peanut_names_and_spouses]
158
- .last.key?(:sammy_the_peanut)
159
- end
160
-
161
- it 'leaves third-level values alone' do
162
- assert_equal 'sallyPeanut', @snaked[:vegetable_types]
163
- .last[:peanut_names_and_spouses]
164
- .first[:bill_the_peanut]
165
- assert_equal 'jillPeanut', @snaked[:vegetable_types]
166
- .last[:peanut_names_and_spouses]
167
- .last[:sammy_the_peanut]
168
- end
169
- end
170
- end
171
- end
172
- end
173
-
174
- describe 'strings with spaces in them' do
175
- before do
176
- @hash = { 'With Spaces' => 'FooBar' }
177
- @snaked = @hash.to_snake_keys
178
- end
179
-
180
- it "doesn't get snaked, although it does get downcased" do
181
- assert @snaked.keys.include? 'with spaces'
182
- end
183
- end
184
- end
@@ -1,2 +0,0 @@
1
- require 'helper'
2
- require File.dirname(__FILE__) + '/../lib/plissken/ext/hash/to_snake_keys'