hash-tweaks 1.0.0 → 1.0.1
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 +5 -5
- data/.travis.yml +1 -1
- data/Gemfile +5 -1
- data/Gemfile.lock +12 -11
- data/LICENSE +21 -0
- data/README.md +9 -5
- data/Rakefile +3 -3
- data/hash-tweaks.gemspec +13 -19
- data/lib/hash-tweaks.rb +33 -3
- data/test/helper.rb +7 -0
- data/test/test-hash-tweaks.rb +41 -6
- metadata +8 -34
- data/lib/hash-tweaks/version.rb +0 -6
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
|
-
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
2
|
+
SHA256:
|
3
|
+
metadata.gz: 7fd091e5ffbe1efac9107418db41c21fc3230799659de5c0c3d3ef7c4b4dad36
|
4
|
+
data.tar.gz: cbc658e257278e31ed90d4b71f375da4b66555ff013e7ec6302aa4d67058fdad
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: f055ad691c38da558f1e52250898de33914d98559280d541c58331d5a74d68856fbf9d91fc8484b222f804006628f74af527e33d7411e82ab90c49e55dd52f8f
|
7
|
+
data.tar.gz: 165dc3ba771d625edd2db92b5d0a385e6371c69b96f091a3160bf360df5061bf3dc27bf0436f5be21e9c2d0554185f5ef1750bc0c1fd3adb3f2153cf43c9d881
|
data/.travis.yml
CHANGED
data/Gemfile
CHANGED
data/Gemfile.lock
CHANGED
@@ -1,26 +1,27 @@
|
|
1
1
|
PATH
|
2
2
|
remote: .
|
3
3
|
specs:
|
4
|
-
hash-tweaks (1.0.
|
4
|
+
hash-tweaks (1.0.1)
|
5
5
|
activesupport (>= 3.0, < 6.0)
|
6
6
|
|
7
7
|
GEM
|
8
8
|
remote: https://rubygems.org/
|
9
9
|
specs:
|
10
|
-
activesupport (5.
|
10
|
+
activesupport (5.2.1)
|
11
11
|
concurrent-ruby (~> 1.0, >= 1.0.2)
|
12
|
-
i18n (
|
12
|
+
i18n (>= 0.7, < 2)
|
13
13
|
minitest (~> 5.1)
|
14
14
|
tzinfo (~> 1.1)
|
15
15
|
concurrent-ruby (1.0.5)
|
16
|
-
i18n (
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
|
16
|
+
i18n (1.1.0)
|
17
|
+
concurrent-ruby (~> 1.0)
|
18
|
+
minitest (5.11.3)
|
19
|
+
power_assert (1.1.3)
|
20
|
+
rake (12.3.1)
|
21
|
+
test-unit (3.2.8)
|
21
22
|
power_assert
|
22
23
|
thread_safe (0.3.6)
|
23
|
-
tzinfo (1.2.
|
24
|
+
tzinfo (1.2.5)
|
24
25
|
thread_safe (~> 0.1)
|
25
26
|
|
26
27
|
PLATFORMS
|
@@ -29,8 +30,8 @@ PLATFORMS
|
|
29
30
|
DEPENDENCIES
|
30
31
|
bundler (~> 1.7)
|
31
32
|
hash-tweaks!
|
32
|
-
rake (~> 12.
|
33
|
+
rake (~> 12.3)
|
33
34
|
test-unit (~> 3.2)
|
34
35
|
|
35
36
|
BUNDLED WITH
|
36
|
-
1.
|
37
|
+
1.16.5
|
data/LICENSE
ADDED
@@ -0,0 +1,21 @@
|
|
1
|
+
The MIT License (MIT)
|
2
|
+
|
3
|
+
Copyright (c) 2018 Yaroslav Konoplov
|
4
|
+
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
7
|
+
in the Software without restriction, including without limitation the rights
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
10
|
+
furnished to do so, subject to the following conditions:
|
11
|
+
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
13
|
+
copies or substantial portions of the Software.
|
14
|
+
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
21
|
+
SOFTWARE.
|
data/README.md
CHANGED
@@ -1,21 +1,25 @@
|
|
1
|
-
##
|
1
|
+
## A gem extending Ruby's hash with useful utilities.
|
2
2
|
|
3
3
|
[](https://badge.fury.io/rb/hash-tweaks)
|
4
4
|
[](https://travis-ci.org/yivo/hash-tweaks)
|
5
5
|
|
6
6
|
## Current features
|
7
|
-
* `camelize`
|
8
|
-
* `camelize!`
|
7
|
+
* `Hash#camelize`
|
8
|
+
* `Hash#camelize!`
|
9
|
+
* `Hash#deep_with_indifferent_access`
|
10
|
+
* `Array#deep_with_indifferent_access`
|
11
|
+
* `Array#deep_symbolize_keys`
|
12
|
+
* `Array#deep_stringify_keys`
|
9
13
|
|
10
14
|
## Installing gem
|
11
15
|
Add to your Gemfile:
|
12
16
|
```ruby
|
13
|
-
gem
|
17
|
+
gem "hash-tweaks", "~> 1.0"
|
14
18
|
```
|
15
19
|
|
16
20
|
If you are using Ruby < 2.4 please add:
|
17
21
|
```ruby
|
18
|
-
gem
|
22
|
+
gem "regexp-match-polyfill", "~> 1.0"
|
19
23
|
```
|
20
24
|
|
21
25
|
## Running tests
|
data/Rakefile
CHANGED
data/hash-tweaks.gemspec
CHANGED
@@ -1,24 +1,18 @@
|
|
1
1
|
# encoding: UTF-8
|
2
2
|
# frozen_string_literal: true
|
3
3
|
|
4
|
-
require File.expand_path('../lib/hash-tweaks/version', __FILE__)
|
5
|
-
|
6
4
|
Gem::Specification.new do |s|
|
7
|
-
s.name
|
8
|
-
s.version
|
9
|
-
s.author
|
10
|
-
s.email
|
11
|
-
s.summary
|
12
|
-
s.description
|
13
|
-
s.homepage
|
14
|
-
s.license
|
15
|
-
|
16
|
-
s.
|
17
|
-
s.
|
18
|
-
s.
|
19
|
-
|
20
|
-
s.add_dependency 'activesupport', '>= 3.0', '< 6.0'
|
21
|
-
s.add_development_dependency 'bundler', '~> 1.7'
|
22
|
-
s.add_development_dependency 'rake', '~> 12.0'
|
23
|
-
s.add_development_dependency 'test-unit', '~> 3.2'
|
5
|
+
s.name = "hash-tweaks"
|
6
|
+
s.version = "1.0.1"
|
7
|
+
s.author = "Yaroslav Konoplov"
|
8
|
+
s.email = "eahome00@gmail.com"
|
9
|
+
s.summary = "Utilities for Ruby's hash."
|
10
|
+
s.description = "A gem extending Ruby's hash with useful utilities."
|
11
|
+
s.homepage = "https://github.com/yivo/hash-tweaks"
|
12
|
+
s.license = "MIT"
|
13
|
+
s.files = `git ls-files -z`.split("\x0")
|
14
|
+
s.test_files = `git ls-files -z -- {test,spec,features}/*`.split("\x0")
|
15
|
+
s.require_paths = ["lib"]
|
16
|
+
s.add_dependency "activesupport", ">= 3.0", "< 6.0"
|
17
|
+
s.add_development_dependency "bundler", "~> 1.7"
|
24
18
|
end
|
data/lib/hash-tweaks.rb
CHANGED
@@ -3,13 +3,17 @@
|
|
3
3
|
|
4
4
|
require 'regexp-match-polyfill' if RUBY_VERSION < '2.4'
|
5
5
|
require 'active_support/core_ext/string/inflections'
|
6
|
+
require 'active_support/core_ext/hash/keys'
|
7
|
+
require 'active_support/core_ext/hash/indifferent_access'
|
6
8
|
|
7
|
-
|
8
|
-
|
9
|
+
class Hash
|
10
|
+
unless method_defined?(:camelize)
|
9
11
|
def camelize(first_letter = :upper)
|
10
12
|
dup.camelize!(first_letter)
|
11
13
|
end
|
14
|
+
end
|
12
15
|
|
16
|
+
unless method_defined?(:camelize!)
|
13
17
|
def camelize!(first_letter = :upper)
|
14
18
|
keys.each do |key|
|
15
19
|
# Check if key is symbol or string and if it is not CONSTANT_VARIABLE.
|
@@ -21,6 +25,32 @@ module HashTweaks
|
|
21
25
|
self
|
22
26
|
end
|
23
27
|
end
|
28
|
+
|
29
|
+
unless method_defined?(:deep_with_indifferent_access)
|
30
|
+
def deep_with_indifferent_access
|
31
|
+
each_with_object({}) do |(k, v), m|
|
32
|
+
m[k] = v.respond_to?(:deep_with_indifferent_access) ? v.deep_with_indifferent_access : v
|
33
|
+
end.with_indifferent_access
|
34
|
+
end
|
35
|
+
end
|
24
36
|
end
|
25
37
|
|
26
|
-
|
38
|
+
class Array
|
39
|
+
unless method_defined?(:deep_with_indifferent_access)
|
40
|
+
def deep_with_indifferent_access
|
41
|
+
map { |item| item.respond_to?(:deep_with_indifferent_access) ? item.deep_with_indifferent_access : item }
|
42
|
+
end
|
43
|
+
end
|
44
|
+
|
45
|
+
unless method_defined?(:deep_symbolize_keys)
|
46
|
+
def deep_symbolize_keys
|
47
|
+
map { |item| item.respond_to?(:deep_symbolize_keys) ? item.deep_symbolize_keys : item }
|
48
|
+
end
|
49
|
+
end
|
50
|
+
|
51
|
+
unless method_defined?(:deep_stringify_keys)
|
52
|
+
def deep_stringify_keys
|
53
|
+
map { |item| item.respond_to?(:deep_stringify_keys) ? item.deep_stringify_keys : item }
|
54
|
+
end
|
55
|
+
end
|
56
|
+
end
|
data/test/helper.rb
ADDED
data/test/test-hash-tweaks.rb
CHANGED
@@ -1,13 +1,48 @@
|
|
1
1
|
# encoding: UTF-8
|
2
2
|
# frozen_string_literal: true
|
3
3
|
|
4
|
-
|
5
|
-
Bundler.require :default, :development, :test
|
4
|
+
require_relative "helper"
|
6
5
|
|
7
6
|
class HashTweaksTest < Test::Unit::TestCase
|
8
|
-
|
9
|
-
assert_equal({fooBarBaz:
|
10
|
-
assert_equal({FooBarBaz:
|
11
|
-
assert_equal({FOO_BAZ_BAZ:
|
7
|
+
test "Hash#camelize" do
|
8
|
+
assert_equal({ fooBarBaz: "qux" }, { foo_bar_baz: "qux" }.camelize(:lower))
|
9
|
+
assert_equal({ FooBarBaz: "qux" }, { foo_bar_baz: "qux" }.camelize(:upper))
|
10
|
+
assert_equal({ FOO_BAZ_BAZ: "qux" }, { FOO_BAZ_BAZ: "qux" }.camelize(:upper))
|
11
|
+
end
|
12
|
+
|
13
|
+
test "Hash#camelize!" do
|
14
|
+
hash = { foo_bar_baz: "qux" }
|
15
|
+
hash.camelize!
|
16
|
+
assert_equal [:FooBarBaz], hash.keys
|
17
|
+
end
|
18
|
+
|
19
|
+
test "Hash#deep_with_indifferent_access" do
|
20
|
+
hash_1 = { a: { "b" => { c: "d" } } }
|
21
|
+
hash_2 = hash_1.deep_with_indifferent_access
|
22
|
+
assert_equal JSON.generate(hash_1[:a]), JSON.generate(hash_2["a"])
|
23
|
+
assert_equal JSON.generate(hash_1[:a]), JSON.generate(hash_2[:a])
|
24
|
+
assert_equal JSON.generate(hash_1[:a]["b"]), JSON.generate(hash_2["a"]["b"])
|
25
|
+
assert_equal JSON.generate(hash_1[:a]["b"]), JSON.generate(hash_2["a"][:b])
|
26
|
+
assert_equal JSON.generate(hash_1[:a]["b"][:c]), JSON.generate(hash_2["a"][:b][:c])
|
27
|
+
assert_equal JSON.generate(hash_1[:a]["b"][:c]), JSON.generate(hash_2["a"][:b]["c"])
|
28
|
+
end
|
29
|
+
|
30
|
+
test "Array#deep_with_indifferent_access" do
|
31
|
+
array = [:foo, "baz", { a: { "b" => :c } }].deep_with_indifferent_access
|
32
|
+
assert_equal :foo, array[0]
|
33
|
+
assert_equal "baz", array[1]
|
34
|
+
assert_equal JSON.generate(a: { b: :c }), JSON.generate(array[2])
|
35
|
+
assert_equal JSON.generate(b: :c), JSON.generate(array[2][:a])
|
36
|
+
assert_equal JSON.generate(b: :c), JSON.generate(array[2]["a"])
|
37
|
+
assert_equal :c, array[2][:a]["b"]
|
38
|
+
assert_equal :c, array[2]["a"][:b]
|
39
|
+
end
|
40
|
+
|
41
|
+
test "Array#deep_symbolize_keys" do
|
42
|
+
assert_equal([{ foo: "bar" }, "baz", :baz], [{ "foo" => "bar" }, "baz", :baz].deep_symbolize_keys)
|
43
|
+
end
|
44
|
+
|
45
|
+
test "Array#deep_stringify_keys" do
|
46
|
+
assert_equal([{ "foo" => :bar }, "baz", :baz], [{ foo: :bar }, "baz", :baz].deep_stringify_keys)
|
12
47
|
end
|
13
48
|
end
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: hash-tweaks
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 1.0.
|
4
|
+
version: 1.0.1
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Yaroslav Konoplov
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date:
|
11
|
+
date: 2018-10-09 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: activesupport
|
@@ -44,35 +44,7 @@ dependencies:
|
|
44
44
|
- - "~>"
|
45
45
|
- !ruby/object:Gem::Version
|
46
46
|
version: '1.7'
|
47
|
-
|
48
|
-
name: rake
|
49
|
-
requirement: !ruby/object:Gem::Requirement
|
50
|
-
requirements:
|
51
|
-
- - "~>"
|
52
|
-
- !ruby/object:Gem::Version
|
53
|
-
version: '12.0'
|
54
|
-
type: :development
|
55
|
-
prerelease: false
|
56
|
-
version_requirements: !ruby/object:Gem::Requirement
|
57
|
-
requirements:
|
58
|
-
- - "~>"
|
59
|
-
- !ruby/object:Gem::Version
|
60
|
-
version: '12.0'
|
61
|
-
- !ruby/object:Gem::Dependency
|
62
|
-
name: test-unit
|
63
|
-
requirement: !ruby/object:Gem::Requirement
|
64
|
-
requirements:
|
65
|
-
- - "~>"
|
66
|
-
- !ruby/object:Gem::Version
|
67
|
-
version: '3.2'
|
68
|
-
type: :development
|
69
|
-
prerelease: false
|
70
|
-
version_requirements: !ruby/object:Gem::Requirement
|
71
|
-
requirements:
|
72
|
-
- - "~>"
|
73
|
-
- !ruby/object:Gem::Version
|
74
|
-
version: '3.2'
|
75
|
-
description: Responsibly extends Ruby's Hash with simple and predictable utilities.
|
47
|
+
description: A gem extending Ruby's hash with useful utilities.
|
76
48
|
email: eahome00@gmail.com
|
77
49
|
executables: []
|
78
50
|
extensions: []
|
@@ -82,11 +54,12 @@ files:
|
|
82
54
|
- ".travis.yml"
|
83
55
|
- Gemfile
|
84
56
|
- Gemfile.lock
|
57
|
+
- LICENSE
|
85
58
|
- README.md
|
86
59
|
- Rakefile
|
87
60
|
- hash-tweaks.gemspec
|
88
61
|
- lib/hash-tweaks.rb
|
89
|
-
-
|
62
|
+
- test/helper.rb
|
90
63
|
- test/test-hash-tweaks.rb
|
91
64
|
homepage: https://github.com/yivo/hash-tweaks
|
92
65
|
licenses:
|
@@ -108,9 +81,10 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
108
81
|
version: '0'
|
109
82
|
requirements: []
|
110
83
|
rubyforge_project:
|
111
|
-
rubygems_version: 2.6
|
84
|
+
rubygems_version: 2.7.6
|
112
85
|
signing_key:
|
113
86
|
specification_version: 4
|
114
|
-
summary:
|
87
|
+
summary: Utilities for Ruby's hash.
|
115
88
|
test_files:
|
89
|
+
- test/helper.rb
|
116
90
|
- test/test-hash-tweaks.rb
|