awrence 0.2.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: 77933d65a1db2326a28049db210871984c203835
4
- data.tar.gz: 232d33b6c13d4bc467d7992e58230698b474838f
3
+ metadata.gz: cbb0ff5ac0e9a4c22394ae4a2ca492701538fbf0
4
+ data.tar.gz: bea61bb8c897f5ffd5a9c4946c932d6d5951bd28
5
5
  SHA512:
6
- metadata.gz: e8fb9b9ab4549fdc8ac59781659b42c37d831b7266b903b0535af394e01de9626552a534b8e06d8ecccbd212d61bb5fb45fcfe2d5f10e5f477ab420ce938f7ea
7
- data.tar.gz: 7c8a1b90010da1feb2abfcdfbf0fd1115c5ff147f5e83cda3ca268814e1b0a30758b564e956a6756e7deac5cea28ecc3688c5ae6fad8bbc51578ad7116282c8e
6
+ metadata.gz: fe6a8e89fc9ae1881fb3e06cff4107d8fd61b2484bf3a0724880f55795ca70e233fd4530775aab5490cb3a4f7432837d30ed623b4f954c44c267cb19a957bae1
7
+ data.tar.gz: 7479507a51b038c95a37780aa66f7b542c1198809ccf92ea95bfa00af8d627b5ae530502389946c4a1eead794a0027f95b7c93a0192eb979a769a9c1de74c076
data/README.md CHANGED
@@ -1,6 +1,6 @@
1
- =======
2
- awrence
3
- ========
1
+ # Awrence
2
+
3
+ [![Gem Version](https://badge.fury.io/rb/awrence.svg)](https://badge.fury.io/rb/awrence)
4
4
 
5
5
  Have you ever needed to automatically convert Rubyish `snake_case` to JSON-style `camelBack` or `CamelCase` hash keys?
6
6
 
@@ -8,6 +8,20 @@ Awrence to the rescue.
8
8
 
9
9
  This gem recursively converts all snake_case keys in a hash structure to camelBack or CamelCase.
10
10
 
11
+ ## Installation
12
+
13
+ Add this to your Gemfile:
14
+
15
+ ```ruby
16
+ gem "awrence"
17
+ ```
18
+
19
+ Or install it yourself as:
20
+
21
+ ```bash
22
+ gem install awrence
23
+ ```
24
+
11
25
  ## Usage
12
26
 
13
27
  ```ruby
@@ -23,6 +37,34 @@ camel_hash = my_hash.to_camelback_keys
23
37
 
24
38
  Awrence works on either string keys or symbolized keys. It has no dependencies, as it has its own `camelize` method lifted out of ActiveSupport.
25
39
 
40
+ ### Acronyms
41
+
42
+ You can set acronyms that Awrence will now check against when converting the keys.
43
+
44
+ ```ruby
45
+ Awrence.acronyms = { "url" => "URL", "id" => "ID" }
46
+
47
+ my_hash = { "user_url" => "http://a.com", "user_id" => 2 }
48
+ camel_hash = my_hash.to_camel_keys
49
+ # => { "UserURL" => "http://a.com", "UserID" => 2 }
50
+
51
+ camel_hash = my_hash.to_camelback_keys
52
+ # => { "userURL" => "http://a.com", "userID" => 2 }
53
+ ```
54
+
55
+ The acronym will be ignored when it's the first word and `to_camelback_keys` is called.
56
+
57
+ ```ruby
58
+ Awrence.acronyms = { "id" => "ID" }
59
+
60
+ my_hash = { "id" => 2 }
61
+ camel_hash = my_hash.to_camel_keys
62
+ # => { "ID" => 2 }
63
+
64
+ camel_hash = my_hash.to_camelback_keys
65
+ # => { "id" => 2 }
66
+ ```
67
+
26
68
  ## Limitations
27
69
 
28
70
  * Unlike the original [T.E. Lawrence](http://en.wikipedia.org/wiki/T._E._Lawrence), the awrence gem is non-destructive to Hashes, Turks, or the nascent political aspirations of oppressed peoples. There is no `Hash#to_camel_keys!` form.
@@ -44,6 +86,5 @@ the [Plissken](http://github.com/futurechimp/plissken) gem.
44
86
 
45
87
  == Copyright
46
88
 
47
- Copyright (c) 2013 Dave Hrycyszyn. See LICENSE.txt for
89
+ Copyright (c) 2017 Dave Hrycyszyn. See LICENSE.txt for
48
90
  further details.
49
-
data/Rakefile CHANGED
@@ -1,44 +1,28 @@
1
- # encoding: utf-8
2
-
3
- require 'rubygems'
4
- require 'bundler'
5
1
  begin
6
- Bundler.setup(:default, :development)
7
- rescue Bundler::BundlerError => e
8
- $stderr.puts e.message
9
- $stderr.puts "Run `bundle install` to install missing gems"
10
- 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"
11
5
  end
12
- require 'rake'
13
-
14
- require 'jeweler'
15
- Jeweler::Tasks.new do |gem|
16
- # gem is a Gem::Specification... see http://docs.rubygems.org/read/chapter/20 for more options
17
- gem.name = "awrence"
18
- gem.homepage = "http://github.com/futurechimp/awrence"
19
- gem.license = "MIT"
20
- gem.summary = %Q{Camelize your snake keys when working with JSON APIs}
21
- gem.description = %Q{Have you ever needed to automatically convert Ruby-style
22
- snake_case to CamelCase or camelBack hash keys?
23
6
 
24
- Awrence to the rescue.
7
+ require "rdoc/task"
25
8
 
26
- This gem recursively converts all snake_case keys in a hash
27
- structure to camelBack. }
28
- gem.email = "dave.hrycyszyn@headlondon.com"
29
- gem.authors = ["Dave Hrycyszyn"]
30
- # dependencies defined in Gemfile
9
+ RDoc::Task.new(:rdoc) do |rdoc|
10
+ rdoc.rdoc_dir = "rdoc"
11
+ rdoc.title = "Awrence"
12
+ rdoc.options << "--line-numbers"
13
+ rdoc.rdoc_files.include("README.md")
14
+ rdoc.rdoc_files.include("lib/**/*.rb")
31
15
  end
32
- Jeweler::RubygemsDotOrgTasks.new
33
16
 
34
- require 'rake/testtask'
35
- Rake::TestTask.new(:test) do |test|
36
- test.libs << 'lib' << 'test'
37
- test.pattern = 'test/**/test_*.rb'
38
- test.verbose = true
39
- end
17
+ require "bundler/gem_tasks"
40
18
 
41
- task :default => :test
19
+ require "rake/testtask"
20
+
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
26
+ end
42
27
 
43
- require 'yard'
44
- YARD::Rake::YardocTask.new
28
+ task default: :test
data/VERSION CHANGED
@@ -1 +1 @@
1
- 0.2.0
1
+ 1.0.0
@@ -1 +1,14 @@
1
- require File.dirname(__FILE__) + '/awrence/ext/hash/to_camel_keys'
1
+ require "awrence/methods"
2
+ require "awrence/ext/array/to_camel_keys"
3
+ require "awrence/ext/hash/to_camel_keys"
4
+
5
+ module Awrence
6
+ class << self
7
+
8
+ attr_writer :acronyms
9
+
10
+ def acronyms
11
+ @acronyms ||= {}
12
+ end
13
+ end
14
+ end
@@ -0,0 +1,5 @@
1
+ class Array
2
+
3
+ include Awrence::Methods
4
+
5
+ end
@@ -1,51 +1,5 @@
1
1
  class Hash
2
2
 
3
- # Recursively converts Rubyish snake_case hash keys to camelBack JSON-style
4
- # hash keys suitable for use with a JSON API.
5
- #
6
- def to_camelback_keys(value = self)
7
- case value
8
- when Array
9
- value.map { |v| to_camelback_keys(v) }
10
- when Hash
11
- Hash[value.map { |k, v| [camelize_key(k, false), to_camelback_keys(v)] }]
12
- else
13
- value
14
- end
15
- end
3
+ include Awrence::Methods
16
4
 
17
- # Recursively converts Rubyish snake_case hash keys to CamelCase JSON-style
18
- # hash keys suitable for use with a JSON API.
19
- #
20
- def to_camel_keys(value = self)
21
- case value
22
- when Array
23
- value.map { |v| to_camel_keys(v) }
24
- when Hash
25
- Hash[value.map { |k, v| [camelize_key(k), to_camel_keys(v)] }]
26
- else
27
- value
28
- end
29
- end
30
-
31
- private
32
-
33
- def camelize_key(k, first_upper = true)
34
- if k.is_a? Symbol
35
- camelize(k.to_s, first_upper).to_sym
36
- elsif k.is_a? String
37
- camelize(k, first_upper)
38
- else
39
- k # Awrence can't camelize anything except strings and symbols
40
- end
41
- end
42
-
43
- def camelize(snake_word, first_upper = true)
44
- if first_upper
45
- snake_word.to_s.gsub(/\/(.?)/) { "::" + $1.upcase }.gsub(/(^|_)(.)/) { $2.upcase }
46
- else
47
- snake_word.chars.first + camelize(snake_word)[1..-1]
48
- end
49
- end
50
-
51
- end
5
+ end
@@ -0,0 +1,59 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Awrence
4
+ module Methods
5
+
6
+ # Recursively converts Rubyish snake_case hash keys to camelBack JSON-style
7
+ # hash keys suitable for use with a JSON API.
8
+ #
9
+ def to_camelback_keys(value = self)
10
+ case value
11
+ when Array
12
+ value.map { |v| to_camelback_keys(v) }
13
+ when Hash
14
+ Hash[value.map { |k, v| [camelize_key(k, false), to_camelback_keys(v)] }]
15
+ else
16
+ value
17
+ end
18
+ end
19
+
20
+ # Recursively converts Rubyish snake_case hash keys to CamelCase JSON-style
21
+ # hash keys suitable for use with a JSON API.
22
+ #
23
+ def to_camel_keys(value = self)
24
+ case value
25
+ when Array
26
+ value.map { |v| to_camel_keys(v) }
27
+ when Hash
28
+ Hash[value.map { |k, v| [camelize_key(k), to_camel_keys(v)] }]
29
+ else
30
+ value
31
+ end
32
+ end
33
+
34
+ private
35
+
36
+ def camelize_key(k, first_upper = true)
37
+ if k.is_a? Symbol
38
+ camelize(k.to_s, first_upper).to_sym
39
+ elsif k.is_a? String
40
+ camelize(k, first_upper)
41
+ else
42
+ k # Awrence can't camelize anything except strings and symbols
43
+ end
44
+ end
45
+
46
+ def camelize(snake_word, first_upper = true)
47
+ if first_upper
48
+ snake_word.to_s
49
+ .gsub(/(?:^|_)([^_\s]+)/) { Awrence.acronyms[$1] || $1.capitalize }
50
+ .gsub(%r|/([^/]*)|) { "::" + (Awrence.acronyms[$1] || $1.capitalize) }
51
+ else
52
+ parts = snake_word.split("_", 2)
53
+ parts[0] << camelize(parts[1]) if parts.size > 1
54
+ parts[0] || ""
55
+ end
56
+ end
57
+
58
+ end
59
+ end
@@ -0,0 +1,3 @@
1
+ module Awrence
2
+ VERSION = File.read("VERSION").split("\n").first
3
+ end
metadata CHANGED
@@ -1,110 +1,79 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: awrence
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.2.0
4
+ version: 1.0.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Dave Hrycyszyn
8
+ - Stuart Chinery
8
9
  autorequire:
9
10
  bindir: bin
10
11
  cert_chain: []
11
- date: 2017-01-13 00:00:00.000000000 Z
12
+ date: 2017-07-19 00:00:00.000000000 Z
12
13
  dependencies:
13
14
  - !ruby/object:Gem::Dependency
14
15
  name: minitest
15
- requirement: !ruby/object:Gem::Requirement
16
- requirements:
17
- - - ">="
18
- - !ruby/object:Gem::Version
19
- version: '0'
20
- type: :development
21
- prerelease: false
22
- version_requirements: !ruby/object:Gem::Requirement
23
- requirements:
24
- - - ">="
25
- - !ruby/object:Gem::Version
26
- version: '0'
27
- - !ruby/object:Gem::Dependency
28
- name: yard
29
16
  requirement: !ruby/object:Gem::Requirement
30
17
  requirements:
31
18
  - - "~>"
32
19
  - !ruby/object:Gem::Version
33
- version: '0.7'
20
+ version: '4.7'
34
21
  type: :development
35
22
  prerelease: false
36
23
  version_requirements: !ruby/object:Gem::Requirement
37
24
  requirements:
38
25
  - - "~>"
39
26
  - !ruby/object:Gem::Version
40
- version: '0.7'
27
+ version: '4.7'
41
28
  - !ruby/object:Gem::Dependency
42
- name: rdoc
29
+ name: minitest-reporters
43
30
  requirement: !ruby/object:Gem::Requirement
44
31
  requirements:
45
32
  - - "~>"
46
33
  - !ruby/object:Gem::Version
47
- version: '4.2'
34
+ version: '0.14'
48
35
  type: :development
49
36
  prerelease: false
50
37
  version_requirements: !ruby/object:Gem::Requirement
51
38
  requirements:
52
39
  - - "~>"
53
40
  - !ruby/object:Gem::Version
54
- version: '4.2'
41
+ version: '0.14'
55
42
  - !ruby/object:Gem::Dependency
56
- name: bundler
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: jeweler
43
+ name: rake
71
44
  requirement: !ruby/object:Gem::Requirement
72
45
  requirements:
73
46
  - - "~>"
74
47
  - !ruby/object:Gem::Version
75
- version: '2.3'
48
+ version: '12.0'
76
49
  type: :development
77
50
  prerelease: false
78
51
  version_requirements: !ruby/object:Gem::Requirement
79
52
  requirements:
80
53
  - - "~>"
81
54
  - !ruby/object:Gem::Version
82
- version: '2.3'
83
- description: "Have you ever needed to automatically convert Ruby-style\n snake_case
84
- to CamelCase or camelBack hash keys?\n\n Awrence to the rescue.\n\n This gem
85
- recursively converts all snake_case keys in a hash\n structure to camelBack.
86
- \ "
87
- email: dave.hrycyszyn@headlondon.com
55
+ version: '12.0'
56
+ description: |-
57
+ Have you ever needed to automatically convert Ruby-style snake_case to CamelCase or camelBack hash keys?
58
+
59
+ Awrence to the rescue.
60
+
61
+ This gem recursively converts all snake_case keys in a hash structure to camelBack.
62
+ email:
63
+ - dhrycyszyn@zonedigital.com
88
64
  executables: []
89
65
  extensions: []
90
- extra_rdoc_files:
91
- - LICENSE.txt
92
- - README.md
66
+ extra_rdoc_files: []
93
67
  files:
94
- - ".document"
95
- - Gemfile
96
- - Gemfile.lock
97
- - LICENSE.txt
98
68
  - README.md
99
69
  - Rakefile
100
70
  - VERSION
101
- - awrence.gemspec
102
71
  - lib/awrence.rb
72
+ - lib/awrence/ext/array/to_camel_keys.rb
103
73
  - lib/awrence/ext/hash/to_camel_keys.rb
104
- - test/awrence/ext/hash/to_camel_keys_test.rb
105
- - test/helper.rb
106
- - test/test_awrence.rb
107
- homepage: http://github.com/futurechimp/awrence
74
+ - lib/awrence/methods.rb
75
+ - lib/awrence/version.rb
76
+ homepage: https://github.com/futurechimp/awrence
108
77
  licenses:
109
78
  - MIT
110
79
  metadata: {}
@@ -124,7 +93,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
124
93
  version: '0'
125
94
  requirements: []
126
95
  rubyforge_project:
127
- rubygems_version: 2.5.1
96
+ rubygems_version: 2.6.11
128
97
  signing_key:
129
98
  specification_version: 4
130
99
  summary: Camelize your snake 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/Gemfile DELETED
@@ -1,14 +0,0 @@
1
- source "https://rubygems.org"
2
- # Add dependencies required to use your gem here.
3
- # Example:
4
- # gem "activesupport", ">= 2.3.5"
5
-
6
- # Add dependencies to develop your gem here.
7
- # Include everything needed to run rake, tests, features, etc.
8
- group :development do
9
- gem "minitest", ">= 0"
10
- gem "yard", "~> 0.7"
11
- gem 'rdoc', '~> 4.2'
12
- gem "bundler"
13
- gem 'jeweler', '~> 2.3'
14
- end
@@ -1,67 +0,0 @@
1
- GEM
2
- remote: https://rubygems.org/
3
- specs:
4
- addressable (2.5.0)
5
- public_suffix (~> 2.0, >= 2.0.2)
6
- builder (3.2.2)
7
- descendants_tracker (0.0.4)
8
- thread_safe (~> 0.3, >= 0.3.1)
9
- faraday (0.9.2)
10
- multipart-post (>= 1.2, < 3)
11
- git (1.3.0)
12
- github_api (0.11.3)
13
- addressable (~> 2.3)
14
- descendants_tracker (~> 0.0.1)
15
- faraday (~> 0.8, < 0.10)
16
- hashie (>= 1.2)
17
- multi_json (>= 1.7.5, < 2.0)
18
- nokogiri (~> 1.6.0)
19
- oauth2
20
- hashie (3.4.6)
21
- highline (1.7.8)
22
- jeweler (2.3.2)
23
- builder
24
- bundler (>= 1.0)
25
- git (>= 1.2.5)
26
- github_api (~> 0.11.0)
27
- highline (>= 1.6.15)
28
- nokogiri (>= 1.5.10)
29
- psych (~> 2.2)
30
- rake
31
- rdoc
32
- semver2
33
- jwt (1.5.6)
34
- mini_portile2 (2.1.0)
35
- minitest (4.7.0)
36
- multi_json (1.12.1)
37
- multi_xml (0.6.0)
38
- multipart-post (2.0.0)
39
- nokogiri (1.6.8.1)
40
- mini_portile2 (~> 2.1.0)
41
- oauth2 (1.3.0)
42
- faraday (>= 0.8, < 0.11)
43
- jwt (~> 1.0)
44
- multi_json (~> 1.3)
45
- multi_xml (~> 0.5)
46
- rack (>= 1.2, < 3)
47
- psych (2.2.2)
48
- public_suffix (2.0.5)
49
- rack (2.0.1)
50
- rake (12.0.0)
51
- rdoc (4.3.0)
52
- semver2 (3.4.2)
53
- thread_safe (0.3.5)
54
- yard (0.8.5.2)
55
-
56
- PLATFORMS
57
- ruby
58
-
59
- DEPENDENCIES
60
- bundler
61
- jeweler (~> 2.3)
62
- minitest
63
- rdoc (~> 4.2)
64
- yard (~> 0.7)
65
-
66
- BUNDLED WITH
67
- 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,65 +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: awrence 0.2.0 ruby lib
6
-
7
- Gem::Specification.new do |s|
8
- s.name = "awrence"
9
- s.version = "0.2.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"]
14
- s.date = "2017-01-13"
15
- s.description = "Have you ever needed to automatically convert Ruby-style\n snake_case to CamelCase or camelBack hash keys?\n\n Awrence to the rescue.\n\n This gem recursively converts all snake_case keys in a hash\n structure to camelBack. "
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
- "Gemfile",
24
- "Gemfile.lock",
25
- "LICENSE.txt",
26
- "README.md",
27
- "Rakefile",
28
- "VERSION",
29
- "awrence.gemspec",
30
- "lib/awrence.rb",
31
- "lib/awrence/ext/hash/to_camel_keys.rb",
32
- "test/awrence/ext/hash/to_camel_keys_test.rb",
33
- "test/helper.rb",
34
- "test/test_awrence.rb"
35
- ]
36
- s.homepage = "http://github.com/futurechimp/awrence"
37
- s.licenses = ["MIT"]
38
- s.rubygems_version = "2.5.1"
39
- s.summary = "Camelize your snake keys when working with JSON APIs"
40
-
41
- if s.respond_to? :specification_version then
42
- s.specification_version = 4
43
-
44
- if Gem::Version.new(Gem::VERSION) >= Gem::Version.new('1.2.0') then
45
- s.add_development_dependency(%q<minitest>, [">= 0"])
46
- s.add_development_dependency(%q<yard>, ["~> 0.7"])
47
- s.add_development_dependency(%q<rdoc>, ["~> 4.2"])
48
- s.add_development_dependency(%q<bundler>, [">= 0"])
49
- s.add_development_dependency(%q<jeweler>, ["~> 2.3"])
50
- else
51
- s.add_dependency(%q<minitest>, [">= 0"])
52
- s.add_dependency(%q<yard>, ["~> 0.7"])
53
- s.add_dependency(%q<rdoc>, ["~> 4.2"])
54
- s.add_dependency(%q<bundler>, [">= 0"])
55
- s.add_dependency(%q<jeweler>, ["~> 2.3"])
56
- end
57
- else
58
- s.add_dependency(%q<minitest>, [">= 0"])
59
- s.add_dependency(%q<yard>, ["~> 0.7"])
60
- s.add_dependency(%q<rdoc>, ["~> 4.2"])
61
- s.add_dependency(%q<bundler>, [">= 0"])
62
- s.add_dependency(%q<jeweler>, ["~> 2.3"])
63
- end
64
- end
65
-
@@ -1,157 +0,0 @@
1
- require File.expand_path(File.dirname(__FILE__) + '/../../../test_awrence.rb')
2
-
3
- describe "A Hash" do
4
- describe "with snake keys" do
5
- describe "which are JSON-style strings" do
6
- describe "in the simplest case" do
7
- before do
8
- @hash = { "first_key" => "fooBar" }
9
- end
10
-
11
- describe "non-destructive conversion to CamelCase" do
12
- before do
13
- @camelized = @hash.to_camel_keys
14
- end
15
-
16
- it "camelizes the key" do
17
- assert_equal("FirstKey", @camelized.keys.first)
18
- end
19
-
20
- it "leaves the key as a string" do
21
- assert @camelized.keys.first.is_a? String
22
- end
23
-
24
- it "leaves the value untouched" do
25
- assert_equal(@camelized.values.first, "fooBar")
26
- end
27
-
28
- it "leaves the original hash untouched" do
29
- assert_equal(@hash.keys.first, "first_key")
30
- end
31
- end
32
-
33
- describe "non-destructive conversion to camelBack" do
34
- before do
35
- @camelized = @hash.to_camelback_keys
36
- end
37
-
38
- it "camelizes the key" do
39
- assert_equal("firstKey", @camelized.keys.first)
40
- end
41
-
42
- it "leaves the key as a string" do
43
- assert @camelized.keys.first.is_a? String
44
- end
45
-
46
- it "leaves the value untouched" do
47
- assert_equal(@camelized.values.first, "fooBar")
48
- end
49
-
50
- it "leaves the original hash untouched" do
51
- assert_equal(@hash.keys.first, "first_key")
52
- end
53
- end
54
- end
55
-
56
- describe "containing an array of other hashes" do
57
- before do
58
- @hash = {
59
- "apple_type" => "Granny Smith",
60
- "vegetable_types" => [
61
- {"potato_type" => "Golden delicious"},
62
- {"other_tuber_type" => "peanut"},
63
- {"peanut_names_and_spouses" => [
64
- {"bill_the_peanut" => "sally_peanut"}, {"sammy_the_peanut" => "jill_peanut"}
65
- ]}
66
- ]}
67
- end
68
-
69
- describe "non-destructive conversion to CamelCase" do
70
- before do
71
- @camelized = @hash.to_camel_keys
72
- end
73
-
74
- it "recursively camelizes the keys on the top level of the hash" do
75
- assert @camelized.keys.include?("AppleType")
76
- assert @camelized.keys.include?("VegetableTypes")
77
- end
78
-
79
- it "leaves the values on the top level alone" do
80
- assert_equal(@camelized["AppleType"], "Granny Smith")
81
- end
82
-
83
- it "converts second-level keys" do
84
- assert @camelized["VegetableTypes"].first.has_key? "PotatoType"
85
- end
86
-
87
- it "leaves second-level values alone" do
88
- assert @camelized["VegetableTypes"].first.has_value? "Golden delicious"
89
- end
90
-
91
- it "converts third-level keys" do
92
- assert @camelized["VegetableTypes"].last["PeanutNamesAndSpouses"].first.has_key?("BillThePeanut")
93
- assert @camelized["VegetableTypes"].last["PeanutNamesAndSpouses"].last.has_key?("SammyThePeanut")
94
- end
95
-
96
- it "leaves third-level values alone" do
97
- assert_equal "sally_peanut", @camelized["VegetableTypes"].last["PeanutNamesAndSpouses"].first["BillThePeanut"]
98
- assert_equal "jill_peanut", @camelized["VegetableTypes"].last["PeanutNamesAndSpouses"].last["SammyThePeanut"]
99
- end
100
- end
101
-
102
- describe "non-destructive conversion to camelBack" do
103
- before do
104
- @camelized = @hash.to_camelback_keys
105
- end
106
-
107
- it "recursively camelizes the keys on the top level of the hash" do
108
- assert @camelized.keys.include?("appleType")
109
- assert @camelized.keys.include?("vegetableTypes")
110
- end
111
-
112
- it "leaves the values on the top level alone" do
113
- assert_equal(@camelized["appleType"], "Granny Smith")
114
- end
115
-
116
- it "converts second-level keys" do
117
- assert @camelized["vegetableTypes"].first.has_key? "potatoType"
118
- end
119
-
120
- it "leaves second-level values alone" do
121
- assert @camelized["vegetableTypes"].first.has_value? "Golden delicious"
122
- end
123
-
124
- it "converts third-level keys" do
125
- assert @camelized["vegetableTypes"].last["peanutNamesAndSpouses"].first.has_key?("billThePeanut")
126
- assert @camelized["vegetableTypes"].last["peanutNamesAndSpouses"].last.has_key?("sammyThePeanut")
127
- end
128
-
129
- it "leaves third-level values alone" do
130
- assert_equal "sally_peanut", @camelized["vegetableTypes"].last["peanutNamesAndSpouses"].first["billThePeanut"]
131
- assert_equal "jill_peanut", @camelized["vegetableTypes"].last["peanutNamesAndSpouses"].last["sammyThePeanut"]
132
- end
133
- end
134
- end
135
- end
136
- end
137
-
138
- describe "strings with spaces in them" do
139
- before do
140
- @hash = { "With Spaces" => "FooBar"}
141
- end
142
-
143
- describe "to_camel_keys" do
144
- it "doesn't get camelized" do
145
- @camelized = @hash.to_camel_keys
146
- assert_equal "With Spaces", @camelized.keys.first
147
- end
148
- end
149
-
150
- describe "to_camelback_keys" do
151
- it "doesn't get camelized" do
152
- @camelized = @hash.to_camelback_keys
153
- assert_equal "With Spaces", @camelized.keys.first
154
- end
155
- end
156
- end
157
- end
@@ -1,19 +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
-
12
- $LOAD_PATH.unshift(File.dirname(__FILE__))
13
- $LOAD_PATH.unshift(File.join(File.dirname(__FILE__), '..', 'lib'))
14
- require 'awrence'
15
-
16
- class MiniTest::Unit::TestCase
17
- end
18
-
19
- MiniTest::Unit.autorun
@@ -1,2 +0,0 @@
1
- require 'helper'
2
- require File.dirname(__FILE__) + '/../lib/awrence/ext/hash/to_camel_keys'