tonsser_hash_utils 1.0
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 +7 -0
- data/.gitignore +14 -0
- data/.rspec +2 -0
- data/Gemfile +4 -0
- data/LICENSE.txt +22 -0
- data/README.md +31 -0
- data/Rakefile +2 -0
- data/lib/deep_hash.rb +24 -0
- data/lib/hash_builder.rb +40 -0
- data/lib/hash_merger.rb +35 -0
- data/lib/hash_with_quick_access.rb +59 -0
- data/lib/tonsser_hash_utils/version.rb +3 -0
- data/lib/tonsser_hash_utils.rb +9 -0
- data/spec/lib/deep_hash_spec.rb +24 -0
- data/spec/lib/hash_builder_spec.rb +29 -0
- data/spec/lib/hash_merger_spec.rb +146 -0
- data/spec/lib/hash_with_quick_access_spec.rb +62 -0
- data/spec/spec_helper.rb +91 -0
- data/tonsser_hash_utils.gemspec +26 -0
- metadata +123 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: 21216e909e28b7232940d8f26b5cf3f6d446ad60
|
4
|
+
data.tar.gz: d1abc94b1c4648912a2cd6c7a454b7fbf121a8df
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: 755fe94450976b16c5d2dd99f3191e6929ef6d7f0b734132fa0876afcb78e5a5f8a6de5b94da3dafb9d0dd85fa4586bb44a9eeb66266932f1e543e32b7ba09b1
|
7
|
+
data.tar.gz: 68a2949f62b74399490ee90880c55212bd4c758116bc7c83b416d0dad52ed00c37d9dfc3b32b78e19fac007d6225457803e4d4e78356a08d2678fcbe7b6d449b
|
data/.gitignore
ADDED
data/.rspec
ADDED
data/Gemfile
ADDED
data/LICENSE.txt
ADDED
@@ -0,0 +1,22 @@
|
|
1
|
+
Copyright (c) 2015 David Pedersen
|
2
|
+
|
3
|
+
MIT License
|
4
|
+
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining
|
6
|
+
a copy of this software and associated documentation files (the
|
7
|
+
"Software"), to deal in the Software without restriction, including
|
8
|
+
without limitation the rights to use, copy, modify, merge, publish,
|
9
|
+
distribute, sublicense, and/or sell copies of the Software, and to
|
10
|
+
permit persons to whom the Software is furnished to do so, subject to
|
11
|
+
the following conditions:
|
12
|
+
|
13
|
+
The above copyright notice and this permission notice shall be
|
14
|
+
included in all copies or substantial portions of the Software.
|
15
|
+
|
16
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
17
|
+
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
18
|
+
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
19
|
+
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
|
20
|
+
LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
|
21
|
+
OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
22
|
+
WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
data/README.md
ADDED
@@ -0,0 +1,31 @@
|
|
1
|
+
# TonsserHashUtils
|
2
|
+
|
3
|
+
TODO: Write a gem description
|
4
|
+
|
5
|
+
## Installation
|
6
|
+
|
7
|
+
Add this line to your application's Gemfile:
|
8
|
+
|
9
|
+
```ruby
|
10
|
+
gem 'tonsser_hash_utils'
|
11
|
+
```
|
12
|
+
|
13
|
+
And then execute:
|
14
|
+
|
15
|
+
$ bundle
|
16
|
+
|
17
|
+
Or install it yourself as:
|
18
|
+
|
19
|
+
$ gem install tonsser_hash_utils
|
20
|
+
|
21
|
+
## Usage
|
22
|
+
|
23
|
+
TODO: Write usage instructions here
|
24
|
+
|
25
|
+
## Contributing
|
26
|
+
|
27
|
+
1. Fork it ( https://github.com/[my-github-username]/tonsser_hash_utils/fork )
|
28
|
+
2. Create your feature branch (`git checkout -b my-new-feature`)
|
29
|
+
3. Commit your changes (`git commit -am 'Add some feature'`)
|
30
|
+
4. Push to the branch (`git push origin my-new-feature`)
|
31
|
+
5. Create a new Pull Request
|
data/Rakefile
ADDED
data/lib/deep_hash.rb
ADDED
@@ -0,0 +1,24 @@
|
|
1
|
+
# This class is useful for checking for keys within nested hashes
|
2
|
+
#
|
3
|
+
# Turns
|
4
|
+
#
|
5
|
+
# params[:foo] && params[:foo][:bar] && params[:foo][:bar][:baz]
|
6
|
+
#
|
7
|
+
# into
|
8
|
+
#
|
9
|
+
# DeepHash.new(params).dig(:foo, :bar, :baz)
|
10
|
+
class DeepHash
|
11
|
+
def initialize(hash)
|
12
|
+
@hash = hash
|
13
|
+
end
|
14
|
+
|
15
|
+
def dig(*keys)
|
16
|
+
keys.inject(@hash) do |location, key|
|
17
|
+
if location.nil?
|
18
|
+
nil
|
19
|
+
else
|
20
|
+
location[key]
|
21
|
+
end
|
22
|
+
end
|
23
|
+
end
|
24
|
+
end
|
data/lib/hash_builder.rb
ADDED
@@ -0,0 +1,40 @@
|
|
1
|
+
# This class simplifies the creation of potentially deeply nested hashes
|
2
|
+
# It turns code like this:
|
3
|
+
#
|
4
|
+
# hash = {
|
5
|
+
# one: {
|
6
|
+
# two: {
|
7
|
+
# three: {
|
8
|
+
# four: :foo
|
9
|
+
# }
|
10
|
+
# }
|
11
|
+
# }
|
12
|
+
# }
|
13
|
+
#
|
14
|
+
# Into this:
|
15
|
+
#
|
16
|
+
# hash = HashBuilder.new
|
17
|
+
# hash.one.two.three.four = :foo
|
18
|
+
#
|
19
|
+
# The underlaying hash can be retrieved with `#as_json`.
|
20
|
+
#
|
21
|
+
# NOTE: Its good practice to also implement respond_to_missing? when
|
22
|
+
# overriding method_missing, but for some reason that makes the tests fail.
|
23
|
+
class HashBuilder
|
24
|
+
def initialize
|
25
|
+
@hash = {}
|
26
|
+
end
|
27
|
+
|
28
|
+
def as_json
|
29
|
+
@hash.as_json
|
30
|
+
end
|
31
|
+
|
32
|
+
def method_missing(name, *args)
|
33
|
+
if match = name.to_s.match(/(?<key>.*?)=$/)
|
34
|
+
@hash[match[:key].to_sym] = args.first
|
35
|
+
else
|
36
|
+
@hash[name] = HashBuilder.new if @hash[name].blank?
|
37
|
+
@hash[name]
|
38
|
+
end
|
39
|
+
end
|
40
|
+
end
|
data/lib/hash_merger.rb
ADDED
@@ -0,0 +1,35 @@
|
|
1
|
+
# This class will deep merge two hashes to create one new hash
|
2
|
+
# with all keys and values from both. If there are duplicate keys
|
3
|
+
# the latter one wins.
|
4
|
+
# If some common keys point to arrays, those arrays will be merged
|
5
|
+
# as well. This is different from Hash#deep_merge, and the reason for
|
6
|
+
# having this class.
|
7
|
+
#
|
8
|
+
# Note that this class uses recursion, which might be dangerous
|
9
|
+
# in Ruby due to lack of tail call elimination. Recursion is
|
10
|
+
# however the easiest way to do stuff like this.
|
11
|
+
class HashMerger
|
12
|
+
def initialize(start)
|
13
|
+
@start = start
|
14
|
+
end
|
15
|
+
|
16
|
+
def merge_with(new)
|
17
|
+
do_merge(new, @start.dup)
|
18
|
+
end
|
19
|
+
|
20
|
+
private
|
21
|
+
|
22
|
+
def do_merge(hash, acc)
|
23
|
+
hash.inject(acc) do |acc, (key, value)|
|
24
|
+
acc[key] = if value.is_a?(Hash)
|
25
|
+
do_merge(value, acc[key].dup || {})
|
26
|
+
elsif value.is_a?(Array)
|
27
|
+
(acc[key] || []) + value
|
28
|
+
else
|
29
|
+
value
|
30
|
+
end
|
31
|
+
|
32
|
+
acc
|
33
|
+
end
|
34
|
+
end
|
35
|
+
end
|
@@ -0,0 +1,59 @@
|
|
1
|
+
class HashWithQuickAccess
|
2
|
+
def initialize(hash)
|
3
|
+
@hash = hash
|
4
|
+
end
|
5
|
+
|
6
|
+
def method_missing(key)
|
7
|
+
if has_key(key)
|
8
|
+
fetch_possibly_decorated_value(key)
|
9
|
+
else
|
10
|
+
raise KeyError.new("key :#{key} was not found")
|
11
|
+
end
|
12
|
+
end
|
13
|
+
|
14
|
+
def respond_to?(method_name, include_private = false)
|
15
|
+
has_key(method_name) || super
|
16
|
+
end
|
17
|
+
|
18
|
+
def keys
|
19
|
+
@hash.keys.map(&:to_sym)
|
20
|
+
end
|
21
|
+
|
22
|
+
def [](key)
|
23
|
+
send(key)
|
24
|
+
end
|
25
|
+
|
26
|
+
private
|
27
|
+
|
28
|
+
def fetch_possibly_decorated_value(key)
|
29
|
+
obj = @hash.fetch(key) { @hash.fetch(key.to_s) }
|
30
|
+
|
31
|
+
if should_be_decorated(obj)
|
32
|
+
decorate(obj)
|
33
|
+
else
|
34
|
+
obj
|
35
|
+
end
|
36
|
+
end
|
37
|
+
|
38
|
+
def should_be_decorated(obj)
|
39
|
+
(obj.is_a?(Array) && obj[0].is_a?(Hash)) || obj.is_a?(Hash)
|
40
|
+
end
|
41
|
+
|
42
|
+
def decorate(obj)
|
43
|
+
if obj.is_a?(Array)
|
44
|
+
obj.map { |o| HashWithQuickAccess.new(o) }
|
45
|
+
elsif obj.is_a?(Hash)
|
46
|
+
HashWithQuickAccess.new(obj)
|
47
|
+
end
|
48
|
+
end
|
49
|
+
|
50
|
+
def has_key(key)
|
51
|
+
all_keys.include?(key)
|
52
|
+
end
|
53
|
+
|
54
|
+
def all_keys
|
55
|
+
@hash.keys.flat_map do |key|
|
56
|
+
[key, key.to_sym]
|
57
|
+
end
|
58
|
+
end
|
59
|
+
end
|
@@ -0,0 +1,9 @@
|
|
1
|
+
require "tonsser_hash_utils/version"
|
2
|
+
|
3
|
+
require File.dirname(__FILE__) + "/hash_with_quick_access"
|
4
|
+
require File.dirname(__FILE__) + "/deep_hash"
|
5
|
+
require File.dirname(__FILE__) + "/hash_builder"
|
6
|
+
require File.dirname(__FILE__) + "/hash_merger"
|
7
|
+
|
8
|
+
module TonsserHashUtils
|
9
|
+
end
|
@@ -0,0 +1,24 @@
|
|
1
|
+
require "deep_hash"
|
2
|
+
|
3
|
+
describe DeepHash, "#dig" do
|
4
|
+
it "returns the value if its there" do
|
5
|
+
hash = DeepHash.new({
|
6
|
+
foo: {
|
7
|
+
bar: {
|
8
|
+
baz: {
|
9
|
+
qux: "value"
|
10
|
+
}
|
11
|
+
}
|
12
|
+
}
|
13
|
+
})
|
14
|
+
|
15
|
+
expect(hash.dig(:foo, :bar, :baz)).to eq({ qux: "value" })
|
16
|
+
expect(hash.dig(:foo, :bar, :baz, :qux)).to eq "value"
|
17
|
+
end
|
18
|
+
|
19
|
+
it "returns nil if the chain of keys fails along the way" do
|
20
|
+
hash = DeepHash.new({})
|
21
|
+
|
22
|
+
expect(hash.dig(:foo, :bar, :baz)).to be_nil
|
23
|
+
end
|
24
|
+
end
|
@@ -0,0 +1,29 @@
|
|
1
|
+
require "active_support/all"
|
2
|
+
require "hash_builder"
|
3
|
+
|
4
|
+
describe HashBuilder do
|
5
|
+
it "quickly assigns stuff to a hash" do
|
6
|
+
hash = HashBuilder.new
|
7
|
+
hash.foo = :foo
|
8
|
+
hash.bar = :bar
|
9
|
+
|
10
|
+
expect(hash.foo).to eq :foo
|
11
|
+
expect(hash.bar).to eq :bar
|
12
|
+
end
|
13
|
+
|
14
|
+
it "converts the hash to json" do
|
15
|
+
hash = HashBuilder.new
|
16
|
+
hash.foo = :foo
|
17
|
+
hash.bar = :bar
|
18
|
+
|
19
|
+
expect(hash.as_json).to eq({"foo"=>"foo", "bar"=>"bar"})
|
20
|
+
end
|
21
|
+
|
22
|
+
it "allows easy creation of nested hashes" do
|
23
|
+
hash = HashBuilder.new
|
24
|
+
hash.one.two.three.four = :foo
|
25
|
+
|
26
|
+
expect(hash.one.two.three.four).to eq :foo
|
27
|
+
expect(hash.as_json).to eq({"one"=>{"two"=>{"three"=>{"four"=>"foo"}}}})
|
28
|
+
end
|
29
|
+
end
|
@@ -0,0 +1,146 @@
|
|
1
|
+
require "hash_merger"
|
2
|
+
|
3
|
+
describe HashMerger do
|
4
|
+
it "deep merges hashes" do
|
5
|
+
a = {
|
6
|
+
foo: {
|
7
|
+
bar: {
|
8
|
+
baz: "one"
|
9
|
+
},
|
10
|
+
yo: "yo"
|
11
|
+
},
|
12
|
+
yo: "yo"
|
13
|
+
}
|
14
|
+
|
15
|
+
b = {
|
16
|
+
foo: {
|
17
|
+
bar: {
|
18
|
+
qux: "two"
|
19
|
+
}
|
20
|
+
},
|
21
|
+
dog: "dog"
|
22
|
+
}
|
23
|
+
|
24
|
+
merged = HashMerger.new(a).merge_with(b)
|
25
|
+
|
26
|
+
expect(merged).to eq({
|
27
|
+
foo: {
|
28
|
+
bar: {
|
29
|
+
baz: "one",
|
30
|
+
qux: "two",
|
31
|
+
},
|
32
|
+
yo: "yo"
|
33
|
+
},
|
34
|
+
yo: "yo",
|
35
|
+
dog: "dog",
|
36
|
+
})
|
37
|
+
|
38
|
+
expect(a).to eq({
|
39
|
+
foo: {
|
40
|
+
bar: {
|
41
|
+
baz: "one"
|
42
|
+
},
|
43
|
+
yo: "yo"
|
44
|
+
},
|
45
|
+
yo: "yo"
|
46
|
+
})
|
47
|
+
|
48
|
+
expect(b).to eq({
|
49
|
+
foo: {
|
50
|
+
bar: {
|
51
|
+
qux: "two"
|
52
|
+
}
|
53
|
+
},
|
54
|
+
dog: "dog"
|
55
|
+
})
|
56
|
+
end
|
57
|
+
|
58
|
+
it "deep merges arrays" do
|
59
|
+
a = {
|
60
|
+
foo: {
|
61
|
+
bar: ["one"]
|
62
|
+
}
|
63
|
+
}
|
64
|
+
|
65
|
+
b = {
|
66
|
+
foo: {
|
67
|
+
bar: ["two"]
|
68
|
+
}
|
69
|
+
}
|
70
|
+
|
71
|
+
merged = HashMerger.new(a).merge_with(b)
|
72
|
+
|
73
|
+
expect(merged).to eq({
|
74
|
+
foo: {
|
75
|
+
bar: ["one", "two"]
|
76
|
+
}
|
77
|
+
})
|
78
|
+
|
79
|
+
expect(a).to eq({
|
80
|
+
foo: { bar: ["one"] }
|
81
|
+
})
|
82
|
+
|
83
|
+
expect(b).to eq({
|
84
|
+
foo: { bar: ["two"] }
|
85
|
+
})
|
86
|
+
end
|
87
|
+
|
88
|
+
it "merges hashes with mixed types" do
|
89
|
+
a = {
|
90
|
+
foo: {
|
91
|
+
bar: {
|
92
|
+
baz: "one"
|
93
|
+
},
|
94
|
+
array: [1,2],
|
95
|
+
yo: "yo"
|
96
|
+
},
|
97
|
+
yo: "yo"
|
98
|
+
}
|
99
|
+
|
100
|
+
b = {
|
101
|
+
foo: {
|
102
|
+
bar: {
|
103
|
+
qux: "two"
|
104
|
+
},
|
105
|
+
array: [3,4]
|
106
|
+
},
|
107
|
+
dog: "dog"
|
108
|
+
}
|
109
|
+
|
110
|
+
merged = HashMerger.new(a).merge_with(b)
|
111
|
+
|
112
|
+
expect(merged).to eq({
|
113
|
+
foo: {
|
114
|
+
bar: {
|
115
|
+
baz: "one",
|
116
|
+
qux: "two",
|
117
|
+
},
|
118
|
+
array: [1,2,3,4],
|
119
|
+
yo: "yo"
|
120
|
+
},
|
121
|
+
yo: "yo",
|
122
|
+
dog: "dog",
|
123
|
+
})
|
124
|
+
|
125
|
+
expect(a).to eq({
|
126
|
+
foo: {
|
127
|
+
bar: {
|
128
|
+
baz: "one"
|
129
|
+
},
|
130
|
+
array: [1,2],
|
131
|
+
yo: "yo"
|
132
|
+
},
|
133
|
+
yo: "yo"
|
134
|
+
})
|
135
|
+
|
136
|
+
expect(b).to eq({
|
137
|
+
foo: {
|
138
|
+
bar: {
|
139
|
+
qux: "two"
|
140
|
+
},
|
141
|
+
array: [3,4]
|
142
|
+
},
|
143
|
+
dog: "dog"
|
144
|
+
})
|
145
|
+
end
|
146
|
+
end
|
@@ -0,0 +1,62 @@
|
|
1
|
+
require "hash_with_quick_access"
|
2
|
+
|
3
|
+
describe HashWithQuickAccess do
|
4
|
+
it "gives you quick access to hashes or arrays nested in other hashes" do
|
5
|
+
hash = HashWithQuickAccess.new({
|
6
|
+
name: "Mikkel Hansen",
|
7
|
+
books: [
|
8
|
+
{ name: "Fight Club" },
|
9
|
+
],
|
10
|
+
job: {
|
11
|
+
title: "Programmer",
|
12
|
+
},
|
13
|
+
})
|
14
|
+
|
15
|
+
expect(hash.name).to eq "Mikkel Hansen"
|
16
|
+
expect(hash.books.first.name).to eq "Fight Club"
|
17
|
+
expect(hash.job.title).to eq "Programmer"
|
18
|
+
end
|
19
|
+
|
20
|
+
it "only wraps values if they are hashes" do
|
21
|
+
hash = HashWithQuickAccess.new({
|
22
|
+
books: [
|
23
|
+
"Fight Club"
|
24
|
+
],
|
25
|
+
})
|
26
|
+
|
27
|
+
expect(hash.books.first).to eq "Fight Club"
|
28
|
+
end
|
29
|
+
|
30
|
+
it "gives a useful error when asking for key that doesn't exist" do
|
31
|
+
hash = HashWithQuickAccess.new({})
|
32
|
+
|
33
|
+
expect {
|
34
|
+
hash.foo.bar.baz
|
35
|
+
}.to raise_error(KeyError, "key :foo was not found")
|
36
|
+
end
|
37
|
+
|
38
|
+
it "lets you get at the keys" do
|
39
|
+
hash = HashWithQuickAccess.new({
|
40
|
+
name: "Mikkel Hansen",
|
41
|
+
books: [],
|
42
|
+
})
|
43
|
+
|
44
|
+
expect(hash.keys).to eq [:name, :books]
|
45
|
+
end
|
46
|
+
|
47
|
+
it "allows lookups when the keys are strings" do
|
48
|
+
hash = HashWithQuickAccess.new({ "name" => 1 })
|
49
|
+
|
50
|
+
expect(hash.name).to eq 1
|
51
|
+
end
|
52
|
+
|
53
|
+
it "lets you use the standard hash #[] method" do
|
54
|
+
hash = HashWithQuickAccess.new({
|
55
|
+
job: {
|
56
|
+
title: "Programmer",
|
57
|
+
},
|
58
|
+
})
|
59
|
+
|
60
|
+
expect(hash[:job][:title]).to eq "Programmer"
|
61
|
+
end
|
62
|
+
end
|
data/spec/spec_helper.rb
ADDED
@@ -0,0 +1,91 @@
|
|
1
|
+
# This file was generated by the `rspec --init` command. Conventionally, all
|
2
|
+
# specs live under a `spec` directory, which RSpec adds to the `$LOAD_PATH`.
|
3
|
+
# The generated `.rspec` file contains `--require spec_helper` which will cause
|
4
|
+
# this file to always be loaded, without a need to explicitly require it in any
|
5
|
+
# files.
|
6
|
+
#
|
7
|
+
# Given that it is always loaded, you are encouraged to keep this file as
|
8
|
+
# light-weight as possible. Requiring heavyweight dependencies from this file
|
9
|
+
# will add to the boot time of your test suite on EVERY test run, even for an
|
10
|
+
# individual file that may not need all of that loaded. Instead, consider making
|
11
|
+
# a separate helper file that requires the additional dependencies and performs
|
12
|
+
# the additional setup, and require it from the spec files that actually need
|
13
|
+
# it.
|
14
|
+
#
|
15
|
+
# The `.rspec` file also contains a few flags that are not defaults but that
|
16
|
+
# users commonly want.
|
17
|
+
#
|
18
|
+
# See http://rubydoc.info/gems/rspec-core/RSpec/Core/Configuration
|
19
|
+
RSpec.configure do |config|
|
20
|
+
# rspec-expectations config goes here. You can use an alternate
|
21
|
+
# assertion/expectation library such as wrong or the stdlib/minitest
|
22
|
+
# assertions if you prefer.
|
23
|
+
config.expect_with :rspec do |expectations|
|
24
|
+
# This option will default to `true` in RSpec 4. It makes the `description`
|
25
|
+
# and `failure_message` of custom matchers include text for helper methods
|
26
|
+
# defined using `chain`, e.g.:
|
27
|
+
# be_bigger_than(2).and_smaller_than(4).description
|
28
|
+
# # => "be bigger than 2 and smaller than 4"
|
29
|
+
# ...rather than:
|
30
|
+
# # => "be bigger than 2"
|
31
|
+
expectations.include_chain_clauses_in_custom_matcher_descriptions = true
|
32
|
+
end
|
33
|
+
|
34
|
+
# rspec-mocks config goes here. You can use an alternate test double
|
35
|
+
# library (such as bogus or mocha) by changing the `mock_with` option here.
|
36
|
+
config.mock_with :rspec do |mocks|
|
37
|
+
# Prevents you from mocking or stubbing a method that does not exist on
|
38
|
+
# a real object. This is generally recommended, and will default to
|
39
|
+
# `true` in RSpec 4.
|
40
|
+
mocks.verify_partial_doubles = true
|
41
|
+
end
|
42
|
+
|
43
|
+
# The settings below are suggested to provide a good initial experience
|
44
|
+
# with RSpec, but feel free to customize to your heart's content.
|
45
|
+
=begin
|
46
|
+
# These two settings work together to allow you to limit a spec run
|
47
|
+
# to individual examples or groups you care about by tagging them with
|
48
|
+
# `:focus` metadata. When nothing is tagged with `:focus`, all examples
|
49
|
+
# get run.
|
50
|
+
config.filter_run :focus
|
51
|
+
config.run_all_when_everything_filtered = true
|
52
|
+
|
53
|
+
# Limits the available syntax to the non-monkey patched syntax that is
|
54
|
+
# recommended. For more details, see:
|
55
|
+
# - http://myronmars.to/n/dev-blog/2012/06/rspecs-new-expectation-syntax
|
56
|
+
# - http://teaisaweso.me/blog/2013/05/27/rspecs-new-message-expectation-syntax/
|
57
|
+
# - http://myronmars.to/n/dev-blog/2014/05/notable-changes-in-rspec-3#new__config_option_to_disable_rspeccore_monkey_patching
|
58
|
+
config.disable_monkey_patching!
|
59
|
+
|
60
|
+
# This setting enables warnings. It's recommended, but in some cases may
|
61
|
+
# be too noisy due to issues in dependencies.
|
62
|
+
config.warnings = true
|
63
|
+
|
64
|
+
# Many RSpec users commonly either run the entire suite or an individual
|
65
|
+
# file, and it's useful to allow more verbose output when running an
|
66
|
+
# individual spec file.
|
67
|
+
if config.files_to_run.one?
|
68
|
+
# Use the documentation formatter for detailed output,
|
69
|
+
# unless a formatter has already been configured
|
70
|
+
# (e.g. via a command-line flag).
|
71
|
+
config.default_formatter = 'doc'
|
72
|
+
end
|
73
|
+
|
74
|
+
# Print the 10 slowest examples and example groups at the
|
75
|
+
# end of the spec run, to help surface which specs are running
|
76
|
+
# particularly slow.
|
77
|
+
config.profile_examples = 10
|
78
|
+
|
79
|
+
# Run specs in random order to surface order dependencies. If you find an
|
80
|
+
# order dependency and want to debug it, you can fix the order by providing
|
81
|
+
# the seed, which is printed after each run.
|
82
|
+
# --seed 1234
|
83
|
+
config.order = :random
|
84
|
+
|
85
|
+
# Seed global randomization in this process using the `--seed` CLI option.
|
86
|
+
# Setting this allows you to use `--seed` to deterministically reproduce
|
87
|
+
# test failures related to randomization by passing the same `--seed` value
|
88
|
+
# as the one that triggered the failure.
|
89
|
+
Kernel.srand config.seed
|
90
|
+
=end
|
91
|
+
end
|
@@ -0,0 +1,26 @@
|
|
1
|
+
# coding: utf-8
|
2
|
+
lib = File.expand_path('../lib', __FILE__)
|
3
|
+
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
4
|
+
require 'tonsser_hash_utils/version'
|
5
|
+
|
6
|
+
Gem::Specification.new do |spec|
|
7
|
+
spec.name = "tonsser_hash_utils"
|
8
|
+
spec.version = TonsserHashUtils::VERSION
|
9
|
+
spec.authors = ["David Pedersen"]
|
10
|
+
spec.email = ["david@tonsser.com"]
|
11
|
+
spec.summary = %q{A collection of classes for dealing with hashes}
|
12
|
+
spec.description = %q{}
|
13
|
+
spec.homepage = "http://github.com/tonsser/tonsser_hash_utils"
|
14
|
+
spec.license = "MIT"
|
15
|
+
|
16
|
+
spec.files = `git ls-files -z`.split("\x0")
|
17
|
+
spec.executables = spec.files.grep(%r{^bin/}) { |f| File.basename(f) }
|
18
|
+
spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
|
19
|
+
spec.require_paths = ["lib"]
|
20
|
+
|
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
|
+
|
25
|
+
spec.add_runtime_dependency "activesupport", "~> 4.2.0"
|
26
|
+
end
|
metadata
ADDED
@@ -0,0 +1,123 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: tonsser_hash_utils
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: '1.0'
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- David Pedersen
|
8
|
+
autorequire:
|
9
|
+
bindir: bin
|
10
|
+
cert_chain: []
|
11
|
+
date: 2015-02-12 00:00:00.000000000 Z
|
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.7'
|
20
|
+
type: :development
|
21
|
+
prerelease: false
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
23
|
+
requirements:
|
24
|
+
- - "~>"
|
25
|
+
- !ruby/object:Gem::Version
|
26
|
+
version: '1.7'
|
27
|
+
- !ruby/object:Gem::Dependency
|
28
|
+
name: rake
|
29
|
+
requirement: !ruby/object:Gem::Requirement
|
30
|
+
requirements:
|
31
|
+
- - "~>"
|
32
|
+
- !ruby/object:Gem::Version
|
33
|
+
version: '10.0'
|
34
|
+
type: :development
|
35
|
+
prerelease: false
|
36
|
+
version_requirements: !ruby/object:Gem::Requirement
|
37
|
+
requirements:
|
38
|
+
- - "~>"
|
39
|
+
- !ruby/object:Gem::Version
|
40
|
+
version: '10.0'
|
41
|
+
- !ruby/object:Gem::Dependency
|
42
|
+
name: rspec
|
43
|
+
requirement: !ruby/object:Gem::Requirement
|
44
|
+
requirements:
|
45
|
+
- - "~>"
|
46
|
+
- !ruby/object:Gem::Version
|
47
|
+
version: 3.2.0
|
48
|
+
type: :development
|
49
|
+
prerelease: false
|
50
|
+
version_requirements: !ruby/object:Gem::Requirement
|
51
|
+
requirements:
|
52
|
+
- - "~>"
|
53
|
+
- !ruby/object:Gem::Version
|
54
|
+
version: 3.2.0
|
55
|
+
- !ruby/object:Gem::Dependency
|
56
|
+
name: activesupport
|
57
|
+
requirement: !ruby/object:Gem::Requirement
|
58
|
+
requirements:
|
59
|
+
- - "~>"
|
60
|
+
- !ruby/object:Gem::Version
|
61
|
+
version: 4.2.0
|
62
|
+
type: :runtime
|
63
|
+
prerelease: false
|
64
|
+
version_requirements: !ruby/object:Gem::Requirement
|
65
|
+
requirements:
|
66
|
+
- - "~>"
|
67
|
+
- !ruby/object:Gem::Version
|
68
|
+
version: 4.2.0
|
69
|
+
description: ''
|
70
|
+
email:
|
71
|
+
- david@tonsser.com
|
72
|
+
executables: []
|
73
|
+
extensions: []
|
74
|
+
extra_rdoc_files: []
|
75
|
+
files:
|
76
|
+
- ".gitignore"
|
77
|
+
- ".rspec"
|
78
|
+
- Gemfile
|
79
|
+
- LICENSE.txt
|
80
|
+
- README.md
|
81
|
+
- Rakefile
|
82
|
+
- lib/deep_hash.rb
|
83
|
+
- lib/hash_builder.rb
|
84
|
+
- lib/hash_merger.rb
|
85
|
+
- lib/hash_with_quick_access.rb
|
86
|
+
- lib/tonsser_hash_utils.rb
|
87
|
+
- lib/tonsser_hash_utils/version.rb
|
88
|
+
- spec/lib/deep_hash_spec.rb
|
89
|
+
- spec/lib/hash_builder_spec.rb
|
90
|
+
- spec/lib/hash_merger_spec.rb
|
91
|
+
- spec/lib/hash_with_quick_access_spec.rb
|
92
|
+
- spec/spec_helper.rb
|
93
|
+
- tonsser_hash_utils.gemspec
|
94
|
+
homepage: http://github.com/tonsser/tonsser_hash_utils
|
95
|
+
licenses:
|
96
|
+
- MIT
|
97
|
+
metadata: {}
|
98
|
+
post_install_message:
|
99
|
+
rdoc_options: []
|
100
|
+
require_paths:
|
101
|
+
- lib
|
102
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
103
|
+
requirements:
|
104
|
+
- - ">="
|
105
|
+
- !ruby/object:Gem::Version
|
106
|
+
version: '0'
|
107
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
108
|
+
requirements:
|
109
|
+
- - ">="
|
110
|
+
- !ruby/object:Gem::Version
|
111
|
+
version: '0'
|
112
|
+
requirements: []
|
113
|
+
rubyforge_project:
|
114
|
+
rubygems_version: 2.4.5
|
115
|
+
signing_key:
|
116
|
+
specification_version: 4
|
117
|
+
summary: A collection of classes for dealing with hashes
|
118
|
+
test_files:
|
119
|
+
- spec/lib/deep_hash_spec.rb
|
120
|
+
- spec/lib/hash_builder_spec.rb
|
121
|
+
- spec/lib/hash_merger_spec.rb
|
122
|
+
- spec/lib/hash_with_quick_access_spec.rb
|
123
|
+
- spec/spec_helper.rb
|