right_support 2.8.30 → 2.8.31
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 +4 -4
- data/LICENSE +57 -1
- data/VERSION +1 -1
- data/lib/right_support/data.rb +1 -0
- data/lib/right_support/data/hash_tools.rb +2 -8
- data/lib/right_support/data/mash.rb +161 -0
- data/right_support.gemspec +5 -3
- data/spec/data/hash_tools_spec.rb +1 -1
- data/spec/data/mash_spec.rb +313 -0
- metadata +4 -2
checksums.yaml
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
---
|
|
2
2
|
SHA1:
|
|
3
|
-
metadata.gz:
|
|
4
|
-
data.tar.gz:
|
|
3
|
+
metadata.gz: 54dcd26e6d8094ac8b3f8ad42dae62aaf9287a7c
|
|
4
|
+
data.tar.gz: aa1a58306c4222a41daa45cc30626723065615a1
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: 97f3b74d83992e636fbc6d09926503db59a427f4907ea1679754dd916be7fee3764d88202be9aead0f484c878efe69d4bf77bfb0d580596a5009e74ad5d76e47
|
|
7
|
+
data.tar.gz: 6192c632633ef97f57ac37fc8159fe40b22a1eebe269608efb560615e138e69118c8b81702f853bfb7042819777225ffda197dfe8b93de21320e2789075532b4
|
data/LICENSE
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
Copyright (c) 2009-
|
|
1
|
+
Copyright (c) 2009-2014 RightScale, Inc.
|
|
2
2
|
|
|
3
3
|
Permission is hereby granted, free of charge, to any person obtaining
|
|
4
4
|
a copy of this software and associated documentation files (the
|
|
@@ -18,3 +18,59 @@ IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
|
|
|
18
18
|
CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
|
|
19
19
|
TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
|
|
20
20
|
SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
|
21
|
+
|
|
22
|
+
---
|
|
23
|
+
---
|
|
24
|
+
|
|
25
|
+
Some portions of lib/right_support/data/mash.rb and spec/data/mash_spec.rb
|
|
26
|
+
are modified versions of the extlib library, which is licensed under the
|
|
27
|
+
MIT license. That license, plus the license of the code from which extlib
|
|
28
|
+
was derived, is included below:
|
|
29
|
+
|
|
30
|
+
Copyright (c) 2010 Dan Kubb
|
|
31
|
+
|
|
32
|
+
Permission is hereby granted, free of charge, to any person obtaining
|
|
33
|
+
a copy of this software and associated documentation files (the
|
|
34
|
+
"Software"), to deal in the Software without restriction, including
|
|
35
|
+
without limitation the rights to use, copy, modify, merge, publish,
|
|
36
|
+
distribute, sublicense, and/or sell copies of the Software, and to
|
|
37
|
+
permit persons to whom the Software is furnished to do so, subject to
|
|
38
|
+
the following conditions:
|
|
39
|
+
|
|
40
|
+
The above copyright notice and this permission notice shall be
|
|
41
|
+
included in all copies or substantial portions of the Software.
|
|
42
|
+
|
|
43
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
|
44
|
+
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
|
45
|
+
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
|
46
|
+
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
|
|
47
|
+
LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
|
|
48
|
+
OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
|
49
|
+
WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
|
50
|
+
|
|
51
|
+
---
|
|
52
|
+
---
|
|
53
|
+
|
|
54
|
+
Some portions of blank.rb and mash.rb are verbatim copies of software
|
|
55
|
+
licensed under the MIT license. That license is included below:
|
|
56
|
+
|
|
57
|
+
Copyright (c) 2005-2008 David Heinemeier Hansson
|
|
58
|
+
|
|
59
|
+
Permission is hereby granted, free of charge, to any person obtaining
|
|
60
|
+
a copy of this software and associated documentation files (the
|
|
61
|
+
"Software"), to deal in the Software without restriction, including
|
|
62
|
+
without limitation the rights to use, copy, modify, merge, publish,
|
|
63
|
+
distribute, sublicense, and/or sell copies of the Software, and to
|
|
64
|
+
permit persons to whom the Software is furnished to do so, subject to
|
|
65
|
+
the following conditions:
|
|
66
|
+
|
|
67
|
+
The above copyright notice and this permission notice shall be
|
|
68
|
+
included in all copies or substantial portions of the Software.
|
|
69
|
+
|
|
70
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
|
71
|
+
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
|
72
|
+
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
|
73
|
+
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
|
|
74
|
+
LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
|
|
75
|
+
OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
|
76
|
+
WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
data/VERSION
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
2.8.
|
|
1
|
+
2.8.31
|
data/lib/right_support/data.rb
CHANGED
|
@@ -26,11 +26,9 @@ module RightSupport::Data
|
|
|
26
26
|
module HashTools
|
|
27
27
|
|
|
28
28
|
# require checks
|
|
29
|
-
HAS_EXTLIB = require_succeeds?('extlib/mash')
|
|
30
29
|
HAS_JSON = require_succeeds?('json')
|
|
31
30
|
|
|
32
31
|
# exceptions
|
|
33
|
-
class NoExtlib < ::StandardError; end
|
|
34
32
|
class NoJson < ::StandardError; end
|
|
35
33
|
|
|
36
34
|
# Determines if given object is hashable (i.e. object responds to hash methods).
|
|
@@ -219,12 +217,8 @@ module RightSupport::Data
|
|
|
219
217
|
# === Return
|
|
220
218
|
# @return [Object] depends on input type
|
|
221
219
|
def self.deep_mash(any, &leaf_callback)
|
|
222
|
-
|
|
223
|
-
|
|
224
|
-
deep_clone2(any, options, &leaf_callback)
|
|
225
|
-
else
|
|
226
|
-
raise NoExtlib, "extlib is unavailable"
|
|
227
|
-
end
|
|
220
|
+
options = { :class => RightSupport::Data::Mash }
|
|
221
|
+
deep_clone2(any, options, &leaf_callback)
|
|
228
222
|
end
|
|
229
223
|
|
|
230
224
|
# Performs a deep merge (but not a deep clone) of one hash into another.
|
|
@@ -0,0 +1,161 @@
|
|
|
1
|
+
module RightSupport::Data
|
|
2
|
+
# A workalike for extlib's ::Mash, but properly namespaced.
|
|
3
|
+
class Mash < ::Hash
|
|
4
|
+
|
|
5
|
+
# @param constructor<Object>
|
|
6
|
+
# The default value for the mash. Defaults to an empty hash.
|
|
7
|
+
#
|
|
8
|
+
# @details [Alternatives]
|
|
9
|
+
# If constructor is a Hash, a new mash will be created based on the keys of
|
|
10
|
+
# the hash and no default value will be set.
|
|
11
|
+
def initialize(constructor = {})
|
|
12
|
+
if constructor.is_a?(Hash)
|
|
13
|
+
super()
|
|
14
|
+
update(constructor)
|
|
15
|
+
else
|
|
16
|
+
super(constructor)
|
|
17
|
+
end
|
|
18
|
+
end
|
|
19
|
+
|
|
20
|
+
# @param key<Object> The default value for the mash. Defaults to nil.
|
|
21
|
+
#
|
|
22
|
+
# @details [Alternatives]
|
|
23
|
+
# If key is a Symbol and it is a key in the mash, then the default value will
|
|
24
|
+
# be set to the value matching the key.
|
|
25
|
+
def default(key = nil)
|
|
26
|
+
if key.is_a?(Symbol) && include?(key = key.to_s)
|
|
27
|
+
self[key]
|
|
28
|
+
else
|
|
29
|
+
super
|
|
30
|
+
end
|
|
31
|
+
end
|
|
32
|
+
|
|
33
|
+
alias_method :regular_writer, :[]= unless method_defined?(:regular_writer)
|
|
34
|
+
alias_method :regular_update, :update unless method_defined?(:regular_update)
|
|
35
|
+
|
|
36
|
+
# @param key<Object> The key to set.
|
|
37
|
+
# @param value<Object>
|
|
38
|
+
# The value to set the key to.
|
|
39
|
+
#
|
|
40
|
+
# @see Mash#convert_key
|
|
41
|
+
# @see Mash#convert_value
|
|
42
|
+
def []=(key, value)
|
|
43
|
+
regular_writer(convert_key(key), convert_value(value))
|
|
44
|
+
end
|
|
45
|
+
|
|
46
|
+
# @param other_hash<Hash>
|
|
47
|
+
# A hash to update values in the mash with. The keys and the values will be
|
|
48
|
+
# converted to Mash format.
|
|
49
|
+
#
|
|
50
|
+
# @return [Mash] The updated mash.
|
|
51
|
+
def update(other_hash)
|
|
52
|
+
other_hash.each_pair { |key, value| regular_writer(convert_key(key), convert_value(value)) }
|
|
53
|
+
self
|
|
54
|
+
end
|
|
55
|
+
|
|
56
|
+
alias_method :merge!, :update
|
|
57
|
+
|
|
58
|
+
# @param key<Object> The key to check for. This will be run through convert_key.
|
|
59
|
+
#
|
|
60
|
+
# @return [Boolean] True if the key exists in the mash.
|
|
61
|
+
def key?(key)
|
|
62
|
+
super(convert_key(key))
|
|
63
|
+
end
|
|
64
|
+
|
|
65
|
+
# def include? def has_key? def member?
|
|
66
|
+
alias_method :include?, :key?
|
|
67
|
+
alias_method :has_key?, :key?
|
|
68
|
+
alias_method :member?, :key?
|
|
69
|
+
|
|
70
|
+
# @param key<Object> The key to fetch. This will be run through convert_key.
|
|
71
|
+
# @param *extras<Array> Default value.
|
|
72
|
+
#
|
|
73
|
+
# @return [Object] The value at key or the default value.
|
|
74
|
+
def fetch(key, *extras)
|
|
75
|
+
super(convert_key(key), *extras)
|
|
76
|
+
end
|
|
77
|
+
|
|
78
|
+
# @param *indices<Array>
|
|
79
|
+
# The keys to retrieve values for. These will be run through +convert_key+.
|
|
80
|
+
#
|
|
81
|
+
# @return [Array] The values at each of the provided keys
|
|
82
|
+
def values_at(*indices)
|
|
83
|
+
indices.collect {|key| self[convert_key(key)]}
|
|
84
|
+
end
|
|
85
|
+
|
|
86
|
+
# @param hash<Hash> The hash to merge with the mash.
|
|
87
|
+
#
|
|
88
|
+
# @return [Mash] A new mash with the hash values merged in.
|
|
89
|
+
def merge(hash)
|
|
90
|
+
self.dup.update(hash)
|
|
91
|
+
end
|
|
92
|
+
|
|
93
|
+
# @param key<Object>
|
|
94
|
+
# The key to delete from the mash.\
|
|
95
|
+
def delete(key)
|
|
96
|
+
super(convert_key(key))
|
|
97
|
+
end
|
|
98
|
+
|
|
99
|
+
# @param *rejected<Array[(String, Symbol)] The mash keys to exclude.
|
|
100
|
+
#
|
|
101
|
+
# @return [Mash] A new mash without the selected keys.
|
|
102
|
+
#
|
|
103
|
+
# @example
|
|
104
|
+
# { :one => 1, :two => 2, :three => 3 }.except(:one)
|
|
105
|
+
# #=> { "two" => 2, "three" => 3 }
|
|
106
|
+
def except(*keys)
|
|
107
|
+
keys = keys.map { |k| convert_key(k) }
|
|
108
|
+
hash = self.dup
|
|
109
|
+
keys.each {|k| hash.delete(k) }
|
|
110
|
+
hash
|
|
111
|
+
end
|
|
112
|
+
|
|
113
|
+
# Used to provide the same interface as Hash.
|
|
114
|
+
#
|
|
115
|
+
# @return [Mash] This mash unchanged.
|
|
116
|
+
def stringify_keys!; self end
|
|
117
|
+
|
|
118
|
+
# @return [Hash] The mash as a Hash with symbolized keys.
|
|
119
|
+
def symbolize_keys
|
|
120
|
+
h = Hash.new(default)
|
|
121
|
+
each { |key, val| h[key.to_sym] = val }
|
|
122
|
+
h
|
|
123
|
+
end
|
|
124
|
+
|
|
125
|
+
# @return [Hash] The mash as a Hash with string keys.
|
|
126
|
+
def to_hash
|
|
127
|
+
Hash.new(default).merge(self)
|
|
128
|
+
end
|
|
129
|
+
|
|
130
|
+
protected
|
|
131
|
+
# @param key<Object> The key to convert.
|
|
132
|
+
#
|
|
133
|
+
# @param [Object]
|
|
134
|
+
# The converted key. If the key was a symbol, it will be converted to a
|
|
135
|
+
# string.
|
|
136
|
+
#
|
|
137
|
+
# @api private
|
|
138
|
+
def convert_key(key)
|
|
139
|
+
key.kind_of?(Symbol) ? key.to_s : key
|
|
140
|
+
end
|
|
141
|
+
|
|
142
|
+
# @param value<Object> The value to convert.
|
|
143
|
+
#
|
|
144
|
+
# @return [Object]
|
|
145
|
+
# The converted value. A Hash or an Array of hashes, will be converted to
|
|
146
|
+
# their Mash equivalents.
|
|
147
|
+
#
|
|
148
|
+
# @api private
|
|
149
|
+
def convert_value(value)
|
|
150
|
+
if value.class == Hash
|
|
151
|
+
hash = Mash.new(value)
|
|
152
|
+
hash.default = value.default
|
|
153
|
+
hash
|
|
154
|
+
elsif value.is_a?(Array)
|
|
155
|
+
value.collect { |e| convert_value(e) }
|
|
156
|
+
else
|
|
157
|
+
value
|
|
158
|
+
end
|
|
159
|
+
end
|
|
160
|
+
end
|
|
161
|
+
end
|
data/right_support.gemspec
CHANGED
|
@@ -2,16 +2,16 @@
|
|
|
2
2
|
# DO NOT EDIT THIS FILE DIRECTLY
|
|
3
3
|
# Instead, edit Jeweler::Tasks in Rakefile, and run 'rake gemspec'
|
|
4
4
|
# -*- encoding: utf-8 -*-
|
|
5
|
-
# stub: right_support 2.8.
|
|
5
|
+
# stub: right_support 2.8.31 ruby lib
|
|
6
6
|
|
|
7
7
|
Gem::Specification.new do |s|
|
|
8
8
|
s.name = "right_support"
|
|
9
|
-
s.version = "2.8.
|
|
9
|
+
s.version = "2.8.31"
|
|
10
10
|
|
|
11
11
|
s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
|
|
12
12
|
s.require_paths = ["lib"]
|
|
13
13
|
s.authors = ["Tony Spataro", "Sergey Sergyenko", "Ryan Williamson", "Lee Kirchhoff", "Alexey Karpik", "Scott Messier"]
|
|
14
|
-
s.date = "2014-09-
|
|
14
|
+
s.date = "2014-09-25"
|
|
15
15
|
s.description = "A toolkit of useful, reusable foundation code created by RightScale."
|
|
16
16
|
s.email = "support@rightscale.com"
|
|
17
17
|
s.extra_rdoc_files = [
|
|
@@ -53,6 +53,7 @@ Gem::Specification.new do |s|
|
|
|
53
53
|
"lib/right_support/crypto/signed_hash.rb",
|
|
54
54
|
"lib/right_support/data.rb",
|
|
55
55
|
"lib/right_support/data/hash_tools.rb",
|
|
56
|
+
"lib/right_support/data/mash.rb",
|
|
56
57
|
"lib/right_support/data/serializer.rb",
|
|
57
58
|
"lib/right_support/data/unknown_type.rb",
|
|
58
59
|
"lib/right_support/data/uuid.rb",
|
|
@@ -100,6 +101,7 @@ Gem::Specification.new do |s|
|
|
|
100
101
|
"spec/config/feature_set_spec.rb",
|
|
101
102
|
"spec/crypto/signed_hash_spec.rb",
|
|
102
103
|
"spec/data/hash_tools_spec.rb",
|
|
104
|
+
"spec/data/mash_spec.rb",
|
|
103
105
|
"spec/data/uuid_spec.rb",
|
|
104
106
|
"spec/db/cassandra_model_part1_spec.rb",
|
|
105
107
|
"spec/db/cassandra_model_part2_spec.rb",
|
|
@@ -194,7 +194,7 @@ describe RightSupport::Data::HashTools do
|
|
|
194
194
|
def deep_check_object_id(a, b, &leaf_callback)
|
|
195
195
|
a.object_id.should_not == b.object_id
|
|
196
196
|
if subject.hashable?(a)
|
|
197
|
-
b.class.should == ::Mash
|
|
197
|
+
b.class.should == RightSupport::Data::Mash
|
|
198
198
|
a.each do |k, v|
|
|
199
199
|
other = b[k]
|
|
200
200
|
if subject.hashable?(v)
|
|
@@ -0,0 +1,313 @@
|
|
|
1
|
+
require 'spec_helper'
|
|
2
|
+
|
|
3
|
+
class AwesomeHash < Hash
|
|
4
|
+
end
|
|
5
|
+
|
|
6
|
+
describe RightSupport::Data::Mash do
|
|
7
|
+
subject { RightSupport::Data::Mash}
|
|
8
|
+
|
|
9
|
+
before(:each) do
|
|
10
|
+
@hash = { "mash" => "indifferent", :hash => "different" }
|
|
11
|
+
@sub = AwesomeHash.new("mash" => "indifferent", :hash => "different")
|
|
12
|
+
end
|
|
13
|
+
|
|
14
|
+
describe "#initialize" do
|
|
15
|
+
it 'converts all keys into strings when param is a Hash' do
|
|
16
|
+
mash = subject.new(@hash)
|
|
17
|
+
|
|
18
|
+
mash.keys.any? { |key| key.is_a?(Symbol) }.should be(false)
|
|
19
|
+
end
|
|
20
|
+
|
|
21
|
+
it 'converts all pure Hash values into Mashes if param is a Hash' do
|
|
22
|
+
mash = subject.new :hash => @hash
|
|
23
|
+
|
|
24
|
+
mash["hash"].should be_an_instance_of(subject)
|
|
25
|
+
# sanity check
|
|
26
|
+
mash["hash"]["hash"].should == "different"
|
|
27
|
+
end
|
|
28
|
+
|
|
29
|
+
it 'doesn not convert Hash subclass values into Mashes' do
|
|
30
|
+
mash = subject.new :sub => @sub
|
|
31
|
+
mash["sub"].should be_an_instance_of(AwesomeHash)
|
|
32
|
+
end
|
|
33
|
+
|
|
34
|
+
it 'converts all value items if value is an Array' do
|
|
35
|
+
mash = subject.new :arry => { :hash => [@hash] }
|
|
36
|
+
|
|
37
|
+
mash["arry"].should be_an_instance_of(subject)
|
|
38
|
+
# sanity check
|
|
39
|
+
mash["arry"]["hash"].first["hash"].should == "different"
|
|
40
|
+
|
|
41
|
+
end
|
|
42
|
+
|
|
43
|
+
it 'delegates to superclass constructor if param is not a Hash' do
|
|
44
|
+
mash = subject.new("dash berlin")
|
|
45
|
+
|
|
46
|
+
mash["unexisting key"].should == "dash berlin"
|
|
47
|
+
end
|
|
48
|
+
end # describe "#initialize"
|
|
49
|
+
|
|
50
|
+
|
|
51
|
+
|
|
52
|
+
describe "#update" do
|
|
53
|
+
it 'converts all keys into strings when param is a Hash' do
|
|
54
|
+
mash = subject.new(@hash)
|
|
55
|
+
mash.update("starry" => "night")
|
|
56
|
+
|
|
57
|
+
mash.keys.any? { |key| key.is_a?(Symbol) }.should be(false)
|
|
58
|
+
end
|
|
59
|
+
|
|
60
|
+
it 'converts all Hash values into Mashes if param is a Hash' do
|
|
61
|
+
mash = subject.new :hash => @hash
|
|
62
|
+
mash.update(:hash => { :hash => "is buggy in Ruby 1.8.6" })
|
|
63
|
+
|
|
64
|
+
mash["hash"].should be_an_instance_of(subject)
|
|
65
|
+
end
|
|
66
|
+
end # describe "#update"
|
|
67
|
+
|
|
68
|
+
|
|
69
|
+
|
|
70
|
+
describe "#[]=" do
|
|
71
|
+
it 'converts key into string' do
|
|
72
|
+
mash = subject.new(@hash)
|
|
73
|
+
mash[:hash] = { "starry" => "night" }
|
|
74
|
+
|
|
75
|
+
mash.keys.any? { |key| key.is_a?(Symbol) }.should be(false)
|
|
76
|
+
end
|
|
77
|
+
|
|
78
|
+
it 'converts all Hash value into subject' do
|
|
79
|
+
mash = subject.new :hash => @hash
|
|
80
|
+
mash[:hash] = { :hash => "is buggy in Ruby 1.8.6" }
|
|
81
|
+
|
|
82
|
+
mash["hash"].should be_an_instance_of(subject)
|
|
83
|
+
end
|
|
84
|
+
end # describe "#[]="
|
|
85
|
+
|
|
86
|
+
|
|
87
|
+
|
|
88
|
+
describe "#key?" do
|
|
89
|
+
before(:each) do
|
|
90
|
+
@mash = subject.new(@hash)
|
|
91
|
+
end
|
|
92
|
+
|
|
93
|
+
it 'converts key before lookup' do
|
|
94
|
+
@mash.key?("mash").should be(true)
|
|
95
|
+
@mash.key?(:mash).should be(true)
|
|
96
|
+
|
|
97
|
+
@mash.key?("hash").should be(true)
|
|
98
|
+
@mash.key?(:hash).should be(true)
|
|
99
|
+
|
|
100
|
+
@mash.key?(:rainclouds).should be(false)
|
|
101
|
+
@mash.key?("rainclouds").should be(false)
|
|
102
|
+
end
|
|
103
|
+
|
|
104
|
+
it 'is aliased as include?' do
|
|
105
|
+
@mash.include?("mash").should be(true)
|
|
106
|
+
@mash.include?(:mash).should be(true)
|
|
107
|
+
|
|
108
|
+
@mash.include?("hash").should be(true)
|
|
109
|
+
@mash.include?(:hash).should be(true)
|
|
110
|
+
|
|
111
|
+
@mash.include?(:rainclouds).should be(false)
|
|
112
|
+
@mash.include?("rainclouds").should be(false)
|
|
113
|
+
end
|
|
114
|
+
|
|
115
|
+
it 'is aliased as member?' do
|
|
116
|
+
@mash.member?("mash").should be(true)
|
|
117
|
+
@mash.member?(:mash).should be(true)
|
|
118
|
+
|
|
119
|
+
@mash.member?("hash").should be(true)
|
|
120
|
+
@mash.member?(:hash).should be(true)
|
|
121
|
+
|
|
122
|
+
@mash.member?(:rainclouds).should be(false)
|
|
123
|
+
@mash.member?("rainclouds").should be(false)
|
|
124
|
+
end
|
|
125
|
+
end # describe "#key?"
|
|
126
|
+
|
|
127
|
+
|
|
128
|
+
describe "#dup" do
|
|
129
|
+
it 'returns instance of subject' do
|
|
130
|
+
subject.new(@hash).dup.should be_an_instance_of(subject)
|
|
131
|
+
end
|
|
132
|
+
|
|
133
|
+
it 'preserves keys' do
|
|
134
|
+
mash = subject.new(@hash)
|
|
135
|
+
dup = mash.dup
|
|
136
|
+
|
|
137
|
+
mash.keys.sort.should == dup.keys.sort
|
|
138
|
+
end
|
|
139
|
+
|
|
140
|
+
it 'preserves value' do
|
|
141
|
+
mash = subject.new(@hash)
|
|
142
|
+
dup = mash.dup
|
|
143
|
+
|
|
144
|
+
mash.values.sort.should == dup.values.sort
|
|
145
|
+
end
|
|
146
|
+
end
|
|
147
|
+
|
|
148
|
+
|
|
149
|
+
|
|
150
|
+
describe "#to_hash" do
|
|
151
|
+
it 'returns instance of subject' do
|
|
152
|
+
subject.new(@hash).to_hash.should be_an_instance_of(Hash)
|
|
153
|
+
end
|
|
154
|
+
|
|
155
|
+
it 'preserves keys' do
|
|
156
|
+
mash = subject.new(@hash)
|
|
157
|
+
converted = mash.to_hash
|
|
158
|
+
|
|
159
|
+
mash.keys.sort.should == converted.keys.sort
|
|
160
|
+
end
|
|
161
|
+
|
|
162
|
+
it 'preserves value' do
|
|
163
|
+
mash = subject.new(@hash)
|
|
164
|
+
converted = mash.to_hash
|
|
165
|
+
|
|
166
|
+
mash.values.sort.should == converted.values.sort
|
|
167
|
+
end
|
|
168
|
+
end
|
|
169
|
+
|
|
170
|
+
|
|
171
|
+
|
|
172
|
+
describe "#symbolize_keys" do
|
|
173
|
+
it 'returns instance of subject' do
|
|
174
|
+
subject.new(@hash).symbolize_keys.should be_an_instance_of(Hash)
|
|
175
|
+
end
|
|
176
|
+
|
|
177
|
+
it 'converts keys to symbols' do
|
|
178
|
+
mash = subject.new(@hash)
|
|
179
|
+
converted = mash.symbolize_keys
|
|
180
|
+
|
|
181
|
+
converted_keys = converted.keys.sort{|k1, k2| k1.to_s <=> k2.to_s}
|
|
182
|
+
orig_keys = mash.keys.map{|k| k.to_sym}.sort{|i1, i2| i1.to_s <=> i2.to_s}
|
|
183
|
+
|
|
184
|
+
converted_keys.should == orig_keys
|
|
185
|
+
end
|
|
186
|
+
|
|
187
|
+
it 'preserves value' do
|
|
188
|
+
mash = subject.new(@hash)
|
|
189
|
+
converted = mash.symbolize_keys
|
|
190
|
+
|
|
191
|
+
mash.values.sort.should == converted.values.sort
|
|
192
|
+
end
|
|
193
|
+
end
|
|
194
|
+
|
|
195
|
+
|
|
196
|
+
|
|
197
|
+
describe "#delete" do
|
|
198
|
+
it 'converts Symbol key into String before deleting' do
|
|
199
|
+
mash = subject.new(@hash)
|
|
200
|
+
|
|
201
|
+
mash.delete(:hash)
|
|
202
|
+
mash.key?("hash").should be(false)
|
|
203
|
+
end
|
|
204
|
+
|
|
205
|
+
it 'works with String keys as well' do
|
|
206
|
+
mash = subject.new(@hash)
|
|
207
|
+
|
|
208
|
+
mash.delete("mash")
|
|
209
|
+
mash.key?("mash").should be(false)
|
|
210
|
+
end
|
|
211
|
+
end
|
|
212
|
+
|
|
213
|
+
|
|
214
|
+
|
|
215
|
+
describe "#except" do
|
|
216
|
+
it "converts Symbol key into String before calling super" do
|
|
217
|
+
mash = subject.new(@hash)
|
|
218
|
+
|
|
219
|
+
hashless_mash = mash.except(:hash)
|
|
220
|
+
hashless_mash.key?("hash").should be(false)
|
|
221
|
+
end
|
|
222
|
+
|
|
223
|
+
it "works with String keys as well" do
|
|
224
|
+
mash = subject.new(@hash)
|
|
225
|
+
|
|
226
|
+
mashless_mash = mash.except("mash")
|
|
227
|
+
mashless_mash.key?("mash").should be(false)
|
|
228
|
+
end
|
|
229
|
+
|
|
230
|
+
it "works with multiple keys" do
|
|
231
|
+
mash = subject.new(@hash)
|
|
232
|
+
|
|
233
|
+
mashless = mash.except("hash", :mash)
|
|
234
|
+
mashless.key?(:hash).should be(false)
|
|
235
|
+
mashless.key?("mash").should be(false)
|
|
236
|
+
end
|
|
237
|
+
|
|
238
|
+
it "should return a mash" do
|
|
239
|
+
mash = subject.new(@hash)
|
|
240
|
+
|
|
241
|
+
hashless_mash = mash.except(:hash)
|
|
242
|
+
hashless_mash.class.should be(subject)
|
|
243
|
+
end
|
|
244
|
+
end
|
|
245
|
+
|
|
246
|
+
|
|
247
|
+
|
|
248
|
+
describe "#merge" do
|
|
249
|
+
before(:each) do
|
|
250
|
+
@mash = subject.new(@hash).merge(:no => "in between")
|
|
251
|
+
end
|
|
252
|
+
|
|
253
|
+
it 'returns instance of subject' do
|
|
254
|
+
@mash.should be_an_instance_of(subject)
|
|
255
|
+
end
|
|
256
|
+
|
|
257
|
+
it 'merges in give Hash' do
|
|
258
|
+
@mash["no"].should == "in between"
|
|
259
|
+
end
|
|
260
|
+
end
|
|
261
|
+
|
|
262
|
+
|
|
263
|
+
|
|
264
|
+
describe "#fetch" do
|
|
265
|
+
before(:each) do
|
|
266
|
+
@mash = subject.new(@hash).merge(:no => "in between")
|
|
267
|
+
end
|
|
268
|
+
|
|
269
|
+
it 'converts key before fetching' do
|
|
270
|
+
@mash.fetch("no").should == "in between"
|
|
271
|
+
end
|
|
272
|
+
|
|
273
|
+
it 'returns alternative value if key lookup fails' do
|
|
274
|
+
@mash.fetch("flying", "screwdriver").should == "screwdriver"
|
|
275
|
+
end
|
|
276
|
+
end
|
|
277
|
+
|
|
278
|
+
|
|
279
|
+
describe "#default" do
|
|
280
|
+
before(:each) do
|
|
281
|
+
@mash = subject.new(:yet_another_technical_revolution)
|
|
282
|
+
end
|
|
283
|
+
|
|
284
|
+
it 'returns default value unless key exists in mash' do
|
|
285
|
+
@mash.default("peak oil is now behind, baby").should == :yet_another_technical_revolution
|
|
286
|
+
end
|
|
287
|
+
|
|
288
|
+
it 'returns existing value if key is Symbol and exists in mash' do
|
|
289
|
+
@mash.update(:no => "in between")
|
|
290
|
+
@mash.default(:no).should == "in between"
|
|
291
|
+
end
|
|
292
|
+
end
|
|
293
|
+
|
|
294
|
+
|
|
295
|
+
describe "#values_at" do
|
|
296
|
+
before(:each) do
|
|
297
|
+
@mash = subject.new(@hash).merge(:no => "in between")
|
|
298
|
+
end
|
|
299
|
+
|
|
300
|
+
it 'is indifferent to whether keys are strings or symbols' do
|
|
301
|
+
@mash.values_at("hash", :mash, :no).should == ["different", "indifferent", "in between"]
|
|
302
|
+
end
|
|
303
|
+
end
|
|
304
|
+
|
|
305
|
+
|
|
306
|
+
describe "#stringify_keys!" do
|
|
307
|
+
it 'returns the mash itself' do
|
|
308
|
+
mash = subject.new(@hash)
|
|
309
|
+
|
|
310
|
+
mash.stringify_keys!.object_id.should == mash.object_id
|
|
311
|
+
end
|
|
312
|
+
end
|
|
313
|
+
end
|
metadata
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
|
2
2
|
name: right_support
|
|
3
3
|
version: !ruby/object:Gem::Version
|
|
4
|
-
version: 2.8.
|
|
4
|
+
version: 2.8.31
|
|
5
5
|
platform: ruby
|
|
6
6
|
authors:
|
|
7
7
|
- Tony Spataro
|
|
@@ -13,7 +13,7 @@ authors:
|
|
|
13
13
|
autorequire:
|
|
14
14
|
bindir: bin
|
|
15
15
|
cert_chain: []
|
|
16
|
-
date: 2014-09-
|
|
16
|
+
date: 2014-09-25 00:00:00.000000000 Z
|
|
17
17
|
dependencies: []
|
|
18
18
|
description: A toolkit of useful, reusable foundation code created by RightScale.
|
|
19
19
|
email: support@rightscale.com
|
|
@@ -57,6 +57,7 @@ files:
|
|
|
57
57
|
- lib/right_support/crypto/signed_hash.rb
|
|
58
58
|
- lib/right_support/data.rb
|
|
59
59
|
- lib/right_support/data/hash_tools.rb
|
|
60
|
+
- lib/right_support/data/mash.rb
|
|
60
61
|
- lib/right_support/data/serializer.rb
|
|
61
62
|
- lib/right_support/data/unknown_type.rb
|
|
62
63
|
- lib/right_support/data/uuid.rb
|
|
@@ -104,6 +105,7 @@ files:
|
|
|
104
105
|
- spec/config/feature_set_spec.rb
|
|
105
106
|
- spec/crypto/signed_hash_spec.rb
|
|
106
107
|
- spec/data/hash_tools_spec.rb
|
|
108
|
+
- spec/data/mash_spec.rb
|
|
107
109
|
- spec/data/uuid_spec.rb
|
|
108
110
|
- spec/db/cassandra_model_part1_spec.rb
|
|
109
111
|
- spec/db/cassandra_model_part2_spec.rb
|