hash_ext 0.3.0 → 0.6.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.travis.yml +7 -9
- data/README.md +8 -1
- data/hash_ext.gemspec +1 -2
- data/lib/hash_ext.rb +3 -1
- data/lib/hash_ext/builder.rb +1 -1
- data/lib/hash_ext/deep_freezable.rb +25 -0
- data/lib/hash_ext/indifferent.rb +1 -1
- data/lib/hash_ext/nested.rb +15 -0
- data/lib/hash_ext/normalized.rb +13 -2
- data/lib/hash_ext/sorted.rb +5 -4
- data/lib/hash_ext/version.rb +1 -1
- metadata +11 -18
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 99fff501a3fca91d49b7506705477c1fefcbf3c8b0ee72f7262da7857a41d00e
|
4
|
+
data.tar.gz: 495e26e293b9534a261026537848bd674873c09a77d766d19941a9d7068405c1
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 795a80a5c4bfd86e24095fd4e5231a711dcbf25a5a87cd3fc68ffc686a7aa1f7392d7b9ca5c985a8a33dd943ad02b9e082156bdba88be81b9c74855e3bba6482
|
7
|
+
data.tar.gz: 71ebaa63fbfb78e8d58cf280c5999ef84a82cc30d06753a4fc84e961cade3553f8229514777bcb0c1370dfb5c02690b3b3de758fe43c63217fbcb0d826f20169
|
data/.travis.yml
CHANGED
@@ -5,11 +5,12 @@ rvm:
|
|
5
5
|
- 2.0
|
6
6
|
- 2.1
|
7
7
|
- 2.2
|
8
|
-
- 2.3
|
9
|
-
- 2.4
|
10
|
-
- 2.5
|
11
|
-
-
|
12
|
-
-
|
8
|
+
- 2.3
|
9
|
+
- 2.4
|
10
|
+
- 2.5
|
11
|
+
- 2.6
|
12
|
+
- 2.7
|
13
|
+
- jruby-9.2.9.0
|
13
14
|
- ruby-head
|
14
15
|
- jruby-head
|
15
16
|
|
@@ -17,7 +18,4 @@ matrix:
|
|
17
18
|
fast_finish: true
|
18
19
|
allow_failures:
|
19
20
|
- rvm: ruby-head
|
20
|
-
- rvm: jruby-head
|
21
|
-
|
22
|
-
before_install:
|
23
|
-
- gem install bundler
|
21
|
+
- rvm: jruby-head
|
data/README.md
CHANGED
@@ -4,7 +4,6 @@
|
|
4
4
|
[![Build Status](https://travis-ci.org/gabynaiman/hash_ext.svg?branch=master)](https://travis-ci.org/gabynaiman/hash_ext)
|
5
5
|
[![Coverage Status](https://coveralls.io/repos/gabynaiman/hash_ext/badge.svg?branch=master)](https://coveralls.io/r/gabynaiman/hash_ext?branch=master)
|
6
6
|
[![Code Climate](https://codeclimate.com/github/gabynaiman/hash_ext.svg)](https://codeclimate.com/github/gabynaiman/hash_ext)
|
7
|
-
[![Dependency Status](https://gemnasium.com/gabynaiman/hash_ext.svg)](https://gemnasium.com/gabynaiman/hash_ext)
|
8
7
|
|
9
8
|
Hash extensions without monkey patching
|
10
9
|
|
@@ -92,6 +91,14 @@ hash[:a] = 3
|
|
92
91
|
hash.keys # => [:a, :b, :c]
|
93
92
|
```
|
94
93
|
|
94
|
+
### Nested
|
95
|
+
```ruby
|
96
|
+
hash = Hash::Nested.new
|
97
|
+
|
98
|
+
hash[:level_1][:level_2][:level_3] = 'value'
|
99
|
+
|
100
|
+
hash # => {level_1: {level_2: {level_3: 'value'}}}
|
101
|
+
```
|
95
102
|
|
96
103
|
## Contributing
|
97
104
|
|
data/hash_ext.gemspec
CHANGED
@@ -19,9 +19,8 @@ Gem::Specification.new do |spec|
|
|
19
19
|
spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
|
20
20
|
spec.require_paths = ['lib']
|
21
21
|
|
22
|
-
spec.add_development_dependency 'bundler', '~> 1.12'
|
23
22
|
spec.add_development_dependency 'rake', '~> 11.0'
|
24
|
-
spec.add_development_dependency 'minitest', '~> 5.0'
|
23
|
+
spec.add_development_dependency 'minitest', '~> 5.0', '< 5.11'
|
25
24
|
spec.add_development_dependency 'minitest-colorin', '~> 0.1'
|
26
25
|
spec.add_development_dependency 'minitest-line', '~> 0.6'
|
27
26
|
spec.add_development_dependency 'simplecov', '~> 0.14'
|
data/lib/hash_ext.rb
CHANGED
@@ -2,8 +2,10 @@ require 'forwardable'
|
|
2
2
|
|
3
3
|
require_relative 'hash_ext/version'
|
4
4
|
|
5
|
+
require_relative 'hash_ext/deep_freezable'
|
5
6
|
require_relative 'hash_ext/normalized'
|
6
7
|
require_relative 'hash_ext/builder'
|
7
8
|
require_relative 'hash_ext/indifferent'
|
8
9
|
require_relative 'hash_ext/accessible'
|
9
|
-
require_relative 'hash_ext/sorted'
|
10
|
+
require_relative 'hash_ext/sorted'
|
11
|
+
require_relative 'hash_ext/nested'
|
data/lib/hash_ext/builder.rb
CHANGED
@@ -0,0 +1,25 @@
|
|
1
|
+
class Hash
|
2
|
+
module DeepFreezable
|
3
|
+
|
4
|
+
def deep_freeze
|
5
|
+
each_value { |v| deep_freeze_value v }
|
6
|
+
freeze
|
7
|
+
end
|
8
|
+
|
9
|
+
def deep_freeze_value(value)
|
10
|
+
if value.respond_to? :deep_freeze
|
11
|
+
value.deep_freeze
|
12
|
+
else
|
13
|
+
if value.is_a? Hash
|
14
|
+
value.each_value { |v| deep_freeze_value v }
|
15
|
+
elsif value.respond_to? :each
|
16
|
+
value.each { |v| deep_freeze_value v }
|
17
|
+
end
|
18
|
+
value.freeze
|
19
|
+
end
|
20
|
+
end
|
21
|
+
|
22
|
+
private :deep_freeze_value
|
23
|
+
|
24
|
+
end
|
25
|
+
end
|
data/lib/hash_ext/indifferent.rb
CHANGED
data/lib/hash_ext/normalized.rb
CHANGED
@@ -1,6 +1,8 @@
|
|
1
1
|
class Hash
|
2
2
|
class Normalized < Hash
|
3
3
|
|
4
|
+
include DeepFreezable
|
5
|
+
|
4
6
|
def self.subclass(&block)
|
5
7
|
Class.new(self) do
|
6
8
|
define_method :initialize do |hash={}|
|
@@ -51,6 +53,13 @@ class Hash
|
|
51
53
|
super normalize_key(key), *args, &block
|
52
54
|
end
|
53
55
|
|
56
|
+
def dig(*keys)
|
57
|
+
normalized_keys = keys.map { |k| normalize_key(k) }
|
58
|
+
normalized_keys.inject(self) do |target, key|
|
59
|
+
target ? target[key] : nil
|
60
|
+
end
|
61
|
+
end
|
62
|
+
|
54
63
|
def to_h
|
55
64
|
each_with_object({}) do |(key, value), hash|
|
56
65
|
hash[key] = value_to_h value
|
@@ -64,8 +73,10 @@ class Hash
|
|
64
73
|
end
|
65
74
|
|
66
75
|
def normalize_value(value)
|
67
|
-
if value.
|
68
|
-
|
76
|
+
if value.is_a? self.class
|
77
|
+
value
|
78
|
+
elsif value.kind_of? Hash
|
79
|
+
self.class.new value, &@normalization_block
|
69
80
|
elsif value.kind_of? Array
|
70
81
|
value.map { |v| normalize_value v }
|
71
82
|
else
|
data/lib/hash_ext/sorted.rb
CHANGED
@@ -3,15 +3,16 @@ class Hash
|
|
3
3
|
|
4
4
|
extend Forwardable
|
5
5
|
include Enumerable
|
6
|
+
include DeepFreezable
|
6
7
|
|
7
8
|
def_delegators :@hash, :[], :[]=, :value?, :fetch, :values_at,
|
8
9
|
:key?, :include?, :empty?,
|
9
|
-
:delete, :delete_if, :clear,
|
10
|
+
:delete, :delete_if, :clear,
|
10
11
|
:merge, :merge!, :update, :store, :replace,
|
11
12
|
:count, :size, :length,
|
12
13
|
:==, :eql, :hash
|
13
|
-
|
14
|
-
def_delegators :to_h, :to_a, :to_s, :inspect,
|
14
|
+
|
15
|
+
def_delegators :to_h, :to_a, :to_s, :inspect,
|
15
16
|
:select, :reject, :flatten,
|
16
17
|
:as_json, :to_json
|
17
18
|
|
@@ -55,7 +56,7 @@ class Hash
|
|
55
56
|
attr_reader :direction, :sort_criteria
|
56
57
|
|
57
58
|
class << self
|
58
|
-
|
59
|
+
|
59
60
|
def ascending(hash={}, &sort_criteria)
|
60
61
|
new hash, :asc, &sort_criteria
|
61
62
|
end
|
data/lib/hash_ext/version.rb
CHANGED
metadata
CHANGED
@@ -1,29 +1,15 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: hash_ext
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.6.1
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Gabriel Naiman
|
8
8
|
autorequire:
|
9
9
|
bindir: exe
|
10
10
|
cert_chain: []
|
11
|
-
date:
|
11
|
+
date: 2020-11-04 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
|
-
- !ruby/object:Gem::Dependency
|
14
|
-
name: bundler
|
15
|
-
requirement: !ruby/object:Gem::Requirement
|
16
|
-
requirements:
|
17
|
-
- - "~>"
|
18
|
-
- !ruby/object:Gem::Version
|
19
|
-
version: '1.12'
|
20
|
-
type: :development
|
21
|
-
prerelease: false
|
22
|
-
version_requirements: !ruby/object:Gem::Requirement
|
23
|
-
requirements:
|
24
|
-
- - "~>"
|
25
|
-
- !ruby/object:Gem::Version
|
26
|
-
version: '1.12'
|
27
13
|
- !ruby/object:Gem::Dependency
|
28
14
|
name: rake
|
29
15
|
requirement: !ruby/object:Gem::Requirement
|
@@ -45,6 +31,9 @@ dependencies:
|
|
45
31
|
- - "~>"
|
46
32
|
- !ruby/object:Gem::Version
|
47
33
|
version: '5.0'
|
34
|
+
- - "<"
|
35
|
+
- !ruby/object:Gem::Version
|
36
|
+
version: '5.11'
|
48
37
|
type: :development
|
49
38
|
prerelease: false
|
50
39
|
version_requirements: !ruby/object:Gem::Requirement
|
@@ -52,6 +41,9 @@ dependencies:
|
|
52
41
|
- - "~>"
|
53
42
|
- !ruby/object:Gem::Version
|
54
43
|
version: '5.0'
|
44
|
+
- - "<"
|
45
|
+
- !ruby/object:Gem::Version
|
46
|
+
version: '5.11'
|
55
47
|
- !ruby/object:Gem::Dependency
|
56
48
|
name: minitest-colorin
|
57
49
|
requirement: !ruby/object:Gem::Requirement
|
@@ -142,7 +134,9 @@ files:
|
|
142
134
|
- lib/hash_ext.rb
|
143
135
|
- lib/hash_ext/accessible.rb
|
144
136
|
- lib/hash_ext/builder.rb
|
137
|
+
- lib/hash_ext/deep_freezable.rb
|
145
138
|
- lib/hash_ext/indifferent.rb
|
139
|
+
- lib/hash_ext/nested.rb
|
146
140
|
- lib/hash_ext/normalized.rb
|
147
141
|
- lib/hash_ext/sorted.rb
|
148
142
|
- lib/hash_ext/version.rb
|
@@ -165,8 +159,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
165
159
|
- !ruby/object:Gem::Version
|
166
160
|
version: '0'
|
167
161
|
requirements: []
|
168
|
-
|
169
|
-
rubygems_version: 2.7.3
|
162
|
+
rubygems_version: 3.0.6
|
170
163
|
signing_key:
|
171
164
|
specification_version: 4
|
172
165
|
summary: Hash extensions without monkey patching
|