awrence 0.2.0 → 1.2.1

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
- SHA1:
3
- metadata.gz: 77933d65a1db2326a28049db210871984c203835
4
- data.tar.gz: 232d33b6c13d4bc467d7992e58230698b474838f
2
+ SHA256:
3
+ metadata.gz: 6ea9ffe08685c4d1f7d302efaf13077b4cf86908fce25dd6dac706e9f832b39e
4
+ data.tar.gz: a9c44ac2fd6134e5063c30eb924fdbf2a44a6652d956b467a8324bd4065034f1
5
5
  SHA512:
6
- metadata.gz: e8fb9b9ab4549fdc8ac59781659b42c37d831b7266b903b0535af394e01de9626552a534b8e06d8ecccbd212d61bb5fb45fcfe2d5f10e5f477ab420ce938f7ea
7
- data.tar.gz: 7c8a1b90010da1feb2abfcdfbf0fd1115c5ff147f5e83cda3ca268814e1b0a30758b564e956a6756e7deac5cea28ecc3688c5ae6fad8bbc51578ad7116282c8e
6
+ metadata.gz: 9da5f704603f55dbf0220554da57c448bedff741751b66836e22a69bbdef9498938cc7149dbbcb036c2808b650024e6ad90875510986f4c675b0b482ec2aae56
7
+ data.tar.gz: 4b97555cb25181c0dadd271b3c2c4b22fd0cf2c5f06b826f7f87f9282b1f7afb3f78c3c7465ede8ec3e1e48084458b4e99a4a6bed3e026c1ff6942f1b5b8e05e
@@ -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,13 +1,28 @@
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)
4
+ ![CI](https://github.com/technicalpanda/awrence/workflows/CI/badge.svg)
6
5
 
7
- Awrence to the rescue.
6
+ Have you ever needed to automatically convert Rubyish `snake_case` to JSON-style `camelBack` or `CamelCase` hash keys?
7
+
8
+ Awrence to the rescue!
8
9
 
9
10
  This gem recursively converts all snake_case keys in a hash structure to camelBack or CamelCase.
10
11
 
12
+ ## Installation
13
+
14
+ Add this to your Gemfile:
15
+
16
+ ```ruby
17
+ gem "awrence"
18
+ ```
19
+
20
+ Or install it yourself as:
21
+
22
+ ```bash
23
+ gem install awrence
24
+ ```
25
+
11
26
  ## Usage
12
27
 
13
28
  ```ruby
@@ -23,27 +38,51 @@ camel_hash = my_hash.to_camelback_keys
23
38
 
24
39
  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
40
 
41
+ ### Acronyms
42
+
43
+ You can set acronyms that Awrence will now check against when converting the keys.
44
+
45
+ ```ruby
46
+ Awrence.acronyms = { "url" => "URL", "id" => "ID" }
47
+
48
+ my_hash = { "user_url" => "http://a.com", "user_id" => 2 }
49
+ camel_hash = my_hash.to_camel_keys
50
+ # => { "UserURL" => "http://a.com", "UserID" => 2 }
51
+
52
+ camel_hash = my_hash.to_camelback_keys
53
+ # => { "userURL" => "http://a.com", "userID" => 2 }
54
+ ```
55
+
56
+ The acronym will be ignored when it's the first word and `to_camelback_keys` is called.
57
+
58
+ ```ruby
59
+ Awrence.acronyms = { "id" => "ID" }
60
+
61
+ my_hash = { "id" => 2 }
62
+ camel_hash = my_hash.to_camel_keys
63
+ # => { "ID" => 2 }
64
+
65
+ camel_hash = my_hash.to_camelback_keys
66
+ # => { "id" => 2 }
67
+ ```
68
+
26
69
  ## Limitations
27
70
 
28
- * 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.
71
+ * There is no `Hash#to_camel_keys!` form.
29
72
 
30
73
  # Going the other way
31
74
 
32
75
  If you've already got `CamelCase` and need to `snake_case` it, you are encouraged to try
33
76
  the [Plissken](http://github.com/futurechimp/plissken) gem.
34
77
 
35
- ## Contributing to awrence
78
+ ## Contributing
79
+
80
+ 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.
36
81
 
37
- * Check out the latest master to make sure the feature hasn't been implemented or the bug hasn't been fixed yet.
38
- * Check out the issue tracker to make sure someone already hasn't requested it and/or contributed it.
39
- * Fork the project.
40
- * Start a feature/bugfix branch.
41
- * Commit and push until you are happy with your contribution.
42
- * Make sure to add tests for it. This is important so I don't break it in a future version unintentionally.
43
- * 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.
82
+ ## License
44
83
 
45
- == Copyright
84
+ The gem is available as open source under the terms of the [MIT License](https://opensource.org/licenses/MIT).
46
85
 
47
- Copyright (c) 2013 Dave Hrycyszyn. See LICENSE.txt for
48
- further details.
86
+ ## Code of Conduct
49
87
 
88
+ 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.2.0
1
+ 1.2.1
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
+ value.map { |k, v| [camelize_key(k, first_upper: first_upper), send(method, v)] }.to_h
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,114 +1,169 @@
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.2.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Dave Hrycyszyn
8
- autorequire:
8
+ - Stuart Chinery
9
+ autorequire:
9
10
  bindir: bin
10
11
  cert_chain: []
11
- date: 2017-01-13 00:00:00.000000000 Z
12
+ date: 2021-02-18 00:00:00.000000000 Z
12
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'
13
28
  - !ruby/object:Gem::Dependency
14
29
  name: minitest
15
30
  requirement: !ruby/object:Gem::Requirement
16
31
  requirements:
17
- - - ">="
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
+ - - "~>"
18
61
  - !ruby/object:Gem::Version
19
- version: '0'
62
+ version: '0.3'
20
63
  type: :development
21
64
  prerelease: false
22
65
  version_requirements: !ruby/object:Gem::Requirement
23
66
  requirements:
24
- - - ">="
67
+ - - "~>"
25
68
  - !ruby/object:Gem::Version
26
- version: '0'
69
+ version: '0.3'
27
70
  - !ruby/object:Gem::Dependency
28
- name: yard
71
+ name: minitest-reporters
29
72
  requirement: !ruby/object:Gem::Requirement
30
73
  requirements:
31
74
  - - "~>"
32
75
  - !ruby/object:Gem::Version
33
- version: '0.7'
76
+ version: '1.4'
34
77
  type: :development
35
78
  prerelease: false
36
79
  version_requirements: !ruby/object:Gem::Requirement
37
80
  requirements:
38
81
  - - "~>"
39
82
  - !ruby/object:Gem::Version
40
- version: '0.7'
83
+ version: '1.4'
41
84
  - !ruby/object:Gem::Dependency
42
- name: rdoc
85
+ name: rake
43
86
  requirement: !ruby/object:Gem::Requirement
44
87
  requirements:
45
88
  - - "~>"
46
89
  - !ruby/object:Gem::Version
47
- version: '4.2'
90
+ version: '13.0'
48
91
  type: :development
49
92
  prerelease: false
50
93
  version_requirements: !ruby/object:Gem::Requirement
51
94
  requirements:
52
95
  - - "~>"
53
96
  - !ruby/object:Gem::Version
54
- version: '4.2'
97
+ version: '13.0'
55
98
  - !ruby/object:Gem::Dependency
56
- name: bundler
99
+ name: rubocop
57
100
  requirement: !ruby/object:Gem::Requirement
58
101
  requirements:
59
- - - ">="
102
+ - - "~>"
60
103
  - !ruby/object:Gem::Version
61
- version: '0'
104
+ version: '1.7'
62
105
  type: :development
63
106
  prerelease: false
64
107
  version_requirements: !ruby/object:Gem::Requirement
65
108
  requirements:
66
- - - ">="
109
+ - - "~>"
67
110
  - !ruby/object:Gem::Version
68
- version: '0'
111
+ version: '1.7'
69
112
  - !ruby/object:Gem::Dependency
70
- name: jeweler
113
+ name: rubocop-minitest
71
114
  requirement: !ruby/object:Gem::Requirement
72
115
  requirements:
73
116
  - - "~>"
74
117
  - !ruby/object:Gem::Version
75
- version: '2.3'
118
+ version: '0.10'
76
119
  type: :development
77
120
  prerelease: false
78
121
  version_requirements: !ruby/object:Gem::Requirement
79
122
  requirements:
80
123
  - - "~>"
81
124
  - !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
125
+ version: '0.10'
126
+ - !ruby/object:Gem::Dependency
127
+ name: rubocop-rake
128
+ requirement: !ruby/object:Gem::Requirement
129
+ requirements:
130
+ - - "~>"
131
+ - !ruby/object:Gem::Version
132
+ version: '0.5'
133
+ type: :development
134
+ prerelease: false
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
88
149
  executables: []
89
150
  extensions: []
90
- extra_rdoc_files:
91
- - LICENSE.txt
92
- - README.md
151
+ extra_rdoc_files: []
93
152
  files:
94
- - ".document"
95
- - Gemfile
96
- - Gemfile.lock
97
- - LICENSE.txt
153
+ - MIT-LICENSE
98
154
  - README.md
99
155
  - Rakefile
100
156
  - VERSION
101
- - awrence.gemspec
102
157
  - lib/awrence.rb
158
+ - lib/awrence/ext/array/to_camel_keys.rb
103
159
  - 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
160
+ - lib/awrence/methods.rb
161
+ - lib/awrence/version.rb
162
+ homepage: https://github.com/technicalpanda/awrence
108
163
  licenses:
109
164
  - MIT
110
165
  metadata: {}
111
- post_install_message:
166
+ post_install_message:
112
167
  rdoc_options: []
113
168
  require_paths:
114
169
  - lib
@@ -116,16 +171,15 @@ required_ruby_version: !ruby/object:Gem::Requirement
116
171
  requirements:
117
172
  - - ">="
118
173
  - !ruby/object:Gem::Version
119
- version: '0'
174
+ version: '2.5'
120
175
  required_rubygems_version: !ruby/object:Gem::Requirement
121
176
  requirements:
122
177
  - - ">="
123
178
  - !ruby/object:Gem::Version
124
179
  version: '0'
125
180
  requirements: []
126
- rubyforge_project:
127
- rubygems_version: 2.5.1
128
- signing_key:
181
+ rubygems_version: 3.1.4
182
+ signing_key:
129
183
  specification_version: 4
130
184
  summary: Camelize your snake keys when working with JSON APIs
131
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', '~> 4.2'
12
- gem "bundler"
13
- gem 'jeweler', '~> 2.3'
14
- end
data/Gemfile.lock DELETED
@@ -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
data/awrence.gemspec DELETED
@@ -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
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'