awrence 0.1.0 → 1.2.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA256:
3
+ metadata.gz: f49788d1e0e12c23a9e0046b28a26b6205e9f5e1876073588d31c019c62bd4ba
4
+ data.tar.gz: 3eb67e0bcfdaa0d83789b7ffc84107c127ebbc79bb1dcdce6be13e66ee6e8d27
5
+ SHA512:
6
+ metadata.gz: 8fba35e04b34b8e45e10d33cde3b349433df9d6b85d8fc25228b485c91d46a32cdb1d1f114447bb9b59b789f617506c33984d5290e52a482e04fde538a15bd19
7
+ data.tar.gz: 1e781631f2a222d5856b1bd63f8853091ff0cada7bbec643307f2bf0a3a28cfc1bc0256e6b72ed23426b3828702853b6cc2f9af7c844f805561fe3c36424ade4
@@ -1,4 +1,4 @@
1
- Copyright (c) 2013 Dave Hrycyszyn
1
+ Copyright (c) 2021 Technical Panda Ltd
2
2
 
3
3
  Permission is hereby granted, free of charge, to any person obtaining
4
4
  a copy of this software and associated documentation files (the
data/README.md CHANGED
@@ -1,40 +1,87 @@
1
- =======
2
- awrence
3
- ========
1
+ # Awrence
4
2
 
5
- Have you ever needed to automatically convert Rubyish `snake_case` to JSON-style `camelBack` or `CamelCase` hash keys?
3
+ [![Gem Version](https://badge.fury.io/rb/awrence.svg)](https://badge.fury.io/rb/awrence)
6
4
 
7
- Awrence to the rescue.
5
+ Have you ever needed to automatically convert Rubyish `snake_case` to JSON-style `camelBack` or `CamelCase` hash keys?
6
+
7
+ 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
14
28
  my_hash = {"first_key" => 1, "foo_bars" => [{"baz_baz" => "value"}, {"blah_blah" => "value"}]}
15
29
  camel_hash = my_hash.to_camel_keys
30
+ # => {"FirstKey" => 1, "FooBars" => [{"BazBaz" => "value"}, {"BlahBlah" => "value"}]}
31
+
32
+ # OR
33
+
34
+ camel_hash = my_hash.to_camelback_keys
16
35
  # => {"firstKey" => 1, "fooBars" => [{"bazBaz" => "value"}, {"blahBlah" => "value"}]}
17
36
  ```
18
37
 
19
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.
20
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
+
21
68
  ## Limitations
22
69
 
23
- * Your keys must be camelBack or CamelCase. The key "Foo Bar" will output as "foo bar".
24
- * Unlike the original T.E. Lawrence, the awrence gem is non-destructive. There is no Hash#to_camel_keys! form.
70
+ * There is no `Hash#to_camel_keys!` form.
71
+
72
+ # Going the other way
73
+
74
+ If you've already got `CamelCase` and need to `snake_case` it, you are encouraged to try
75
+ the [Plissken](http://github.com/futurechimp/plissken) gem.
76
+
77
+ ## Contributing
25
78
 
26
- ## Contributing to awrence
79
+ Bug reports and pull requests are welcome on GitHub at https://github.com/technicalpanda/awrence. This project is intended to be a safe, welcoming space for collaboration, and contributors are expected to adhere to the [Contributor Covenant](http://contributor-covenant.org) code of conduct.
27
80
 
28
- * Check out the latest master to make sure the feature hasn't been implemented or the bug hasn't been fixed yet.
29
- * Check out the issue tracker to make sure someone already hasn't requested it and/or contributed it.
30
- * Fork the project.
31
- * Start a feature/bugfix branch.
32
- * Commit and push until you are happy with your contribution.
33
- * Make sure to add tests for it. This is important so I don't break it in a future version unintentionally.
34
- * 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.
81
+ ## License
35
82
 
36
- == Copyright
83
+ The gem is available as open source under the terms of the [MIT License](https://opensource.org/licenses/MIT).
37
84
 
38
- Copyright (c) 2013 Dave Hrycyszyn. See LICENSE.txt for
39
- further details.
85
+ ## Code of Conduct
40
86
 
87
+ Everyone interacting with this project’s codebases, issue trackers, chat rooms and mailing lists is expected to follow the [code of conduct](https://github.com/technicalpanda/awrence/blob/main/CODE_OF_CONDUCT.md).
data/Rakefile CHANGED
@@ -1,44 +1,30 @@
1
- # encoding: utf-8
1
+ # frozen_string_literal: true
2
2
 
3
- require 'rubygems'
4
- require 'bundler'
5
3
  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
4
+ require "bundler/setup"
5
+ rescue LoadError
6
+ puts "You must `gem install bundler` and `bundle install` to run rake tasks"
11
7
  end
12
- require 'rake'
13
8
 
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?
9
+ require "rdoc/task"
23
10
 
24
- Awrence to the rescue.
25
-
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
11
+ RDoc::Task.new(:rdoc) do |rdoc|
12
+ rdoc.rdoc_dir = "rdoc"
13
+ rdoc.title = "Awrence"
14
+ rdoc.options << "--line-numbers"
15
+ rdoc.rdoc_files.include("README.md")
16
+ rdoc.rdoc_files.include("lib/**/*.rb")
31
17
  end
32
- Jeweler::RubygemsDotOrgTasks.new
33
18
 
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
19
+ require "bundler/gem_tasks"
40
20
 
41
- task :default => :test
21
+ require "rake/testtask"
22
+
23
+ Rake::TestTask.new(:test) do |t|
24
+ t.libs << "lib"
25
+ t.libs << "test"
26
+ t.pattern = "test/**/*_test.rb"
27
+ t.verbose = false
28
+ end
42
29
 
43
- require 'yard'
44
- YARD::Rake::YardocTask.new
30
+ task default: :test
data/VERSION CHANGED
@@ -1 +1 @@
1
- 0.1.0
1
+ 1.2.0
data/lib/awrence.rb CHANGED
@@ -1 +1,15 @@
1
- require File.dirname(__FILE__) + '/awrence/ext/hash/to_camel_keys'
1
+ # frozen_string_literal: true
2
+
3
+ require "awrence/methods"
4
+ require "awrence/ext/array/to_camel_keys"
5
+ require "awrence/ext/hash/to_camel_keys"
6
+
7
+ module Awrence
8
+ class << self
9
+ attr_writer :acronyms
10
+
11
+ def acronyms
12
+ @acronyms ||= {}
13
+ end
14
+ end
15
+ end
@@ -0,0 +1,5 @@
1
+ # frozen_string_literal: true
2
+
3
+ class Array
4
+ include Awrence::Methods
5
+ end
@@ -1,51 +1,5 @@
1
- class Hash
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
16
-
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
1
+ # frozen_string_literal: true
32
2
 
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
3
+ class Hash
4
+ include Awrence::Methods
5
+ end
@@ -0,0 +1,61 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Awrence
4
+ module Methods
5
+ # Recursively converts Rubyish snake_case hash keys to camelBack JSON-style
6
+ # hash keys suitable for use with a JSON API.
7
+ #
8
+ def to_camelback_keys(value = self)
9
+ process_value(:to_camelback_keys, value, first_upper: false)
10
+ end
11
+
12
+ # Recursively converts Rubyish snake_case hash keys to CamelCase JSON-style
13
+ # hash keys suitable for use with a JSON API.
14
+ #
15
+ def to_camel_keys(value = self)
16
+ process_value(:to_camel_keys, value, first_upper: true)
17
+ end
18
+
19
+ private
20
+
21
+ def camelize_key(key, first_upper: true)
22
+ case key
23
+ when Symbol
24
+ camelize(key.to_s, first_upper: first_upper).to_sym
25
+ when String
26
+ camelize(key, first_upper: first_upper)
27
+ else
28
+ key # Awrence can't camelize anything except strings and symbols
29
+ end
30
+ end
31
+
32
+ def camelize(snake_word, first_upper: true)
33
+ if first_upper
34
+ str = snake_word.to_s
35
+ str = gsubbed(str, /(?:^|_)([^_\s]+)/)
36
+ gsubbed(str, %r{/([^/]*)}, "::")
37
+ else
38
+ parts = snake_word.split("_", 2)
39
+ parts[0] << camelize(parts[1]) if parts.size > 1
40
+ parts[0] || ""
41
+ end
42
+ end
43
+
44
+ def gsubbed(str, pattern, extra = "")
45
+ str.gsub(pattern) do
46
+ extra + (Awrence.acronyms[Regexp.last_match(1)] || Regexp.last_match(1).capitalize)
47
+ end
48
+ end
49
+
50
+ def process_value(method, value, first_upper: true)
51
+ case value
52
+ when Array
53
+ value.map { |v| send(method, v) }
54
+ when Hash
55
+ Hash[value.map { |k, v| [camelize_key(k, first_upper: first_upper), send(method, v)] }]
56
+ else
57
+ value
58
+ end
59
+ end
60
+ end
61
+ end
@@ -0,0 +1,6 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Awrence
4
+ version_file = File.join(File.dirname(__FILE__), "../../VERSION")
5
+ VERSION = File.read(version_file).split("\n").first
6
+ end
metadata CHANGED
@@ -1,121 +1,185 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: awrence
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.0
5
- prerelease:
4
+ version: 1.2.0
6
5
  platform: ruby
7
6
  authors:
8
7
  - Dave Hrycyszyn
9
- autorequire:
8
+ - Stuart Chinery
9
+ autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2013-03-19 00:00:00.000000000 Z
12
+ date: 2021-02-01 00:00:00.000000000 Z
13
13
  dependencies:
14
+ - !ruby/object:Gem::Dependency
15
+ name: byebug
16
+ requirement: !ruby/object:Gem::Requirement
17
+ requirements:
18
+ - - "~>"
19
+ - !ruby/object:Gem::Version
20
+ version: '11.1'
21
+ type: :development
22
+ prerelease: false
23
+ version_requirements: !ruby/object:Gem::Requirement
24
+ requirements:
25
+ - - "~>"
26
+ - !ruby/object:Gem::Version
27
+ version: '11.1'
14
28
  - !ruby/object:Gem::Dependency
15
29
  name: minitest
16
- requirement: &2165004220 !ruby/object:Gem::Requirement
17
- none: false
30
+ requirement: !ruby/object:Gem::Requirement
31
+ requirements:
32
+ - - "~>"
33
+ - !ruby/object:Gem::Version
34
+ version: '5.14'
35
+ type: :development
36
+ prerelease: false
37
+ version_requirements: !ruby/object:Gem::Requirement
38
+ requirements:
39
+ - - "~>"
40
+ - !ruby/object:Gem::Version
41
+ version: '5.14'
42
+ - !ruby/object:Gem::Dependency
43
+ name: minitest-fail-fast
44
+ requirement: !ruby/object:Gem::Requirement
45
+ requirements:
46
+ - - "~>"
47
+ - !ruby/object:Gem::Version
48
+ version: '0.1'
49
+ type: :development
50
+ prerelease: false
51
+ version_requirements: !ruby/object:Gem::Requirement
52
+ requirements:
53
+ - - "~>"
54
+ - !ruby/object:Gem::Version
55
+ version: '0.1'
56
+ - !ruby/object:Gem::Dependency
57
+ name: minitest-macos-notification
58
+ requirement: !ruby/object:Gem::Requirement
59
+ requirements:
60
+ - - "~>"
61
+ - !ruby/object:Gem::Version
62
+ version: '0.3'
63
+ type: :development
64
+ prerelease: false
65
+ version_requirements: !ruby/object:Gem::Requirement
18
66
  requirements:
19
- - - ! '>='
67
+ - - "~>"
20
68
  - !ruby/object:Gem::Version
21
- version: '0'
69
+ version: '0.3'
70
+ - !ruby/object:Gem::Dependency
71
+ name: minitest-reporters
72
+ requirement: !ruby/object:Gem::Requirement
73
+ requirements:
74
+ - - "~>"
75
+ - !ruby/object:Gem::Version
76
+ version: '1.4'
22
77
  type: :development
23
78
  prerelease: false
24
- version_requirements: *2165004220
79
+ version_requirements: !ruby/object:Gem::Requirement
80
+ requirements:
81
+ - - "~>"
82
+ - !ruby/object:Gem::Version
83
+ version: '1.4'
25
84
  - !ruby/object:Gem::Dependency
26
- name: yard
27
- requirement: &2165003740 !ruby/object:Gem::Requirement
28
- none: false
85
+ name: rake
86
+ requirement: !ruby/object:Gem::Requirement
29
87
  requirements:
30
- - - ~>
88
+ - - "~>"
31
89
  - !ruby/object:Gem::Version
32
- version: '0.7'
90
+ version: '13.0'
33
91
  type: :development
34
92
  prerelease: false
35
- version_requirements: *2165003740
93
+ version_requirements: !ruby/object:Gem::Requirement
94
+ requirements:
95
+ - - "~>"
96
+ - !ruby/object:Gem::Version
97
+ version: '13.0'
36
98
  - !ruby/object:Gem::Dependency
37
- name: rdoc
38
- requirement: &2165003260 !ruby/object:Gem::Requirement
39
- none: false
99
+ name: rubocop
100
+ requirement: !ruby/object:Gem::Requirement
40
101
  requirements:
41
- - - ~>
102
+ - - "~>"
42
103
  - !ruby/object:Gem::Version
43
- version: '3.12'
104
+ version: '1.7'
44
105
  type: :development
45
106
  prerelease: false
46
- version_requirements: *2165003260
107
+ version_requirements: !ruby/object:Gem::Requirement
108
+ requirements:
109
+ - - "~>"
110
+ - !ruby/object:Gem::Version
111
+ version: '1.7'
47
112
  - !ruby/object:Gem::Dependency
48
- name: bundler
49
- requirement: &2165002780 !ruby/object:Gem::Requirement
50
- none: false
113
+ name: rubocop-minitest
114
+ requirement: !ruby/object:Gem::Requirement
51
115
  requirements:
52
- - - ! '>='
116
+ - - "~>"
53
117
  - !ruby/object:Gem::Version
54
- version: '0'
118
+ version: '0.10'
55
119
  type: :development
56
120
  prerelease: false
57
- version_requirements: *2165002780
121
+ version_requirements: !ruby/object:Gem::Requirement
122
+ requirements:
123
+ - - "~>"
124
+ - !ruby/object:Gem::Version
125
+ version: '0.10'
58
126
  - !ruby/object:Gem::Dependency
59
- name: jeweler
60
- requirement: &2165002300 !ruby/object:Gem::Requirement
61
- none: false
127
+ name: rubocop-rake
128
+ requirement: !ruby/object:Gem::Requirement
62
129
  requirements:
63
- - - ~>
130
+ - - "~>"
64
131
  - !ruby/object:Gem::Version
65
- version: 1.8.4
132
+ version: '0.5'
66
133
  type: :development
67
134
  prerelease: false
68
- version_requirements: *2165002300
69
- description: ! "Have you ever needed to automatically convert Ruby-style\n snake_case
70
- to CamelCase or camelBack hash keys?\n\n Awrence to the rescue.\n\n This gem
71
- recursively converts all snake_case keys in a hash\n structure to camelBack.
72
- \ "
73
- email: dave.hrycyszyn@headlondon.com
135
+ version_requirements: !ruby/object:Gem::Requirement
136
+ requirements:
137
+ - - "~>"
138
+ - !ruby/object:Gem::Version
139
+ version: '0.5'
140
+ description: |-
141
+ Have you ever needed to automatically convert Ruby-style snake_case to CamelCase or camelBack hash keys?
142
+
143
+ Awrence to the rescue.
144
+
145
+ This gem recursively converts all snake_case keys in a hash structure to camelBack.
146
+ email:
147
+ - dave@constructiveproof.com
148
+ - code@technicalpanda.co.uk
74
149
  executables: []
75
150
  extensions: []
76
- extra_rdoc_files:
77
- - LICENSE.txt
78
- - README.md
151
+ extra_rdoc_files: []
79
152
  files:
80
- - .document
81
- - Gemfile
82
- - Gemfile.lock
83
- - LICENSE.txt
153
+ - MIT-LICENSE
84
154
  - README.md
85
155
  - Rakefile
86
156
  - VERSION
87
- - awrence.gemspec
88
157
  - lib/awrence.rb
158
+ - lib/awrence/ext/array/to_camel_keys.rb
89
159
  - lib/awrence/ext/hash/to_camel_keys.rb
90
- - test/awrence/ext/hash/to_camel_keys_test.rb
91
- - test/helper.rb
92
- - test/test_awrence.rb
93
- homepage: http://github.com/futurechimp/awrence
160
+ - lib/awrence/methods.rb
161
+ - lib/awrence/version.rb
162
+ homepage: https://github.com/technicalpanda/awrence
94
163
  licenses:
95
164
  - MIT
96
- post_install_message:
165
+ metadata: {}
166
+ post_install_message:
97
167
  rdoc_options: []
98
168
  require_paths:
99
169
  - lib
100
170
  required_ruby_version: !ruby/object:Gem::Requirement
101
- none: false
102
171
  requirements:
103
- - - ! '>='
172
+ - - ">="
104
173
  - !ruby/object:Gem::Version
105
- version: '0'
106
- segments:
107
- - 0
108
- hash: -4025899429127598383
174
+ version: '2.5'
109
175
  required_rubygems_version: !ruby/object:Gem::Requirement
110
- none: false
111
176
  requirements:
112
- - - ! '>='
177
+ - - ">="
113
178
  - !ruby/object:Gem::Version
114
179
  version: '0'
115
180
  requirements: []
116
- rubyforge_project:
117
- rubygems_version: 1.8.17
118
- signing_key:
119
- specification_version: 3
181
+ rubygems_version: 3.1.4
182
+ signing_key:
183
+ specification_version: 4
120
184
  summary: Camelize your snake keys when working with JSON APIs
121
185
  test_files: []
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", "~> 3.12"
12
- gem "bundler"
13
- gem "jeweler", "~> 1.8.4"
14
- end
data/Gemfile.lock DELETED
@@ -1,25 +0,0 @@
1
- GEM
2
- remote: https://rubygems.org/
3
- specs:
4
- git (1.2.5)
5
- jeweler (1.8.4)
6
- bundler (~> 1.0)
7
- git (>= 1.2.5)
8
- rake
9
- rdoc
10
- json (1.7.7)
11
- minitest (4.7.0)
12
- rake (10.0.3)
13
- rdoc (3.12.2)
14
- json (~> 1.4)
15
- yard (0.8.5.2)
16
-
17
- PLATFORMS
18
- ruby
19
-
20
- DEPENDENCIES
21
- bundler
22
- jeweler (~> 1.8.4)
23
- minitest
24
- rdoc (~> 3.12)
25
- yard (~> 0.7)
data/awrence.gemspec DELETED
@@ -1,64 +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
-
6
- Gem::Specification.new do |s|
7
- s.name = "awrence"
8
- s.version = "0.1.0"
9
-
10
- s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
11
- s.authors = ["Dave Hrycyszyn"]
12
- s.date = "2013-03-19"
13
- 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. "
14
- s.email = "dave.hrycyszyn@headlondon.com"
15
- s.extra_rdoc_files = [
16
- "LICENSE.txt",
17
- "README.md"
18
- ]
19
- s.files = [
20
- ".document",
21
- "Gemfile",
22
- "Gemfile.lock",
23
- "LICENSE.txt",
24
- "README.md",
25
- "Rakefile",
26
- "VERSION",
27
- "awrence.gemspec",
28
- "lib/awrence.rb",
29
- "lib/awrence/ext/hash/to_camel_keys.rb",
30
- "test/awrence/ext/hash/to_camel_keys_test.rb",
31
- "test/helper.rb",
32
- "test/test_awrence.rb"
33
- ]
34
- s.homepage = "http://github.com/futurechimp/awrence"
35
- s.licenses = ["MIT"]
36
- s.require_paths = ["lib"]
37
- s.rubygems_version = "1.8.17"
38
- s.summary = "Camelize your snake keys when working with JSON APIs"
39
-
40
- if s.respond_to? :specification_version then
41
- s.specification_version = 3
42
-
43
- if Gem::Version.new(Gem::VERSION) >= Gem::Version.new('1.2.0') then
44
- s.add_development_dependency(%q<minitest>, [">= 0"])
45
- s.add_development_dependency(%q<yard>, ["~> 0.7"])
46
- s.add_development_dependency(%q<rdoc>, ["~> 3.12"])
47
- s.add_development_dependency(%q<bundler>, [">= 0"])
48
- s.add_development_dependency(%q<jeweler>, ["~> 1.8.4"])
49
- else
50
- s.add_dependency(%q<minitest>, [">= 0"])
51
- s.add_dependency(%q<yard>, ["~> 0.7"])
52
- s.add_dependency(%q<rdoc>, ["~> 3.12"])
53
- s.add_dependency(%q<bundler>, [">= 0"])
54
- s.add_dependency(%q<jeweler>, ["~> 1.8.4"])
55
- end
56
- else
57
- s.add_dependency(%q<minitest>, [">= 0"])
58
- s.add_dependency(%q<yard>, ["~> 0.7"])
59
- s.add_dependency(%q<rdoc>, ["~> 3.12"])
60
- s.add_dependency(%q<bundler>, [">= 0"])
61
- s.add_dependency(%q<jeweler>, ["~> 1.8.4"])
62
- end
63
- end
64
-
@@ -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
data/test/helper.rb DELETED
@@ -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
data/test/test_awrence.rb DELETED
@@ -1,2 +0,0 @@
1
- require 'helper'
2
- require File.dirname(__FILE__) + '/../lib/awrence/ext/hash/to_camel_keys'