advanced_hash_keys 1.0.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +7 -0
- data/.gitignore +38 -0
- data/.rubocop.yml +87 -0
- data/Gemfile +4 -0
- data/Gemfile.lock +54 -0
- data/LICENSE +22 -0
- data/README.md +61 -0
- data/Rakefile +10 -0
- data/advanced_hash_keys.gemspec +22 -0
- data/lib/advanced_hash_keys.rb +5 -0
- data/lib/advanced_hash_keys/core_ext/hash.rb +49 -0
- data/lib/advanced_hash_keys/core_ext/hash_with_indifferent_access.rb +13 -0
- data/lib/advanced_hash_keys/version.rb +3 -0
- data/spec/advanded_hash_keys_spec.rb +173 -0
- metadata +117 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: f7946b652b528ba73093fe49bb542cc51c432df8
|
4
|
+
data.tar.gz: 66bf4356ecb9ecd1439004e09605902e81496696
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: 9a73129e04f45ac5d417bcbf2effa063fe33da919621f24c22d5cd8413fcf161220551276f5d635864fd2bfd8ded9e39abc09a07edc8c67b7838b5fddfd3522f
|
7
|
+
data.tar.gz: c9644b15501cb035e5dc31298fda2e36a409e67f0e94cf8113763ba7a295d8fbac505aa10e17d544c92cff95f247ffea144b66c6617ea8a78291c7695343ba82
|
data/.gitignore
ADDED
@@ -0,0 +1,38 @@
|
|
1
|
+
*.gem
|
2
|
+
*.rbc
|
3
|
+
/.config
|
4
|
+
/coverage/
|
5
|
+
/InstalledFiles
|
6
|
+
/pkg/
|
7
|
+
/spec/reports/
|
8
|
+
/test/tmp/
|
9
|
+
/test/version_tmp/
|
10
|
+
/tmp/
|
11
|
+
|
12
|
+
## Specific to RubyMotion:
|
13
|
+
.dat*
|
14
|
+
.repl_history
|
15
|
+
build/
|
16
|
+
|
17
|
+
## Documentation cache and generated files:
|
18
|
+
/.yardoc/
|
19
|
+
/_yardoc/
|
20
|
+
/doc/
|
21
|
+
/rdoc/
|
22
|
+
|
23
|
+
## Environment normalisation:
|
24
|
+
/.bundle/
|
25
|
+
/lib/bundler/man/
|
26
|
+
|
27
|
+
# for a library or gem, you might want to ignore these files since the code is
|
28
|
+
# intended to run in multiple environments; otherwise, check them in:
|
29
|
+
# Gemfile.lock
|
30
|
+
# .ruby-version
|
31
|
+
# .ruby-gemset
|
32
|
+
|
33
|
+
# unless supporting rvm < 1.11.0 or doing something fancy, ignore this:
|
34
|
+
.rvmrc
|
35
|
+
|
36
|
+
# bundler
|
37
|
+
vendor/
|
38
|
+
|
data/.rubocop.yml
ADDED
@@ -0,0 +1,87 @@
|
|
1
|
+
# This file overrides https://github.com/bbatsov/rubocop/blob/master/config/default.yml
|
2
|
+
|
3
|
+
AllCops:
|
4
|
+
Include:
|
5
|
+
- Rakefile
|
6
|
+
- advanced_hash_keys.gemspec
|
7
|
+
Exclude:
|
8
|
+
- vendor/**
|
9
|
+
|
10
|
+
# Limit lines to 80 characters.
|
11
|
+
LineLength:
|
12
|
+
Enabled: false
|
13
|
+
|
14
|
+
# Avoid methods longer than 10 lines of code
|
15
|
+
MethodLength:
|
16
|
+
Enabled: false
|
17
|
+
|
18
|
+
ClassLength:
|
19
|
+
Enabled: false
|
20
|
+
|
21
|
+
# Favor modifier if/unless usage when you have a single-line body.
|
22
|
+
IfUnlessModifier:
|
23
|
+
Enabled: false
|
24
|
+
|
25
|
+
# Favor modifier while/until usage when you have a single-line body.
|
26
|
+
WhileUntilModifier:
|
27
|
+
Enabled: false
|
28
|
+
|
29
|
+
# Preferred collection methods.
|
30
|
+
CollectionMethods:
|
31
|
+
Enabled: false
|
32
|
+
|
33
|
+
# Don't interpolate global, instance and class variables directly in strings.
|
34
|
+
VariableInterpolation:
|
35
|
+
Enabled: false
|
36
|
+
|
37
|
+
# Use only ascii symbols in comments.
|
38
|
+
AsciiComments:
|
39
|
+
Enabled: false
|
40
|
+
|
41
|
+
CaseEquality:
|
42
|
+
Description: 'Avoid explicit use of the case equality operator(===).'
|
43
|
+
Enabled: false
|
44
|
+
|
45
|
+
SignalException:
|
46
|
+
Description: 'Checks for proper usage of fail and raise.'
|
47
|
+
Enabled: false
|
48
|
+
|
49
|
+
SymbolArray:
|
50
|
+
Description: 'Use %i or %I for arrays of symbols.'
|
51
|
+
Enabled: true
|
52
|
+
|
53
|
+
CyclomaticComplexity:
|
54
|
+
Max: 10
|
55
|
+
|
56
|
+
Documentation:
|
57
|
+
Description: 'Document classes and non-namespace modules.'
|
58
|
+
Enabled: false
|
59
|
+
|
60
|
+
TrivialAccessors:
|
61
|
+
Enabled: false
|
62
|
+
|
63
|
+
AccessModifierIndentation:
|
64
|
+
Enabled: false
|
65
|
+
|
66
|
+
PerlBackrefs:
|
67
|
+
Enabled: false
|
68
|
+
|
69
|
+
SingleLineBlockParams:
|
70
|
+
Description: 'Enforces the names of some block params.'
|
71
|
+
Enabled: false
|
72
|
+
|
73
|
+
ClassAndModuleChildren:
|
74
|
+
Enabled: false
|
75
|
+
|
76
|
+
FileName:
|
77
|
+
Enabled: false
|
78
|
+
|
79
|
+
RegexpLiteral:
|
80
|
+
Enabled: false
|
81
|
+
|
82
|
+
HashSyntax:
|
83
|
+
Description: >-
|
84
|
+
Prefer Ruby 1.9 hash syntax { a: 1, b: 2 } over 1.8 syntax
|
85
|
+
{ :a => 1, :b => 2 }.
|
86
|
+
Enabled: false
|
87
|
+
|
data/Gemfile
ADDED
data/Gemfile.lock
ADDED
@@ -0,0 +1,54 @@
|
|
1
|
+
PATH
|
2
|
+
remote: .
|
3
|
+
specs:
|
4
|
+
advanced_hash_keys (2.0.0)
|
5
|
+
activesupport
|
6
|
+
rake
|
7
|
+
|
8
|
+
GEM
|
9
|
+
remote: https://rubygems.org/
|
10
|
+
specs:
|
11
|
+
activesupport (4.1.0)
|
12
|
+
i18n (~> 0.6, >= 0.6.9)
|
13
|
+
json (~> 1.7, >= 1.7.7)
|
14
|
+
minitest (~> 5.1)
|
15
|
+
thread_safe (~> 0.1)
|
16
|
+
tzinfo (~> 1.1)
|
17
|
+
ast (2.0.0)
|
18
|
+
diff-lcs (1.2.5)
|
19
|
+
i18n (0.6.9)
|
20
|
+
json (1.8.1)
|
21
|
+
minitest (5.3.3)
|
22
|
+
parser (2.1.9)
|
23
|
+
ast (>= 1.1, < 3.0)
|
24
|
+
slop (~> 3.4, >= 3.4.5)
|
25
|
+
powerpack (0.0.9)
|
26
|
+
rainbow (2.0.0)
|
27
|
+
rake (10.3.1)
|
28
|
+
rspec (2.14.1)
|
29
|
+
rspec-core (~> 2.14.0)
|
30
|
+
rspec-expectations (~> 2.14.0)
|
31
|
+
rspec-mocks (~> 2.14.0)
|
32
|
+
rspec-core (2.14.8)
|
33
|
+
rspec-expectations (2.14.5)
|
34
|
+
diff-lcs (>= 1.1.3, < 2.0)
|
35
|
+
rspec-mocks (2.14.6)
|
36
|
+
rubocop (0.20.1)
|
37
|
+
json (>= 1.7.7, < 2)
|
38
|
+
parser (~> 2.1.7)
|
39
|
+
powerpack (~> 0.0.6)
|
40
|
+
rainbow (>= 1.99.1, < 3.0)
|
41
|
+
ruby-progressbar (~> 1.4)
|
42
|
+
ruby-progressbar (1.4.2)
|
43
|
+
slop (3.5.0)
|
44
|
+
thread_safe (0.3.3)
|
45
|
+
tzinfo (1.1.0)
|
46
|
+
thread_safe (~> 0.1)
|
47
|
+
|
48
|
+
PLATFORMS
|
49
|
+
ruby
|
50
|
+
|
51
|
+
DEPENDENCIES
|
52
|
+
advanced_hash_keys!
|
53
|
+
rspec
|
54
|
+
rubocop
|
data/LICENSE
ADDED
@@ -0,0 +1,22 @@
|
|
1
|
+
Copyright (c) 2012 Anjali Shenoy
|
2
|
+
|
3
|
+
MIT License
|
4
|
+
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining
|
6
|
+
a copy of this software and associated documentation files (the
|
7
|
+
"Software"), to deal in the Software without restriction, including
|
8
|
+
without limitation the rights to use, copy, modify, merge, publish,
|
9
|
+
distribute, sublicense, and/or sell copies of the Software, and to
|
10
|
+
permit persons to whom the Software is furnished to do so, subject to
|
11
|
+
the following conditions:
|
12
|
+
|
13
|
+
The above copyright notice and this permission notice shall be
|
14
|
+
included in all copies or substantial portions of the Software.
|
15
|
+
|
16
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
17
|
+
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
18
|
+
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
19
|
+
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
|
20
|
+
LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
|
21
|
+
OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
22
|
+
WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
data/README.md
ADDED
@@ -0,0 +1,61 @@
|
|
1
|
+
# AdvancedHashKeys
|
2
|
+
|
3
|
+
Extends ActiveSupport's symbolize_keys/stringify_keys to recursively convert all keys in a gem. By default, it is fully backwards compatible with ActiveSupport's symbolize_keys/stringify_keys method. If the recursive flag is set to true however and it recursively converts any values which are hashes.
|
4
|
+
|
5
|
+
## Installation
|
6
|
+
|
7
|
+
Add this line to your application's Gemfile:
|
8
|
+
|
9
|
+
gem 'advanced_hash_keys'
|
10
|
+
|
11
|
+
And then execute:
|
12
|
+
|
13
|
+
$ bundle
|
14
|
+
|
15
|
+
Or install it yourself as:
|
16
|
+
|
17
|
+
$ gem install advanced_hash_keys
|
18
|
+
|
19
|
+
## Usage
|
20
|
+
|
21
|
+
gem install advanced_hash_keys
|
22
|
+
or
|
23
|
+
include it in your Gemfile and then run bundle install.
|
24
|
+
|
25
|
+
Works on Ruby 2.1.1p76, ActiveSupport version 4.1.0 as of now.
|
26
|
+
|
27
|
+
### symbolize_keys Examples:
|
28
|
+
|
29
|
+
{'a' => {'b' => 1}}.symbolize_keys = {:a => {'b' => 1}}
|
30
|
+
|
31
|
+
{'a' => {'b' => 1}}.symbolize_keys(true) = {:a => {:b => 1}}
|
32
|
+
|
33
|
+
{'a' => {'b' => 1}}.symbolize_keys! = {:a => {'b' => 1}}
|
34
|
+
|
35
|
+
{'a' => {'b' => 1}}.symbolize_keys!(true) = {:a => {:b => 1}}
|
36
|
+
|
37
|
+
### stringify_keys Examples:
|
38
|
+
|
39
|
+
{:a => {:b => 1}}.stringify_keys = {'a' => {:b => 1}}
|
40
|
+
|
41
|
+
{:a => {:b => 1}}.stringify_keys(true) = {'a' => {'b' => 1}}
|
42
|
+
|
43
|
+
{:a => {:b => 1}}.stringify_keys! = {'a' => {:b => 1}}
|
44
|
+
|
45
|
+
{:a => {:b => 1}}.stringify_keys!(true) = {'a' => {'b' => 1}}
|
46
|
+
|
47
|
+
|
48
|
+
## Contributing
|
49
|
+
|
50
|
+
1. Fork it
|
51
|
+
2. Create your feature branch (`git checkout -b my-new-feature`)
|
52
|
+
3. Commit your changes (`git commit -am 'Added some feature'`)
|
53
|
+
4. Check rspec(`bundle exec rake spec`)
|
54
|
+
5. Push to the branch (`git push origin my-new-feature`)
|
55
|
+
6. Create new Pull Request
|
56
|
+
|
57
|
+
|
58
|
+
## Special Thanks
|
59
|
+
|
60
|
+
* hash_symoblizer (https://github.com/anjshenoy/hash_symbolizer)
|
61
|
+
** symbolize_keys(true)'s original repository.
|
data/Rakefile
ADDED
@@ -0,0 +1,22 @@
|
|
1
|
+
# -*- encoding: utf-8 -*-
|
2
|
+
require File.expand_path('../lib/advanced_hash_keys/version', __FILE__)
|
3
|
+
|
4
|
+
Gem::Specification.new do |gem|
|
5
|
+
gem.authors = ['Yuichi UEMURA']
|
6
|
+
gem.email = ['yuichi.u@gmail.com']
|
7
|
+
gem.description = %q(Extends ActiveSupport's symbolize_keys / stringifier_keys to recursively symbolize keys at all levels in a Hash / Array)
|
8
|
+
gem.summary = %q(Extends ActiveSupport's symbolize_keys to recursively symbolize / stringifier all keys in a gem. By default, it is fully backwards compatible with ActiveSupport's symbolize_keys/stringfier_keys method. If the recursive flag is set to true however and it recursively symbolizes any values which are hashes.)
|
9
|
+
gem.homepage = 'http://github.com/u-ichi/advanced_hash_keys'
|
10
|
+
|
11
|
+
gem.files = `git ls-files`.split($OUTPUT_RECORD_SEPARATOR)
|
12
|
+
gem.executables = gem.files.grep(%r{^bin/}).map { |f| File.basename(f) }
|
13
|
+
gem.test_files = gem.files.grep(%r{^(test|spec|features)/})
|
14
|
+
gem.name = 'advanced_hash_keys'
|
15
|
+
gem.require_paths = ['lib']
|
16
|
+
gem.version = AdvancedHashKeys::VERSION
|
17
|
+
|
18
|
+
gem.add_dependency 'rake'
|
19
|
+
gem.add_dependency 'activesupport'
|
20
|
+
gem.add_development_dependency('rubocop')
|
21
|
+
gem.add_development_dependency('rspec')
|
22
|
+
end
|
@@ -0,0 +1,49 @@
|
|
1
|
+
class Hash
|
2
|
+
# Return a new hash with all keys converted to symbols, as long as
|
3
|
+
# they respond to +to_sym+.
|
4
|
+
# If recursive is set to true, then keys at all levels will be symbolized.
|
5
|
+
def symbolize_keys(recursive = false)
|
6
|
+
dup.symbolize_keys!(recursive)
|
7
|
+
end
|
8
|
+
|
9
|
+
# Destructively convert all keys to symbols, as long as they respond
|
10
|
+
# to +to_sym+.
|
11
|
+
# If recursive is set to true, then keys at all levels will be symbolized.
|
12
|
+
def symbolize_keys!(recursive = false)
|
13
|
+
keys.each do |key|
|
14
|
+
value = delete(key)
|
15
|
+
key = key.respond_to?(:to_sym) ? key.to_sym : key
|
16
|
+
if value.is_a?(Array)
|
17
|
+
value = value.map do |sub_value|
|
18
|
+
(recursive && sub_value.is_a?(Hash)) ? sub_value.dup.symbolize_keys!(recursive) : sub_value
|
19
|
+
end
|
20
|
+
end
|
21
|
+
self[key] = (recursive && value.is_a?(Hash)) ? value.dup.symbolize_keys!(recursive) : value
|
22
|
+
end
|
23
|
+
self
|
24
|
+
end
|
25
|
+
|
26
|
+
# Return a new hash with all keys converted to symbols, as long as
|
27
|
+
# they respond to +to_s+.
|
28
|
+
# If recursive is set to true, then keys at all levels will be stringified.
|
29
|
+
def stringify_keys(recursive = false)
|
30
|
+
dup.stringify_keys!(recursive)
|
31
|
+
end
|
32
|
+
|
33
|
+
# Destructively convert all keys to strings, as long as they respond
|
34
|
+
# to +to_sym+.
|
35
|
+
# If recursive is set to true, then keys at all levels will be stringified.
|
36
|
+
def stringify_keys!(recursive = false)
|
37
|
+
keys.each do |key|
|
38
|
+
value = delete(key)
|
39
|
+
key = key.respond_to?(:to_s) ? key.to_s : key
|
40
|
+
if value.is_a?(Array)
|
41
|
+
value = value.map do |sub_value|
|
42
|
+
(recursive && sub_value.is_a?(Hash)) ? sub_value.dup.stringify_keys!(recursive) : sub_value
|
43
|
+
end
|
44
|
+
end
|
45
|
+
self[key] = (recursive && value.is_a?(Hash)) ? value.dup.stringify_keys!(recursive) : value
|
46
|
+
end
|
47
|
+
self
|
48
|
+
end
|
49
|
+
end
|
@@ -0,0 +1,13 @@
|
|
1
|
+
class HashWithIndifferentAccess < Hash
|
2
|
+
undef :symbolize_keys
|
3
|
+
# If recursive is set to true, keys at all levels will be symbolized
|
4
|
+
def symbolize_keys(recursive = false)
|
5
|
+
to_hash.symbolize_keys(recursive)
|
6
|
+
end
|
7
|
+
|
8
|
+
undef :stringify_keys
|
9
|
+
# If recursive is set to true, keys at all levels will be symbolized
|
10
|
+
def stringify_keys(recursive = false)
|
11
|
+
to_hash.stringify_keys(recursive)
|
12
|
+
end
|
13
|
+
end
|
@@ -0,0 +1,173 @@
|
|
1
|
+
require 'rspec'
|
2
|
+
|
3
|
+
RSpec.configure do |c|
|
4
|
+
c.color = true
|
5
|
+
c.tty = true
|
6
|
+
end
|
7
|
+
|
8
|
+
require File.expand_path("#{File.dirname(__FILE__)}/../lib/advanced_hash_keys")
|
9
|
+
|
10
|
+
describe Hash do
|
11
|
+
before do
|
12
|
+
@strings = { 'a' => 1, 'b' => 2 }
|
13
|
+
@symbols = { :a => 1, :b => 2 }
|
14
|
+
@mixed = { :a => 1, 'b' => 2 }
|
15
|
+
@fixnums = { 0 => 1, 1 => 2 }
|
16
|
+
@illegal_symbols = { [] => 3 }
|
17
|
+
@nested_hash = { 'a' => { 'b' => 2 }, 'c' => [{ 'd' => 3 }] }
|
18
|
+
@nested_hash_first_level_symbolized = { :a => { 'b' => 2 }, :c => [{ 'd' => 3 }] }
|
19
|
+
@nested_hash_all_keys_symbolized = { :a => { :b => 2 }, :c => [{ :d => 3 }] }
|
20
|
+
@nested_hash_first_level_stringfied = { 'a' => { 'b' => 2 }, 'c' => [{ 'd' => 3 }] }
|
21
|
+
@nested_hash_all_keys_stringfied = { 'a' => { 'b' => 2 }, 'c' => [{ 'd' => 3 }] }
|
22
|
+
end
|
23
|
+
|
24
|
+
describe 'symolize_keys' do
|
25
|
+
subject { base_param.symbolize_keys(input_param) }
|
26
|
+
context 'input_param is true' do
|
27
|
+
let(:input_param) { true }
|
28
|
+
context 'base_param is string key' do
|
29
|
+
let(:base_param) { @strings }
|
30
|
+
|
31
|
+
it 'agrees with symbols' do
|
32
|
+
expect(subject).to eq @symbols
|
33
|
+
end
|
34
|
+
end
|
35
|
+
|
36
|
+
context 'base_param is mixed key' do
|
37
|
+
let(:base_param) { @mixed }
|
38
|
+
|
39
|
+
it 'agrees with symbols' do
|
40
|
+
expect(subject).to eq @symbols
|
41
|
+
end
|
42
|
+
end
|
43
|
+
|
44
|
+
context 'base_param is nested_hash' do
|
45
|
+
let(:base_param) { @nested_hash }
|
46
|
+
|
47
|
+
it 'agrees with nested hash all keys symbolized' do
|
48
|
+
expect(subject).to eq @nested_hash_all_keys_symbolized
|
49
|
+
end
|
50
|
+
end
|
51
|
+
|
52
|
+
context 'base_param is illegal_symbol' do
|
53
|
+
let(:base_param) { @illegal_symbol }
|
54
|
+
|
55
|
+
it 'raise NoMethodError' do
|
56
|
+
expect { subject }.to raise_error NoMethodError
|
57
|
+
end
|
58
|
+
end
|
59
|
+
end
|
60
|
+
|
61
|
+
context 'input_param is false' do
|
62
|
+
let(:input_param) { false }
|
63
|
+
|
64
|
+
context 'base_param is string key' do
|
65
|
+
let(:base_param) { @strings }
|
66
|
+
|
67
|
+
it 'agrees with symbols' do
|
68
|
+
expect(subject).to eq @symbols
|
69
|
+
end
|
70
|
+
end
|
71
|
+
|
72
|
+
context 'base_param is mixed key' do
|
73
|
+
let(:base_param) { @mixed }
|
74
|
+
|
75
|
+
it 'agrees with symbols' do
|
76
|
+
expect(subject).to eq @symbols
|
77
|
+
end
|
78
|
+
end
|
79
|
+
|
80
|
+
context 'base_param is nested_hash' do
|
81
|
+
let(:base_param) { @nested_hash }
|
82
|
+
|
83
|
+
it 'agrees with nested hash first level symbolized' do
|
84
|
+
expect(subject).to eq @nested_hash_first_level_symbolized
|
85
|
+
end
|
86
|
+
end
|
87
|
+
|
88
|
+
context 'base_param is illegal_symbol' do
|
89
|
+
let(:base_param) { @illegal_symbol }
|
90
|
+
|
91
|
+
it 'raise NoMethodError' do
|
92
|
+
expect { subject }.to raise_error NoMethodError
|
93
|
+
end
|
94
|
+
end
|
95
|
+
end
|
96
|
+
end
|
97
|
+
|
98
|
+
describe 'stringify_keys' do
|
99
|
+
subject { base_param.stringify_keys(input_param) }
|
100
|
+
|
101
|
+
context 'input_param is true' do
|
102
|
+
let(:input_param) { true }
|
103
|
+
|
104
|
+
context 'base_param is symolized key' do
|
105
|
+
let(:base_param) { @symbols }
|
106
|
+
|
107
|
+
it 'agrees with string' do
|
108
|
+
expect(subject).to eq @strings
|
109
|
+
end
|
110
|
+
end
|
111
|
+
|
112
|
+
context 'base_param is mixed key' do
|
113
|
+
let(:base_param) { @mixed }
|
114
|
+
|
115
|
+
it 'agrees with symbols' do
|
116
|
+
expect(subject).to eq @strings
|
117
|
+
end
|
118
|
+
end
|
119
|
+
|
120
|
+
context 'base_param is nested_hash' do
|
121
|
+
let(:base_param) { @nested_hash }
|
122
|
+
|
123
|
+
it 'agrees with nested hash all keys stringified' do
|
124
|
+
expect(subject).to eq @nested_hash_all_keys_stringfied
|
125
|
+
end
|
126
|
+
end
|
127
|
+
|
128
|
+
context 'base_param is illegal_symbol' do
|
129
|
+
let(:base_param) { @illegal_symbol }
|
130
|
+
|
131
|
+
it 'raise NoMethodError' do
|
132
|
+
expect { subject }.to raise_error NoMethodError
|
133
|
+
end
|
134
|
+
end
|
135
|
+
end
|
136
|
+
|
137
|
+
context 'input_param is false' do
|
138
|
+
let(:input_param) { false }
|
139
|
+
|
140
|
+
context 'base_param is symolized key' do
|
141
|
+
let(:base_param) { @symbols }
|
142
|
+
|
143
|
+
it 'agrees with string' do
|
144
|
+
expect(subject).to eq @strings
|
145
|
+
end
|
146
|
+
end
|
147
|
+
|
148
|
+
context 'base_param is mixed key' do
|
149
|
+
let(:base_param) { @mixed }
|
150
|
+
|
151
|
+
it 'agrees with symbols' do
|
152
|
+
expect(subject).to eq @strings
|
153
|
+
end
|
154
|
+
end
|
155
|
+
|
156
|
+
context 'base_param is nested_hash' do
|
157
|
+
let(:base_param) { @nested_hash }
|
158
|
+
|
159
|
+
it 'agrees with nested hash first level stringified' do
|
160
|
+
expect(subject).to eq @nested_hash_first_level_stringfied
|
161
|
+
end
|
162
|
+
end
|
163
|
+
|
164
|
+
context 'base_param is illegal_symbol' do
|
165
|
+
let(:base_param) { @illegal_symbol }
|
166
|
+
|
167
|
+
it 'raise NoMethodError' do
|
168
|
+
expect { subject }.to raise_error NoMethodError
|
169
|
+
end
|
170
|
+
end
|
171
|
+
end
|
172
|
+
end
|
173
|
+
end
|
metadata
ADDED
@@ -0,0 +1,117 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: advanced_hash_keys
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 1.0.0
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Yuichi UEMURA
|
8
|
+
autorequire:
|
9
|
+
bindir: bin
|
10
|
+
cert_chain: []
|
11
|
+
date: 2014-04-22 00:00:00.000000000 Z
|
12
|
+
dependencies:
|
13
|
+
- !ruby/object:Gem::Dependency
|
14
|
+
name: rake
|
15
|
+
requirement: !ruby/object:Gem::Requirement
|
16
|
+
requirements:
|
17
|
+
- - ">="
|
18
|
+
- !ruby/object:Gem::Version
|
19
|
+
version: '0'
|
20
|
+
type: :runtime
|
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: activesupport
|
29
|
+
requirement: !ruby/object:Gem::Requirement
|
30
|
+
requirements:
|
31
|
+
- - ">="
|
32
|
+
- !ruby/object:Gem::Version
|
33
|
+
version: '0'
|
34
|
+
type: :runtime
|
35
|
+
prerelease: false
|
36
|
+
version_requirements: !ruby/object:Gem::Requirement
|
37
|
+
requirements:
|
38
|
+
- - ">="
|
39
|
+
- !ruby/object:Gem::Version
|
40
|
+
version: '0'
|
41
|
+
- !ruby/object:Gem::Dependency
|
42
|
+
name: rubocop
|
43
|
+
requirement: !ruby/object:Gem::Requirement
|
44
|
+
requirements:
|
45
|
+
- - ">="
|
46
|
+
- !ruby/object:Gem::Version
|
47
|
+
version: '0'
|
48
|
+
type: :development
|
49
|
+
prerelease: false
|
50
|
+
version_requirements: !ruby/object:Gem::Requirement
|
51
|
+
requirements:
|
52
|
+
- - ">="
|
53
|
+
- !ruby/object:Gem::Version
|
54
|
+
version: '0'
|
55
|
+
- !ruby/object:Gem::Dependency
|
56
|
+
name: rspec
|
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
|
+
description: Extends ActiveSupport's symbolize_keys / stringifier_keys to recursively
|
70
|
+
symbolize keys at all levels in a Hash / Array
|
71
|
+
email:
|
72
|
+
- yuichi.u@gmail.com
|
73
|
+
executables: []
|
74
|
+
extensions: []
|
75
|
+
extra_rdoc_files: []
|
76
|
+
files:
|
77
|
+
- ".gitignore"
|
78
|
+
- ".rubocop.yml"
|
79
|
+
- Gemfile
|
80
|
+
- Gemfile.lock
|
81
|
+
- LICENSE
|
82
|
+
- README.md
|
83
|
+
- Rakefile
|
84
|
+
- advanced_hash_keys.gemspec
|
85
|
+
- lib/advanced_hash_keys.rb
|
86
|
+
- lib/advanced_hash_keys/core_ext/hash.rb
|
87
|
+
- lib/advanced_hash_keys/core_ext/hash_with_indifferent_access.rb
|
88
|
+
- lib/advanced_hash_keys/version.rb
|
89
|
+
- spec/advanded_hash_keys_spec.rb
|
90
|
+
homepage: http://github.com/u-ichi/advanced_hash_keys
|
91
|
+
licenses: []
|
92
|
+
metadata: {}
|
93
|
+
post_install_message:
|
94
|
+
rdoc_options: []
|
95
|
+
require_paths:
|
96
|
+
- lib
|
97
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
98
|
+
requirements:
|
99
|
+
- - ">="
|
100
|
+
- !ruby/object:Gem::Version
|
101
|
+
version: '0'
|
102
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
103
|
+
requirements:
|
104
|
+
- - ">="
|
105
|
+
- !ruby/object:Gem::Version
|
106
|
+
version: '0'
|
107
|
+
requirements: []
|
108
|
+
rubyforge_project:
|
109
|
+
rubygems_version: 2.2.2
|
110
|
+
signing_key:
|
111
|
+
specification_version: 4
|
112
|
+
summary: Extends ActiveSupport's symbolize_keys to recursively symbolize / stringifier
|
113
|
+
all keys in a gem. By default, it is fully backwards compatible with ActiveSupport's
|
114
|
+
symbolize_keys/stringfier_keys method. If the recursive flag is set to true however
|
115
|
+
and it recursively symbolizes any values which are hashes.
|
116
|
+
test_files:
|
117
|
+
- spec/advanded_hash_keys_spec.rb
|