collapsium 0.5.0 → 0.5.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
2
  SHA1:
3
- metadata.gz: c4eb75d59a4fd999a789ee4fb811263dea86b493
4
- data.tar.gz: 15a3e7ff204d3268112e41a565d6d441d60db873
3
+ metadata.gz: a5f69b509b0b797408a7a7b49f205cf1664d9931
4
+ data.tar.gz: c8cddb20e60be62dcf7522ef8008e9d02a4c256b
5
5
  SHA512:
6
- metadata.gz: 31d5e290424e9e75eda116508351e2ae7ff3873ba977257140bf1112532278f4eae00590e9974b351d84afa89b1e1943d7ed4b4f74705c2ae54d6538b948b71f
7
- data.tar.gz: 395b15971c754dea2eea60d7ebd601691f02214e7eeb97fa25281626b84cdaf6b4ecbb40585ebbfd8daa3914aa770f28856c81de8d7543a3e43ce15b8d4bc5a2
6
+ metadata.gz: 5586fb4097ab338d3a2d2d4a55d3ae2bd91eebea7d2a02acbe49500c45da8b735922ea989b2f9fbaa4d0134d26308d4ead461a40b86fec99d1c901c81690bf95
7
+ data.tar.gz: f57e9dd8df1ee2013db148d3acc86a462d10701dbaf72276997ef3e2a10724c51cd663696745d604cf66069684318d7507e3987235ddb48fe476eb5f762dcf81
data/Gemfile.lock CHANGED
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- collapsium (0.5.0)
4
+ collapsium (0.5.1)
5
5
 
6
6
  GEM
7
7
  remote: https://rubygems.org/
@@ -30,7 +30,7 @@ GEM
30
30
  diff-lcs (>= 1.2.0, < 2.0)
31
31
  rspec-support (~> 3.5.0)
32
32
  rspec-support (3.5.0)
33
- rubocop (0.44.1)
33
+ rubocop (0.45.0)
34
34
  parser (>= 2.3.1.1, < 3.0)
35
35
  powerpack (~> 0.1)
36
36
  rainbow (>= 1.99.1, < 3.0)
@@ -54,7 +54,7 @@ DEPENDENCIES
54
54
  collapsium!
55
55
  rake (~> 11.3)
56
56
  rspec (~> 3.5)
57
- rubocop (~> 0.44)
57
+ rubocop (~> 0.45)
58
58
  simplecov (~> 0.12)
59
59
  yard (~> 0.9)
60
60
 
data/README.md CHANGED
@@ -1,5 +1,5 @@
1
1
  # collapsium
2
- *Provides various Hash extensions, and an UberHash class that uses them all.*
2
+ *Provides various Hash and Array extensions, and an UberHash class that uses them all.*
3
3
 
4
4
  Ruby's Hash is a pretty nice class, but various extensions are commonly (or not
5
5
  so commonly) used to make it even more convenient. The most notable would
@@ -37,6 +37,10 @@ that is ActiveSupport...
37
37
  # },
38
38
  # }
39
39
  ```
40
+ - The `RecursiveDup` module provides a `#recursive_dup` function which `#dup`s
41
+ recursively.
42
+ - The `RecursiveSort` module provides a `#recursive_sort` function which sorts
43
+ recursively.
40
44
  - The `PathedAccess` module provides a pathed access method to nested Hashes:
41
45
 
42
46
  ```ruby
@@ -44,5 +48,43 @@ that is ActiveSupport...
44
48
  x.extend(::Collapsium::PathedAccess)
45
49
  x["foo.bar"] # => 42
46
50
  ```
51
+ - The `PrototypeMatch` module provides the ability to match nested structures
52
+ by prototype:
53
+
54
+ ```ruby
55
+ x = { "foo" => { "bar" => 42 } }
56
+ x.extend(::Collapsium::PrototypeMatch)
57
+ x.prototype_match("foo" => { "bar" => nil }}) # => true
58
+ ```
59
+
60
+ Prototypes can include values, in which case they need to match. Or they can
61
+ contain nil, in which case any value will match, but the associated key must
62
+ still exist in the receiver.
63
+ - Finally, the `ViralCapabilities` module is included in many of the above,
64
+ and ensures that nested structures retain the capabilites of their parents:
65
+
66
+ ```ruby
67
+ x = { "foo" => { "bar" => 42 } }
68
+ x.extend(::Collapsium::PathedAccess)
69
+ x.path_prefix # => "." (part of PathedAccess)
70
+ x["foo"].path_prefix # => ".foo" (virally inherited)
71
+ ```
47
72
 
48
73
  Finally, the `UberHash` class just includes all of the above.
74
+
75
+ - The `EnvironmentOverride` method allows you to override keys in a nested
76
+ structure with environment variables:
77
+
78
+ ```ruby
79
+ x = ::Collapsium::UberHash.new
80
+ x.extend(::Collapsium::EnvironmentOverride)
81
+
82
+ x["foo.bar"] = 42
83
+ ENV["FOO_BAR"] = "override"
84
+ x["foo.bar"] # => "override"
85
+ ```
86
+
87
+ Note that `EnvironmentOverride` is not included in `UberHash` by default.
88
+ It just messes with the predictability of the class too much. However, the
89
+ [collapsium-config](https://github.com/jfinkhaeuser/collapsium-config) gem
90
+ uses it extensively to provide easy overrides for configuration values.
data/collapsium.gemspec CHANGED
@@ -35,7 +35,7 @@ Gem::Specification.new do |spec|
35
35
  spec.required_ruby_version = '>= 2.0'
36
36
 
37
37
  spec.add_development_dependency "bundler", "~> 1.12"
38
- spec.add_development_dependency "rubocop", "~> 0.44"
38
+ spec.add_development_dependency "rubocop", "~> 0.45"
39
39
  spec.add_development_dependency "rake", "~> 11.3"
40
40
  spec.add_development_dependency "rspec", "~> 3.5"
41
41
  spec.add_development_dependency "simplecov", "~> 0.12"
@@ -8,5 +8,5 @@
8
8
  #
9
9
  module Collapsium
10
10
  # The current release version
11
- VERSION = "0.5.0".freeze
11
+ VERSION = "0.5.1".freeze
12
12
  end
@@ -270,6 +270,9 @@ module Collapsium
270
270
  # rubocop:disable Lint/HandleExceptions
271
271
  begin
272
272
  klass = receiver.send(getter)
273
+ if klass.nil? or klass == NilClass
274
+ next
275
+ end
273
276
  if klass != default
274
277
  return klass
275
278
  end
@@ -80,6 +80,12 @@ module ViralityModule
80
80
  end
81
81
  end
82
82
 
83
+ class RespondsToHashAncestor < Hash
84
+ def hash_ancestor
85
+ return nil
86
+ end
87
+ end
88
+
83
89
  describe ::Collapsium::ViralCapabilities do
84
90
  context PrependedHash do
85
91
  let(:tester) do
@@ -272,4 +278,11 @@ describe ::Collapsium::ViralCapabilities do
272
278
  expect(tester[:bar][:bar].object_id).to eql innermost.object_id
273
279
  end
274
280
  end
281
+
282
+ context RespondsToHashAncestor do
283
+ it "can still be used virally" do
284
+ tester = PrependedHash.new
285
+ expect { tester.merge(RespondsToHashAncestor.new) }.not_to raise_error
286
+ end
287
+ end
275
288
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: collapsium
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.5.0
4
+ version: 0.5.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Jens Finkhaeuser
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2016-10-27 00:00:00.000000000 Z
11
+ date: 2016-11-02 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler
@@ -30,14 +30,14 @@ dependencies:
30
30
  requirements:
31
31
  - - "~>"
32
32
  - !ruby/object:Gem::Version
33
- version: '0.44'
33
+ version: '0.45'
34
34
  type: :development
35
35
  prerelease: false
36
36
  version_requirements: !ruby/object:Gem::Requirement
37
37
  requirements:
38
38
  - - "~>"
39
39
  - !ruby/object:Gem::Version
40
- version: '0.44'
40
+ version: '0.45'
41
41
  - !ruby/object:Gem::Dependency
42
42
  name: rake
43
43
  requirement: !ruby/object:Gem::Requirement