tonsser_hash_utils 1.0.4 → 1.0.5
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +5 -5
- data/bin/rspec +17 -0
- data/lib/hash_with_quick_access.rb +19 -7
- data/lib/tonsser_hash_utils/version.rb +1 -1
- data/spec/lib/hash_with_quick_access_spec.rb +16 -0
- data/tonsser_hash_utils.gemspec +3 -3
- metadata +12 -10
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
|
-
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
2
|
+
SHA256:
|
3
|
+
metadata.gz: 8cb49e652eda07aca3dcc8fb15a6837951e2c397bbd11344ca30e9b6d43a70b3
|
4
|
+
data.tar.gz: bc0db979b26c1aca79c2fb20fe0c8fc2a976f8d4e80d7e62a2bebe6db5310f61
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 906daf636af381752b35ca788b2d74732a7194387520db33e3dbed341845a82226843261138b965b3d9eea45ecf482431525d8081b877971fc824ad536f5fd3a
|
7
|
+
data.tar.gz: 732fad0ba14711ba4c56980b09632db9844d3de4c3e9c57ec41e6efe0b7780a13c3b4e368662c8ca7b9b51cd7b7fb7601157902d62470ce96fff0254559d3610
|
data/bin/rspec
ADDED
@@ -0,0 +1,17 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
# frozen_string_literal: true
|
3
|
+
#
|
4
|
+
# This file was generated by Bundler.
|
5
|
+
#
|
6
|
+
# The application 'rspec' is installed as part of a gem, and
|
7
|
+
# this file is here to facilitate running it.
|
8
|
+
#
|
9
|
+
|
10
|
+
require "pathname"
|
11
|
+
ENV["BUNDLE_GEMFILE"] ||= File.expand_path("../../Gemfile",
|
12
|
+
Pathname.new(__FILE__).realpath)
|
13
|
+
|
14
|
+
require "rubygems"
|
15
|
+
require "bundler/setup"
|
16
|
+
|
17
|
+
load Gem.bin_path("rspec-core", "rspec")
|
@@ -1,16 +1,22 @@
|
|
1
1
|
class HashWithQuickAccess
|
2
|
+
def self.add_convenience_method_to_hash!
|
3
|
+
Hash.send(:include, ConvenienceMethod)
|
4
|
+
end
|
5
|
+
|
2
6
|
def initialize(hash)
|
3
7
|
@hash = hash
|
4
8
|
end
|
5
9
|
|
6
10
|
def method_missing(key, *args, &block)
|
7
|
-
if key?(key)
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
|
11
|
+
value = if key?(key)
|
12
|
+
fetch_possibly_decorated_value(key)
|
13
|
+
elsif hash.respond_to?(key)
|
14
|
+
delegate_and_decorate(key, *args, &block)
|
15
|
+
else
|
16
|
+
fail KeyError, "key :#{key} was not found"
|
17
|
+
end
|
18
|
+
define_singleton_method(key) { value }
|
19
|
+
value
|
14
20
|
end
|
15
21
|
|
16
22
|
def respond_to?(method_name, include_private = false)
|
@@ -68,4 +74,10 @@ class HashWithQuickAccess
|
|
68
74
|
[key, key.to_sym]
|
69
75
|
end
|
70
76
|
end
|
77
|
+
|
78
|
+
module ConvenienceMethod
|
79
|
+
def with_quick_access
|
80
|
+
HashWithQuickAccess.new(self)
|
81
|
+
end
|
82
|
+
end
|
71
83
|
end
|
@@ -76,4 +76,20 @@ describe HashWithQuickAccess do
|
|
76
76
|
|
77
77
|
expect(derived_hash.new).to eq 1337
|
78
78
|
end
|
79
|
+
|
80
|
+
it "adds accessed keys as instance methods" do
|
81
|
+
hash = HashWithQuickAccess.new(a: 1)
|
82
|
+
|
83
|
+
hash.a
|
84
|
+
|
85
|
+
expect(hash.methods - Object.new.methods).to include :a
|
86
|
+
end
|
87
|
+
|
88
|
+
it "can monkey patch Hash with a convenience method" do
|
89
|
+
HashWithQuickAccess.add_convenience_method_to_hash!
|
90
|
+
|
91
|
+
hash = { a: 1 }.with_quick_access
|
92
|
+
|
93
|
+
expect(hash.a).to eq 1
|
94
|
+
end
|
79
95
|
end
|
data/tonsser_hash_utils.gemspec
CHANGED
@@ -18,9 +18,9 @@ Gem::Specification.new do |spec|
|
|
18
18
|
spec.test_files = spec.files.grep(/^(test|spec|features)/)
|
19
19
|
spec.require_paths = ["lib"]
|
20
20
|
|
21
|
-
spec.add_development_dependency "bundler", "
|
22
|
-
spec.add_development_dependency "rake", "
|
23
|
-
spec.add_development_dependency "rspec", "
|
21
|
+
spec.add_development_dependency "bundler", ">= 1.7"
|
22
|
+
spec.add_development_dependency "rake", ">= 10.0"
|
23
|
+
spec.add_development_dependency "rspec", ">= 3.2.0"
|
24
24
|
|
25
25
|
spec.add_runtime_dependency "activesupport", ">= 4.0"
|
26
26
|
end
|
metadata
CHANGED
@@ -1,55 +1,55 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: tonsser_hash_utils
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 1.0.
|
4
|
+
version: 1.0.5
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- David Pedersen
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date:
|
11
|
+
date: 2018-07-02 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: bundler
|
15
15
|
requirement: !ruby/object:Gem::Requirement
|
16
16
|
requirements:
|
17
|
-
- - "
|
17
|
+
- - ">="
|
18
18
|
- !ruby/object:Gem::Version
|
19
19
|
version: '1.7'
|
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
26
|
version: '1.7'
|
27
27
|
- !ruby/object:Gem::Dependency
|
28
28
|
name: rake
|
29
29
|
requirement: !ruby/object:Gem::Requirement
|
30
30
|
requirements:
|
31
|
-
- - "
|
31
|
+
- - ">="
|
32
32
|
- !ruby/object:Gem::Version
|
33
33
|
version: '10.0'
|
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
40
|
version: '10.0'
|
41
41
|
- !ruby/object:Gem::Dependency
|
42
42
|
name: rspec
|
43
43
|
requirement: !ruby/object:Gem::Requirement
|
44
44
|
requirements:
|
45
|
-
- - "
|
45
|
+
- - ">="
|
46
46
|
- !ruby/object:Gem::Version
|
47
47
|
version: 3.2.0
|
48
48
|
type: :development
|
49
49
|
prerelease: false
|
50
50
|
version_requirements: !ruby/object:Gem::Requirement
|
51
51
|
requirements:
|
52
|
-
- - "
|
52
|
+
- - ">="
|
53
53
|
- !ruby/object:Gem::Version
|
54
54
|
version: 3.2.0
|
55
55
|
- !ruby/object:Gem::Dependency
|
@@ -69,7 +69,8 @@ dependencies:
|
|
69
69
|
description: ''
|
70
70
|
email:
|
71
71
|
- david@tonsser.com
|
72
|
-
executables:
|
72
|
+
executables:
|
73
|
+
- rspec
|
73
74
|
extensions: []
|
74
75
|
extra_rdoc_files: []
|
75
76
|
files:
|
@@ -80,6 +81,7 @@ files:
|
|
80
81
|
- LICENSE.txt
|
81
82
|
- README.md
|
82
83
|
- Rakefile
|
84
|
+
- bin/rspec
|
83
85
|
- lib/deep_hash.rb
|
84
86
|
- lib/hash_builder.rb
|
85
87
|
- lib/hash_merger.rb
|
@@ -112,7 +114,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
112
114
|
version: '0'
|
113
115
|
requirements: []
|
114
116
|
rubyforge_project:
|
115
|
-
rubygems_version: 2.
|
117
|
+
rubygems_version: 2.7.3
|
116
118
|
signing_key:
|
117
119
|
specification_version: 4
|
118
120
|
summary: A collection of classes for dealing with hashes
|