hash_ext 0.2.3 → 0.6.0

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: eba87bb627d260913baffdb6da736ed155ccef99
4
- data.tar.gz: f44ace55737bf6249643940f8fea149bc176c7be
2
+ SHA256:
3
+ metadata.gz: 97edf774c7ae90b8d8dd27030b1df0b025186e35028c7e5933a1ebf4e63f0c1c
4
+ data.tar.gz: 1a5ba2d621c3eb1d786f7870130274f2b1d522cab2e1bd61ced2a75f2dbaf904
5
5
  SHA512:
6
- metadata.gz: 6071d9756d9ca39ba7bcd151b32e357fdc454c010de8938c6680ce17cbace13386095b1cc6a7a813270dd0cc14c318af617fa1fb7d18e5a7d0aa67ed90cb03c4
7
- data.tar.gz: 773ca805d092b144470489a2cd931cc515b5efa79c2b83afe345658171009da156056ae174ad33abdfb3d4c769650dc3aeb3e1bf8996f6cb49447d34870b90d1
6
+ metadata.gz: 40d2e0967ecc8a5c73efe22bc29bdf5184e411adc189f555d182d46a31639556802be0daa7f67a239110e55558583fa4598d3bb75f3846b36381578a671018a2
7
+ data.tar.gz: 5ff8c56fa6e3729927714f7713bf88540ed718ac1cd0c2814e220ce7b8c815738cd89e33c81281fd726d23a5e5c492d8798ab5230dd002d122bd7e4f259ab242
@@ -1 +1 @@
1
- ruby-2.3.0
1
+ ruby-2.5.0
@@ -1,10 +1,21 @@
1
1
  language: ruby
2
+
2
3
  rvm:
3
4
  - 1.9.3
4
5
  - 2.0
5
6
  - 2.1
6
7
  - 2.2
7
- - 2.3.0
8
- - jruby
9
- before_install:
10
- - gem install bundler
8
+ - 2.3
9
+ - 2.4
10
+ - 2.5
11
+ - 2.6
12
+ - 2.7
13
+ - jruby-9.2.9.0
14
+ - ruby-head
15
+ - jruby-head
16
+
17
+ matrix:
18
+ fast_finish: true
19
+ allow_failures:
20
+ - rvm: ruby-head
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/Rakefile CHANGED
@@ -3,9 +3,15 @@ require 'rake/testtask'
3
3
 
4
4
  Rake::TestTask.new(:spec) do |t|
5
5
  t.libs << 'spec'
6
- t.pattern = 'spec/**/*_spec.rb'
6
+ t.libs << 'lib'
7
+ t.pattern = ENV['DIR'] ? File.join(ENV['DIR'], '**', '*_spec.rb') : 'spec/**/*_spec.rb'
7
8
  t.verbose = false
8
9
  t.warning = false
10
+ t.loader = nil if ENV['TEST']
11
+ ENV['TEST'], ENV['LINE'] = ENV['TEST'].split(':') if ENV['TEST'] && !ENV['LINE']
12
+ t.options = ''
13
+ t.options << "--name=/#{ENV['NAME']}/ " if ENV['NAME']
14
+ t.options << "-l #{ENV['LINE']} " if ENV['LINE'] && ENV['TEST']
9
15
  end
10
16
 
11
17
  task default: :spec
@@ -19,11 +19,11 @@ 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.6'
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
- spec.add_development_dependency 'simplecov', '~> 0.12'
25
+ spec.add_development_dependency 'minitest-line', '~> 0.6'
26
+ spec.add_development_dependency 'simplecov', '~> 0.14'
27
27
  spec.add_development_dependency 'coveralls', '~> 0.8'
28
28
  spec.add_development_dependency 'pry-nav', '~> 0.2'
29
29
 
@@ -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'
@@ -5,7 +5,7 @@ class Hash
5
5
  if value.kind_of? Hash
6
6
  self.new value
7
7
  elsif value.kind_of? ::Array
8
- Array.new value
8
+ Accessible::Array.new value
9
9
  else
10
10
  value
11
11
  end
@@ -25,7 +25,7 @@ class Hash
25
25
  end
26
26
 
27
27
  def []=(key, value)
28
- super key, self.class.make_accessible(value)
28
+ super key, Accessible.make_accessible(value)
29
29
  end
30
30
 
31
31
  private
@@ -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
@@ -1,3 +1,15 @@
1
1
  class Hash
2
- Indifferent = Normalized.subclass { |key| key.kind_of?(String) ? key.to_sym : key }
2
+ class Indifferent < Normalized
3
+
4
+ def initialize(hash={})
5
+ super hash
6
+ end
7
+
8
+ private
9
+
10
+ def normalize_key(key)
11
+ key.kind_of?(String) ? key.to_sym : key
12
+ end
13
+
14
+ end
3
15
  end
@@ -0,0 +1,15 @@
1
+ class Hash
2
+ class Nested < Hash
3
+
4
+ include DeepFreezable
5
+
6
+ def [](key)
7
+ if key? key
8
+ super(key)
9
+ else
10
+ self[key] = Nested.new
11
+ end
12
+ end
13
+
14
+ end
15
+ end
@@ -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_key = keys.map { |k| normalize_key(k) }
58
+ normalized_key.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
@@ -3,6 +3,7 @@ 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?,
@@ -1,3 +1,3 @@
1
1
  module HashExt
2
- VERSION = '0.2.3'
2
+ VERSION = '0.6.0'
3
3
  end
metadata CHANGED
@@ -1,85 +1,91 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: hash_ext
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.2.3
4
+ version: 0.6.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Gabriel Naiman
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2017-01-10 00:00:00.000000000 Z
11
+ date: 2020-06-12 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
- name: bundler
14
+ name: rake
15
15
  requirement: !ruby/object:Gem::Requirement
16
16
  requirements:
17
17
  - - "~>"
18
18
  - !ruby/object:Gem::Version
19
- version: '1.6'
19
+ version: '11.0'
20
20
  type: :development
21
21
  prerelease: false
22
22
  version_requirements: !ruby/object:Gem::Requirement
23
23
  requirements:
24
24
  - - "~>"
25
25
  - !ruby/object:Gem::Version
26
- version: '1.6'
26
+ version: '11.0'
27
27
  - !ruby/object:Gem::Dependency
28
- name: rake
28
+ name: minitest
29
29
  requirement: !ruby/object:Gem::Requirement
30
30
  requirements:
31
31
  - - "~>"
32
32
  - !ruby/object:Gem::Version
33
- version: '11.0'
33
+ version: '5.0'
34
+ - - "<"
35
+ - !ruby/object:Gem::Version
36
+ version: '5.11'
34
37
  type: :development
35
38
  prerelease: false
36
39
  version_requirements: !ruby/object:Gem::Requirement
37
40
  requirements:
38
41
  - - "~>"
39
42
  - !ruby/object:Gem::Version
40
- version: '11.0'
43
+ version: '5.0'
44
+ - - "<"
45
+ - !ruby/object:Gem::Version
46
+ version: '5.11'
41
47
  - !ruby/object:Gem::Dependency
42
- name: minitest
48
+ name: minitest-colorin
43
49
  requirement: !ruby/object:Gem::Requirement
44
50
  requirements:
45
51
  - - "~>"
46
52
  - !ruby/object:Gem::Version
47
- version: '5.0'
53
+ version: '0.1'
48
54
  type: :development
49
55
  prerelease: false
50
56
  version_requirements: !ruby/object:Gem::Requirement
51
57
  requirements:
52
58
  - - "~>"
53
59
  - !ruby/object:Gem::Version
54
- version: '5.0'
60
+ version: '0.1'
55
61
  - !ruby/object:Gem::Dependency
56
- name: minitest-colorin
62
+ name: minitest-line
57
63
  requirement: !ruby/object:Gem::Requirement
58
64
  requirements:
59
65
  - - "~>"
60
66
  - !ruby/object:Gem::Version
61
- version: '0.1'
67
+ version: '0.6'
62
68
  type: :development
63
69
  prerelease: false
64
70
  version_requirements: !ruby/object:Gem::Requirement
65
71
  requirements:
66
72
  - - "~>"
67
73
  - !ruby/object:Gem::Version
68
- version: '0.1'
74
+ version: '0.6'
69
75
  - !ruby/object:Gem::Dependency
70
76
  name: simplecov
71
77
  requirement: !ruby/object:Gem::Requirement
72
78
  requirements:
73
79
  - - "~>"
74
80
  - !ruby/object:Gem::Version
75
- version: '0.12'
81
+ version: '0.14'
76
82
  type: :development
77
83
  prerelease: false
78
84
  version_requirements: !ruby/object:Gem::Requirement
79
85
  requirements:
80
86
  - - "~>"
81
87
  - !ruby/object:Gem::Version
82
- version: '0.12'
88
+ version: '0.14'
83
89
  - !ruby/object:Gem::Dependency
84
90
  name: coveralls
85
91
  requirement: !ruby/object:Gem::Requirement
@@ -128,7 +134,9 @@ files:
128
134
  - lib/hash_ext.rb
129
135
  - lib/hash_ext/accessible.rb
130
136
  - lib/hash_ext/builder.rb
137
+ - lib/hash_ext/deep_freezable.rb
131
138
  - lib/hash_ext/indifferent.rb
139
+ - lib/hash_ext/nested.rb
132
140
  - lib/hash_ext/normalized.rb
133
141
  - lib/hash_ext/sorted.rb
134
142
  - lib/hash_ext/version.rb
@@ -151,8 +159,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
151
159
  - !ruby/object:Gem::Version
152
160
  version: '0'
153
161
  requirements: []
154
- rubyforge_project:
155
- rubygems_version: 2.5.1
162
+ rubygems_version: 3.0.6
156
163
  signing_key:
157
164
  specification_version: 4
158
165
  summary: Hash extensions without monkey patching