hashery 2.0.1 → 2.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.
- data/{.ruby → .meta} +3 -3
- data/HISTORY.rdoc +28 -5
- data/README.rdoc +23 -12
- data/alt/hashery/basicobject.rb +1 -0
- data/alt/hashery/castinghash.rb +1 -0
- data/alt/hashery/fuzzyhash.rb +1 -0
- data/alt/hashery/keyhash.rb +1 -0
- data/alt/hashery/linkedlist.rb +1 -0
- data/alt/hashery/lruhash.rb +1 -0
- data/alt/hashery/opencascade.rb +1 -0
- data/alt/hashery/openhash.rb +1 -0
- data/alt/hashery/orderedhash.rb +1 -0
- data/alt/hashery/propertyhash.rb +1 -0
- data/alt/hashery/queryhash.rb +1 -0
- data/alt/hashery/statichash.rb +1 -0
- data/lib/hashery.rb +4 -0
- data/lib/hashery.yml +3 -3
- data/lib/hashery/core_ext.rb +13 -4
- data/lib/hashery/crud_hash.rb +60 -20
- data/lib/hashery/dictionary.rb +30 -13
- data/lib/hashery/open_cascade.rb +12 -7
- data/lib/hashery/open_hash.rb +14 -12
- data/lib/hashery/property_hash.rb +1 -1
- data/lib/hashery/static_hash.rb +1 -1
- data/test/case_dictionary.rb +2 -0
- metadata +123 -65
- data/Config.rb +0 -28
data/{.ruby → .meta}
RENAMED
@@ -1,6 +1,6 @@
|
|
1
1
|
---
|
2
2
|
source:
|
3
|
-
-
|
3
|
+
- METADATA
|
4
4
|
authors:
|
5
5
|
- name: Trans
|
6
6
|
email: transfire@gmail.com
|
@@ -72,5 +72,5 @@ description: ! 'The Hashery is a tight collection of Hash-like classes. Included
|
|
72
72
|
of the CRUDHash which defines a CRUD model on top of Ruby''s standard Hash
|
73
73
|
|
74
74
|
making it a snap to subclass and augment to fit any specific use case.'
|
75
|
-
version: 2.0
|
76
|
-
date: '2012-
|
75
|
+
version: 2.1.0
|
76
|
+
date: '2012-11-24'
|
data/HISTORY.rdoc
CHANGED
@@ -1,5 +1,28 @@
|
|
1
1
|
= RELEASE HISTORY
|
2
2
|
|
3
|
+
== 2.1.0 / 2012-11-24
|
4
|
+
|
5
|
+
The major change of the 2.1 release is to switch over to `Hash#fetch`
|
6
|
+
as the fundamental CRUD read method inplace of the previous `#read` core
|
7
|
+
extension (an alias of `#[]`). This is a pretty fundamental change which
|
8
|
+
required modification of a number of classes. So please do extra-diligence
|
9
|
+
and file an issue if you experience any problems.
|
10
|
+
|
11
|
+
In addition, the Hash#read core extension has been renamed to Hash#retrieve
|
12
|
+
to avoid any possible confusion with IO objects. This release also fixes
|
13
|
+
a couple of issues with 1.8 compatibility and makes a few other small
|
14
|
+
enhancements.
|
15
|
+
|
16
|
+
Changes:
|
17
|
+
|
18
|
+
* Rename Hash#read to Hash#retrieve.
|
19
|
+
* Deprecate `Dictionary.alpha` in favor of `Dictionary.alphabetic`.
|
20
|
+
* Add support for block argument in Dictionary#order_by_key and #order_by_value.
|
21
|
+
* Fix OpenHash issues with Ruby 1.8.x compatibility.
|
22
|
+
* OpenHash methods are opened up via `protected` instead of `private`.
|
23
|
+
* Change OpenCascade to auto-create the subclass when inherited.
|
24
|
+
|
25
|
+
|
3
26
|
== 2.0.1 / 2012-07-06
|
4
27
|
|
5
28
|
This minor release fixes an issue with OpenCascade (#13).
|
@@ -7,7 +30,7 @@ The key_proc procedure wasn't being passed along to sub-cascades.
|
|
7
30
|
|
8
31
|
Changes:
|
9
32
|
|
10
|
-
* OpenCascade passes along key_proc to
|
33
|
+
* OpenCascade passes along key_proc to children.
|
11
34
|
|
12
35
|
|
13
36
|
== 2.0.0 / 2012-05-11
|
@@ -49,7 +72,7 @@ Changes:
|
|
49
72
|
|
50
73
|
== 1.5.0 / 2011-11-10
|
51
74
|
|
52
|
-
In this release, CoreExt module has been
|
75
|
+
In this release, CoreExt module has been added to encapsulate
|
53
76
|
methods that extend Ruby's core Hash class (there are only a few).
|
54
77
|
Presently these are only loaded when using `require 'hashery'`.
|
55
78
|
If you are cherry-picking from Hashery but still want the core
|
@@ -69,7 +92,7 @@ Changes:
|
|
69
92
|
|
70
93
|
This release includes a copy of Ruby Facets' BasicObject class, which
|
71
94
|
fixes the loading bug of the previous version. This release also renames
|
72
|
-
OpenObject to BasicStruct, which is a much better
|
95
|
+
OpenObject to BasicStruct, which is a much better description of what the
|
73
96
|
class actually provides.
|
74
97
|
|
75
98
|
Changes:
|
@@ -96,7 +119,7 @@ Changes:
|
|
96
119
|
|
97
120
|
== 1.2.0 / 2010-06-04
|
98
121
|
|
99
|
-
This release makes two
|
122
|
+
This release makes two significant changes to the Hashery.
|
100
123
|
First, we have a new shiny library called FuzzyHash by
|
101
124
|
Joshua Hull. It's a cool idea that allows hash keys to be
|
102
125
|
regular expressions. Secondly, OpenCascade is now a subclass
|
@@ -123,7 +146,7 @@ entries, but they each belong in a unique way. An Association
|
|
123
146
|
is akin to a single entry Hash --it represents a pairing.
|
124
147
|
While a SpareArray, though compatible with the Array class,
|
125
148
|
is completely under-pinned by a Hash in order to make it
|
126
|
-
|
149
|
+
efficient when no entries are given for a set of indexes,
|
127
150
|
hence "sparse".
|
128
151
|
|
129
152
|
Changes:
|
data/README.rdoc
CHANGED
@@ -13,25 +13,31 @@
|
|
13
13
|
|
14
14
|
Among Ruby Facets most common additions were an assortment
|
15
15
|
of Hash-like classes. To better support this collection
|
16
|
-
of libraries it was deemed prudent to create a
|
17
|
-
specifically for them. Hence the
|
16
|
+
of libraries it was deemed prudent to create a new project
|
17
|
+
specifically for them. Hence the *Facets* Hashery.
|
18
18
|
|
19
19
|
Included in this collection are the widely used OrderedHash,
|
20
20
|
the related but more featured Dictionary class, a number
|
21
|
-
of _open_ classes
|
22
|
-
|
21
|
+
of _open_ classes similar to the standard OpenStruct,
|
22
|
+
some variations of the standard Hash class and a few
|
23
23
|
other yummy morsels.
|
24
24
|
|
25
25
|
|
26
|
-
==
|
26
|
+
== HOW TO USE
|
27
27
|
|
28
|
-
|
28
|
+
For usage information, see the individual library files included
|
29
|
+
in this collection and read the demo documents which give
|
30
|
+
examples of almost all features.
|
29
31
|
|
30
32
|
|
31
|
-
==
|
33
|
+
== CORE EXTENSIONS
|
32
34
|
|
33
|
-
|
34
|
-
|
35
|
+
Hashery adds four core extensions of Ruby's Hash class: `#retrieve`,
|
36
|
+
`#rekey`, `#rekey!` and `Hash.create`. The first is simply an alias
|
37
|
+
for `#[]`. The later two have proven too useful over the years to
|
38
|
+
omit. And the last is a convenience class method for populating
|
39
|
+
a new hash with another hash upon initialization. All of these are
|
40
|
+
sorely missing for Ruby itself, which is why they are provided here.
|
35
41
|
|
36
42
|
|
37
43
|
== HOW TO INSTALL
|
@@ -72,7 +78,7 @@ Run the QED specs via:
|
|
72
78
|
$ qed -Ilib demo/
|
73
79
|
|
74
80
|
Lemon is used to create low-level unit tests. Run these via the
|
75
|
-
RubyTest
|
81
|
+
RubyTest universal test harness.
|
76
82
|
|
77
83
|
$ rubytest -Ilib test/
|
78
84
|
|
@@ -90,7 +96,12 @@ so I won't bug you with it yet again.
|
|
90
96
|
Yes, we FOSS programmers need to eat too! ;-) No seriously, any help you can
|
91
97
|
offer goes a long way toward continued development of Rubyworks projects,
|
92
98
|
including Hashery. See the upper right-hand corner on the
|
93
|
-
Rubyworks[http://rubyworks.github.com]
|
99
|
+
Rubyworks[http://rubyworks.github.com] homepage. Thanks.
|
100
|
+
|
101
|
+
|
102
|
+
== RELEASE NOTES
|
103
|
+
|
104
|
+
Please see the HISTORY file.
|
94
105
|
|
95
106
|
|
96
107
|
== COPYRIGHTS
|
@@ -103,5 +114,5 @@ See COPYING.rdoc file for further details.
|
|
103
114
|
|
104
115
|
Some libraries included in the Hashery have special copyrights
|
105
116
|
attributing specific authors. Please see each library script for
|
106
|
-
specifics and the
|
117
|
+
specifics and the NOTICE.txt file for an overview.
|
107
118
|
|
@@ -0,0 +1 @@
|
|
1
|
+
require 'hasery/basic_object'
|
@@ -0,0 +1 @@
|
|
1
|
+
require 'hashery/casting_hash'
|
@@ -0,0 +1 @@
|
|
1
|
+
require 'hashery/fuzzy_hash'
|
@@ -0,0 +1 @@
|
|
1
|
+
require 'hashery/key_hash'
|
@@ -0,0 +1 @@
|
|
1
|
+
require 'hashery/linked_list'
|
@@ -0,0 +1 @@
|
|
1
|
+
require 'hashery/lru_hash'
|
@@ -0,0 +1 @@
|
|
1
|
+
require 'hashery/open_cascade'
|
@@ -0,0 +1 @@
|
|
1
|
+
require 'hashery/open_hash'
|
@@ -0,0 +1 @@
|
|
1
|
+
require 'hashery/ordered_hash'
|
@@ -0,0 +1 @@
|
|
1
|
+
require 'hashery/property_hash'
|
@@ -0,0 +1 @@
|
|
1
|
+
require 'hashery/query_hash'
|
@@ -0,0 +1 @@
|
|
1
|
+
require 'hashery/static_hash'
|
data/lib/hashery.rb
CHANGED
data/lib/hashery.yml
CHANGED
@@ -1,6 +1,6 @@
|
|
1
1
|
---
|
2
2
|
source:
|
3
|
-
-
|
3
|
+
- METADATA
|
4
4
|
authors:
|
5
5
|
- name: Trans
|
6
6
|
email: transfire@gmail.com
|
@@ -72,5 +72,5 @@ description: ! 'The Hashery is a tight collection of Hash-like classes. Included
|
|
72
72
|
of the CRUDHash which defines a CRUD model on top of Ruby''s standard Hash
|
73
73
|
|
74
74
|
making it a snap to subclass and augment to fit any specific use case.'
|
75
|
-
version: 2.0
|
76
|
-
date: '2012-
|
75
|
+
version: 2.1.0
|
76
|
+
date: '2012-11-24'
|
data/lib/hashery/core_ext.rb
CHANGED
@@ -15,21 +15,30 @@ class Hash
|
|
15
15
|
end
|
16
16
|
|
17
17
|
#
|
18
|
-
#
|
18
|
+
# Like #fetch but returns the results of calling `default_proc`, if defined,
|
19
|
+
# otherwise `default`.
|
19
20
|
#
|
20
|
-
|
21
|
+
# key - Hash key to lookup.
|
22
|
+
#
|
23
|
+
# Returns value of Hash entry or `nil`.
|
24
|
+
#
|
25
|
+
def retrieve(key)
|
26
|
+
fetch(key, default_proc ? default_proc[self, key] : default)
|
27
|
+
end
|
21
28
|
|
22
29
|
#
|
23
30
|
# Convert to Hash.
|
24
31
|
#
|
25
32
|
def to_hash
|
26
33
|
dup # -or- `h = {}; each{ |k,v| h[k] = v }; h` ?
|
27
|
-
end
|
34
|
+
end \
|
35
|
+
unless method_defined?(:to_hash)
|
28
36
|
|
29
37
|
#
|
30
38
|
# For a Hash, `#to_h` is the same as `#to_hash`.
|
31
39
|
#
|
32
|
-
alias :to_h :to_hash
|
40
|
+
alias :to_h :to_hash \
|
41
|
+
unless method_defined?(:to_h)
|
33
42
|
|
34
43
|
#
|
35
44
|
# Synonym for Hash#rekey, but modifies the receiver in place (and returns it).
|
data/lib/hashery/crud_hash.rb
CHANGED
@@ -12,8 +12,28 @@ module Hashery
|
|
12
12
|
# In addition to the CRUD features, CRUDHash supports a `#key_proc`, akin to
|
13
13
|
# `#default_proc`, that can be used to normalize keys.
|
14
14
|
#
|
15
|
+
# The CRUD methods are:
|
16
|
+
#
|
17
|
+
# * key?
|
18
|
+
# * fetch
|
19
|
+
# * store
|
20
|
+
# * delete
|
21
|
+
#
|
22
|
+
# In addition to these main methods, there are these supporting "CRUD" methods:
|
23
|
+
#
|
24
|
+
# * default
|
25
|
+
# * default_proc
|
26
|
+
# * default_proc=
|
27
|
+
# * key_proc
|
28
|
+
# * key_proc=
|
29
|
+
#
|
15
30
|
class CRUDHash < ::Hash
|
16
31
|
|
32
|
+
#
|
33
|
+
# Dummy object for null arguments.
|
34
|
+
#
|
35
|
+
NA = Object.new
|
36
|
+
|
17
37
|
#
|
18
38
|
# This method is overridden to ensure that new entries pass through
|
19
39
|
# the `#store` method.
|
@@ -112,14 +132,19 @@ module Hashery
|
|
112
132
|
end
|
113
133
|
|
114
134
|
#
|
115
|
-
# CRUD method for
|
135
|
+
# CRUD method for read. This method gets the value for a given key.
|
136
|
+
# An error is raised if the key is not present, but an optional argument
|
137
|
+
# can be provided to be returned instead.
|
116
138
|
#
|
117
|
-
# key
|
139
|
+
# key - Hash key to lookup.
|
140
|
+
# default - Value to return if key is not present.
|
118
141
|
#
|
119
|
-
#
|
142
|
+
# Raises KeyError when key is not found and default has not been given.
|
120
143
|
#
|
121
|
-
|
122
|
-
|
144
|
+
# Returns the `Object` that is the Hash entry's value.
|
145
|
+
#
|
146
|
+
def fetch(key, *default)
|
147
|
+
super(cast_key(key), *default)
|
123
148
|
end
|
124
149
|
|
125
150
|
#
|
@@ -145,16 +170,38 @@ module Hashery
|
|
145
170
|
super cast_key(key)
|
146
171
|
end
|
147
172
|
|
173
|
+
# END OF CRUD METHODS
|
174
|
+
|
148
175
|
#
|
149
|
-
# Like #
|
176
|
+
# Like #fetch but returns the results of calling `default_proc`, if defined,
|
177
|
+
# otherwise `default`.
|
150
178
|
#
|
151
179
|
# key - Hash key to lookup.
|
152
180
|
#
|
153
|
-
# Returns
|
181
|
+
# Returns value of Hash entry or `nil`.
|
182
|
+
#
|
183
|
+
def retrieve(key)
|
184
|
+
if key?(key)
|
185
|
+
fetch(key)
|
186
|
+
else
|
187
|
+
default_proc ? default_proc.call(self, key) : default
|
188
|
+
end
|
189
|
+
end
|
190
|
+
|
191
|
+
#
|
192
|
+
# Method for reading value. Returns `nil` if key is not present.
|
154
193
|
#
|
155
|
-
|
156
|
-
|
157
|
-
|
194
|
+
# Note that this method used to be the CRUD method instead of #retrieve. Complaints about
|
195
|
+
# #read being indicative of an IO object (though in my opinion that is a bad asumption) have
|
196
|
+
# led to this method's deprecation.
|
197
|
+
#
|
198
|
+
# key - Hash key to lookup.
|
199
|
+
#
|
200
|
+
# Returns value of Hash entry.
|
201
|
+
#
|
202
|
+
def read(key)
|
203
|
+
warn "The #read method as been deprecated. Use #retrieve instead."
|
204
|
+
retrieve(key)
|
158
205
|
end
|
159
206
|
|
160
207
|
#
|
@@ -178,21 +225,14 @@ module Hashery
|
|
178
225
|
end
|
179
226
|
|
180
227
|
#
|
181
|
-
# Operator for `#
|
228
|
+
# Operator for `#retrieve`.
|
182
229
|
#
|
183
230
|
# key - Index key to lookup.
|
184
231
|
#
|
185
232
|
# Returns `Object` value of key.
|
186
233
|
#
|
187
234
|
def [](key)
|
188
|
-
|
189
|
-
# fetch(key)
|
190
|
-
#elsif default_proc
|
191
|
-
# default_proc.call(self, key)
|
192
|
-
#else
|
193
|
-
# default
|
194
|
-
#end
|
195
|
-
read(key)
|
235
|
+
retrieve(key)
|
196
236
|
end
|
197
237
|
|
198
238
|
#
|
@@ -246,7 +286,7 @@ module Hashery
|
|
246
286
|
def each #:yield:
|
247
287
|
if block_given?
|
248
288
|
keys.each do |k|
|
249
|
-
yield(k,
|
289
|
+
yield(k, retrieve(k))
|
250
290
|
end
|
251
291
|
else
|
252
292
|
to_enum(:each)
|
data/lib/hashery/dictionary.rb
CHANGED
@@ -56,10 +56,14 @@ module Hashery
|
|
56
56
|
include Enumerable
|
57
57
|
|
58
58
|
class << self
|
59
|
-
#--
|
60
|
-
# TODO is this needed? Doesn't the super class do this?
|
61
|
-
#++
|
62
59
|
|
60
|
+
#
|
61
|
+
# Create a new Dictionary storing argument pairs as an initial mapping.
|
62
|
+
#
|
63
|
+
# TODO: Is this needed? Doesn't the super class do this?
|
64
|
+
#
|
65
|
+
# Returns Dictionary instance.
|
66
|
+
#
|
63
67
|
def [](*args)
|
64
68
|
hsh = new
|
65
69
|
if Hash === args[0]
|
@@ -75,16 +79,18 @@ module Hashery
|
|
75
79
|
end
|
76
80
|
|
77
81
|
#
|
78
|
-
# Like #new but the block sets the order.
|
82
|
+
# Like #new but the block sets the order instead of the default.
|
83
|
+
#
|
84
|
+
# Dictionary.new_by{ |k,v| k }
|
79
85
|
#
|
80
86
|
def new_by(*args, &blk)
|
81
87
|
new(*args).order_by(&blk)
|
82
88
|
end
|
83
89
|
|
84
90
|
#
|
85
|
-
# Alternate to #new which creates a dictionary sorted by key.
|
91
|
+
# Alternate to #new which creates a dictionary sorted by the key as a string.
|
86
92
|
#
|
87
|
-
# d = Dictionary.
|
93
|
+
# d = Dictionary.alphabetic
|
88
94
|
# d["z"] = 1
|
89
95
|
# d["y"] = 2
|
90
96
|
# d["x"] = 3
|
@@ -92,12 +98,15 @@ module Hashery
|
|
92
98
|
#
|
93
99
|
# This is equivalent to:
|
94
100
|
#
|
95
|
-
# Dictionary.new.order_by { |key,value| key }
|
96
|
-
|
97
|
-
def
|
98
|
-
new(*args, &block).
|
101
|
+
# Dictionary.new.order_by { |key,value| key.to_s }
|
102
|
+
#
|
103
|
+
def alphabetic(*args, &block)
|
104
|
+
new(*args, &block).order_by { |key,value| key.to_s }
|
99
105
|
end
|
100
106
|
|
107
|
+
# DEPRECATED: Use #alphabetic instead.
|
108
|
+
alias :alpha :alphabetic
|
109
|
+
|
101
110
|
#
|
102
111
|
# Alternate to #new which auto-creates sub-dictionaries as needed.
|
103
112
|
#
|
@@ -120,7 +129,7 @@ module Hashery
|
|
120
129
|
@order = []
|
121
130
|
@order_by = nil
|
122
131
|
if blk
|
123
|
-
dict = self # This
|
132
|
+
dict = self # This ensures automatic key entry effect the
|
124
133
|
oblk = lambda{ |hsh, key| blk[dict,key] } # dictionary rather then just the interal hash.
|
125
134
|
@hash = Hash.new(*args, &oblk)
|
126
135
|
else
|
@@ -169,7 +178,11 @@ module Hashery
|
|
169
178
|
# Returns +self+.
|
170
179
|
#
|
171
180
|
def order_by_key
|
172
|
-
|
181
|
+
if block_given?
|
182
|
+
@order_by = Proc.new{ |k,v| yield(k) }
|
183
|
+
else
|
184
|
+
@order_by = Proc.new{ |k,v| k }
|
185
|
+
end
|
173
186
|
order
|
174
187
|
self
|
175
188
|
end
|
@@ -188,7 +201,11 @@ module Hashery
|
|
188
201
|
# Dictionary.new.order_by { |key,value| value }
|
189
202
|
#
|
190
203
|
def order_by_value
|
191
|
-
|
204
|
+
if block_given?
|
205
|
+
@order_by = Proc.new{ |k,v| yield(v) }
|
206
|
+
else
|
207
|
+
@order_by = Proc.new{ |k,v| v }
|
208
|
+
end
|
192
209
|
order
|
193
210
|
self
|
194
211
|
end
|
data/lib/hashery/open_cascade.rb
CHANGED
@@ -43,6 +43,10 @@ module Hashery
|
|
43
43
|
#
|
44
44
|
# c.x!(4).y!(3) #=> #<OpenCascade:0x7fac3680ccf0 {:x=>4, :y=>3}>
|
45
45
|
#
|
46
|
+
# Subclassing OpenCascade with cause the new subclass to become the class that
|
47
|
+
# is auto-created. If this is not the behavior desired, consider using delegation
|
48
|
+
# instead of subclassing.
|
49
|
+
#
|
46
50
|
class OpenCascade < OpenHash
|
47
51
|
|
48
52
|
#
|
@@ -60,14 +64,14 @@ module Hashery
|
|
60
64
|
def initialize(*default)
|
61
65
|
@read = {}
|
62
66
|
|
63
|
-
leet = lambda { |h,k| h[k] =
|
67
|
+
leet = lambda { |h,k| h[k] = self.class.new(&leet) }
|
64
68
|
super(*default, &leet)
|
65
69
|
end
|
66
70
|
|
67
71
|
#
|
68
72
|
# Alias for original read method.
|
69
73
|
#
|
70
|
-
alias :
|
74
|
+
alias :retrieve! :retrieve
|
71
75
|
|
72
76
|
#
|
73
77
|
# Read value given a +key+.
|
@@ -76,11 +80,12 @@ module Hashery
|
|
76
80
|
#
|
77
81
|
# Returns value.
|
78
82
|
#
|
79
|
-
def
|
80
|
-
|
83
|
+
def retrieve(key)
|
84
|
+
ckey = cast_key(key)
|
85
|
+
if @read[ckey]
|
81
86
|
super(key)
|
82
87
|
else
|
83
|
-
@read[
|
88
|
+
@read[ckey] = store(key, cast_value(super(key)))
|
84
89
|
end
|
85
90
|
end
|
86
91
|
|
@@ -95,12 +100,12 @@ module Hashery
|
|
95
100
|
when '='
|
96
101
|
store(name, args.first)
|
97
102
|
when '?'
|
98
|
-
key?(name) ?
|
103
|
+
key?(name) ? retrieve!(name) : nil # key?(name)
|
99
104
|
when '!'
|
100
105
|
__send__(name, *args, &blk)
|
101
106
|
else
|
102
107
|
#if key?(name)
|
103
|
-
|
108
|
+
retrieve(name)
|
104
109
|
#else
|
105
110
|
# #default = OpenCascade.new #self.class.new
|
106
111
|
# #default = default_proc ? default_proc.call(self, name) : default
|
data/lib/hashery/open_hash.rb
CHANGED
@@ -41,6 +41,11 @@ module Hashery
|
|
41
41
|
#
|
42
42
|
attr_accessor :safe
|
43
43
|
|
44
|
+
#
|
45
|
+
# Alias to original store method.
|
46
|
+
#
|
47
|
+
#alias :store! :store
|
48
|
+
|
44
49
|
#
|
45
50
|
# Index `value` to `key`. Unless safe mode, will also open up the
|
46
51
|
# key if it is not already open.
|
@@ -51,7 +56,7 @@ module Hashery
|
|
51
56
|
# Returns +value+.
|
52
57
|
#
|
53
58
|
def store(key, value)
|
54
|
-
open!(key)
|
59
|
+
#open!(key)
|
55
60
|
super(key, value)
|
56
61
|
end
|
57
62
|
|
@@ -65,21 +70,19 @@ module Hashery
|
|
65
70
|
# Returns Array of slot names that were opened.
|
66
71
|
#
|
67
72
|
def open!(*methods)
|
68
|
-
#
|
73
|
+
# Only select string and symbols, any other type of key is allowed,
|
69
74
|
# it just won't be accessible via dynamic methods.
|
70
75
|
methods = methods.select{ |x| String === x || Symbol === x }
|
71
|
-
# @todo should we just ignore these instead of raising an error?
|
72
|
-
#methods.reject!{ |x| x.to_s =~ /^__/ }
|
73
76
|
if methods.any?{ |m| m.to_s.start_with?('__') }
|
74
|
-
raise ArgumentError, "cannot
|
77
|
+
raise ArgumentError, "cannot open shadow methods"
|
75
78
|
end
|
76
|
-
# only public methods need
|
79
|
+
# only public methods need be made protected
|
77
80
|
methods = methods.map{ |x| x.to_sym }
|
78
|
-
methods = methods & public_methods(true)
|
81
|
+
methods = methods & public_methods(true).map{ |x| x.to_sym }
|
79
82
|
if @safe
|
80
83
|
raise ArgumentError, "cannot set public method" unless methods.empty?
|
81
84
|
else
|
82
|
-
(class << self; self; end).class_eval{
|
85
|
+
(class << self; self; end).class_eval{ protected *methods }
|
83
86
|
end
|
84
87
|
methods
|
85
88
|
end
|
@@ -95,7 +98,8 @@ module Hashery
|
|
95
98
|
# Returns `true` or `false`.
|
96
99
|
#
|
97
100
|
def open?(method)
|
98
|
-
|
101
|
+
methods = public_methods(true).map{ |m| m.to_sym }
|
102
|
+
! methods.include?(method.to_sym)
|
99
103
|
end
|
100
104
|
|
101
105
|
#
|
@@ -120,8 +124,6 @@ module Hashery
|
|
120
124
|
|
121
125
|
case type
|
122
126
|
when '='
|
123
|
-
#open!(key) unless open?(key)
|
124
|
-
#self[key] = a.first
|
125
127
|
store(key, a.first)
|
126
128
|
when '?'
|
127
129
|
key?(key)
|
@@ -131,7 +133,7 @@ module Hashery
|
|
131
133
|
__send__(name, *a, &b)
|
132
134
|
else
|
133
135
|
#if key?(key)
|
134
|
-
|
136
|
+
retrieve(key)
|
135
137
|
#else
|
136
138
|
# super(s,*a,&b)
|
137
139
|
#end
|
data/lib/hashery/static_hash.rb
CHANGED
data/test/case_dictionary.rb
CHANGED
@@ -218,6 +218,7 @@ testcase Dictionary do
|
|
218
218
|
|
219
219
|
method :each_key do
|
220
220
|
d = Dictionary[:a=>1, :b=>2, :c=>3]
|
221
|
+
d.order_by_key
|
221
222
|
a = []
|
222
223
|
d.each_key{ |k| a << k }
|
223
224
|
a.assert == [:a, :b, :c]
|
@@ -225,6 +226,7 @@ testcase Dictionary do
|
|
225
226
|
|
226
227
|
method :each_value do
|
227
228
|
d = Dictionary[:a=>1, :b=>2, :c=>3]
|
229
|
+
d.order_by_value
|
228
230
|
a = []
|
229
231
|
d.each_value{ |v| a << v }
|
230
232
|
a.assert == [1, 2, 3]
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: hashery
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 2.0
|
4
|
+
version: 2.1.0
|
5
5
|
prerelease:
|
6
6
|
platform: ruby
|
7
7
|
authors:
|
@@ -15,11 +15,11 @@ authors:
|
|
15
15
|
autorequire:
|
16
16
|
bindir: bin
|
17
17
|
cert_chain: []
|
18
|
-
date: 2012-
|
18
|
+
date: 2012-11-25 00:00:00.000000000 Z
|
19
19
|
dependencies:
|
20
20
|
- !ruby/object:Gem::Dependency
|
21
21
|
name: detroit
|
22
|
-
requirement: !ruby/object:Gem::Requirement
|
22
|
+
requirement: &6389540 !ruby/object:Gem::Requirement
|
23
23
|
none: false
|
24
24
|
requirements:
|
25
25
|
- - ! '>='
|
@@ -27,15 +27,10 @@ dependencies:
|
|
27
27
|
version: '0'
|
28
28
|
type: :development
|
29
29
|
prerelease: false
|
30
|
-
version_requirements:
|
31
|
-
none: false
|
32
|
-
requirements:
|
33
|
-
- - ! '>='
|
34
|
-
- !ruby/object:Gem::Version
|
35
|
-
version: '0'
|
30
|
+
version_requirements: *6389540
|
36
31
|
- !ruby/object:Gem::Dependency
|
37
32
|
name: qed
|
38
|
-
requirement: !ruby/object:Gem::Requirement
|
33
|
+
requirement: &6373700 !ruby/object:Gem::Requirement
|
39
34
|
none: false
|
40
35
|
requirements:
|
41
36
|
- - ! '>='
|
@@ -43,15 +38,10 @@ dependencies:
|
|
43
38
|
version: '0'
|
44
39
|
type: :development
|
45
40
|
prerelease: false
|
46
|
-
version_requirements:
|
47
|
-
none: false
|
48
|
-
requirements:
|
49
|
-
- - ! '>='
|
50
|
-
- !ruby/object:Gem::Version
|
51
|
-
version: '0'
|
41
|
+
version_requirements: *6373700
|
52
42
|
- !ruby/object:Gem::Dependency
|
53
43
|
name: lemon
|
54
|
-
requirement: !ruby/object:Gem::Requirement
|
44
|
+
requirement: &6363300 !ruby/object:Gem::Requirement
|
55
45
|
none: false
|
56
46
|
requirements:
|
57
47
|
- - ! '>='
|
@@ -59,12 +49,7 @@ dependencies:
|
|
59
49
|
version: '0'
|
60
50
|
type: :development
|
61
51
|
prerelease: false
|
62
|
-
version_requirements:
|
63
|
-
none: false
|
64
|
-
requirements:
|
65
|
-
- - ! '>='
|
66
|
-
- !ruby/object:Gem::Version
|
67
|
-
version: '0'
|
52
|
+
version_requirements: *6363300
|
68
53
|
description: ! 'The Hashery is a tight collection of Hash-like classes. Included among
|
69
54
|
its many
|
70
55
|
|
@@ -80,55 +65,113 @@ email:
|
|
80
65
|
executables: []
|
81
66
|
extensions: []
|
82
67
|
extra_rdoc_files:
|
83
|
-
- NOTICE.txt
|
84
68
|
- LICENSE.txt
|
69
|
+
- NOTICE.txt
|
85
70
|
- HISTORY.rdoc
|
86
71
|
- DEMO.rdoc
|
87
72
|
- README.rdoc
|
88
73
|
files:
|
89
|
-
- .
|
74
|
+
- .meta
|
90
75
|
- .yardopts
|
91
|
-
-
|
92
|
-
|
93
|
-
-
|
94
|
-
|
95
|
-
-
|
96
|
-
|
97
|
-
-
|
98
|
-
|
99
|
-
-
|
100
|
-
|
101
|
-
-
|
102
|
-
|
103
|
-
-
|
104
|
-
|
105
|
-
-
|
106
|
-
|
107
|
-
-
|
108
|
-
|
109
|
-
-
|
110
|
-
|
111
|
-
-
|
112
|
-
|
113
|
-
-
|
114
|
-
|
115
|
-
-
|
116
|
-
|
117
|
-
-
|
118
|
-
|
119
|
-
-
|
120
|
-
|
121
|
-
-
|
122
|
-
|
123
|
-
-
|
124
|
-
|
125
|
-
-
|
76
|
+
- !binary |-
|
77
|
+
YWx0L2hhc2hlcnkva2V5aGFzaC5yYg==
|
78
|
+
- !binary |-
|
79
|
+
YWx0L2hhc2hlcnkvb3Blbmhhc2gucmI=
|
80
|
+
- !binary |-
|
81
|
+
YWx0L2hhc2hlcnkvYmFzaWNvYmplY3QucmI=
|
82
|
+
- !binary |-
|
83
|
+
YWx0L2hhc2hlcnkvcHJvcGVydHloYXNoLnJi
|
84
|
+
- !binary |-
|
85
|
+
YWx0L2hhc2hlcnkvbHJ1aGFzaC5yYg==
|
86
|
+
- !binary |-
|
87
|
+
YWx0L2hhc2hlcnkvY2FzdGluZ2hhc2gucmI=
|
88
|
+
- !binary |-
|
89
|
+
YWx0L2hhc2hlcnkvb3JkZXJlZGhhc2gucmI=
|
90
|
+
- !binary |-
|
91
|
+
YWx0L2hhc2hlcnkvZnV6enloYXNoLnJi
|
92
|
+
- !binary |-
|
93
|
+
YWx0L2hhc2hlcnkvcXVlcnloYXNoLnJi
|
94
|
+
- !binary |-
|
95
|
+
YWx0L2hhc2hlcnkvb3BlbmNhc2NhZGUucmI=
|
96
|
+
- !binary |-
|
97
|
+
YWx0L2hhc2hlcnkvc3RhdGljaGFzaC5yYg==
|
98
|
+
- !binary |-
|
99
|
+
YWx0L2hhc2hlcnkvbGlua2VkbGlzdC5yYg==
|
100
|
+
- !binary |-
|
101
|
+
bGliL2hhc2hlcnkueW1s
|
102
|
+
- !binary |-
|
103
|
+
bGliL2hhc2hlcnkucmI=
|
104
|
+
- !binary |-
|
105
|
+
bGliL2hhc2hlcnkvZnV6enlfaGFzaC5yYg==
|
106
|
+
- !binary |-
|
107
|
+
bGliL2hhc2hlcnkvcGF0aF9oYXNoLnJi
|
108
|
+
- !binary |-
|
109
|
+
bGliL2hhc2hlcnkvb3Blbl9jYXNjYWRlLnJi
|
110
|
+
- !binary |-
|
111
|
+
bGliL2hhc2hlcnkvYXNzb2NpYXRpb24ucmI=
|
112
|
+
- !binary |-
|
113
|
+
bGliL2hhc2hlcnkvbGlua2VkX2xpc3QucmI=
|
114
|
+
- !binary |-
|
115
|
+
bGliL2hhc2hlcnkvb3Blbl9oYXNoLnJi
|
116
|
+
- !binary |-
|
117
|
+
bGliL2hhc2hlcnkvZGljdGlvbmFyeS5yYg==
|
118
|
+
- !binary |-
|
119
|
+
bGliL2hhc2hlcnkva2V5X2hhc2gucmI=
|
120
|
+
- !binary |-
|
121
|
+
bGliL2hhc2hlcnkvY29yZV9leHQucmI=
|
122
|
+
- !binary |-
|
123
|
+
bGliL2hhc2hlcnkvc3RhdGljX2hhc2gucmI=
|
124
|
+
- !binary |-
|
125
|
+
bGliL2hhc2hlcnkvcXVlcnlfaGFzaC5yYg==
|
126
|
+
- !binary |-
|
127
|
+
bGliL2hhc2hlcnkvaW5pX2hhc2gucmI=
|
128
|
+
- !binary |-
|
129
|
+
bGliL2hhc2hlcnkvcHJvcGVydHlfaGFzaC5yYg==
|
130
|
+
- !binary |-
|
131
|
+
bGliL2hhc2hlcnkvb3JkZXJlZF9oYXNoLnJi
|
132
|
+
- !binary |-
|
133
|
+
bGliL2hhc2hlcnkvbHJ1X2hhc2gucmI=
|
134
|
+
- !binary |-
|
135
|
+
bGliL2hhc2hlcnkvY3J1ZF9oYXNoLnJi
|
136
|
+
- !binary |-
|
137
|
+
bGliL2hhc2hlcnkvc3Rhc2gucmI=
|
138
|
+
- !binary |-
|
139
|
+
bGliL2hhc2hlcnkvY2FzdGluZ19oYXNoLnJi
|
140
|
+
- !binary |-
|
141
|
+
dGVzdC9jYXNlX29wZW5fY2FzY2FkZS5yYg==
|
142
|
+
- !binary |-
|
143
|
+
dGVzdC9jYXNlX3F1ZXJ5X2hhc2gucmI=
|
144
|
+
- !binary |-
|
145
|
+
dGVzdC9oZWxwZXIucmI=
|
146
|
+
- !binary |-
|
147
|
+
dGVzdC9jYXNlX2NydWRfaGFzaC5yYg==
|
148
|
+
- !binary |-
|
149
|
+
dGVzdC9jYXNlX2xydV9oYXNoLnJi
|
150
|
+
- !binary |-
|
151
|
+
dGVzdC9jYXNlX2RpY3Rpb25hcnkucmI=
|
152
|
+
- !binary |-
|
153
|
+
dGVzdC9jYXNlX2luaV9oYXNoLnJi
|
154
|
+
- !binary |-
|
155
|
+
dGVzdC9jYXNlX2NvcmVfZXh0LnJi
|
156
|
+
- !binary |-
|
157
|
+
dGVzdC9jYXNlX29wZW5faGFzaC5yYg==
|
158
|
+
- !binary |-
|
159
|
+
dGVzdC9jYXNlX2tleV9oYXNoLnJi
|
160
|
+
- !binary |-
|
161
|
+
dGVzdC9jYXNlX2Fzc29jaWF0aW9uLnJi
|
162
|
+
- !binary |-
|
163
|
+
dGVzdC9jYXNlX3Byb3BlcnR5X2hhc2gucmI=
|
164
|
+
- !binary |-
|
165
|
+
dGVzdC9maXh0dXJlL2V4YW1wbGUuaW5p
|
166
|
+
- !binary |-
|
167
|
+
dGVzdC9jYXNlX2Nhc3RpbmdfaGFzaC5yYg==
|
168
|
+
- !binary |-
|
169
|
+
dGVzdC9jYXNlX2xpbmtlZF9saXN0LnJi
|
126
170
|
- HISTORY.rdoc
|
127
171
|
- DEMO.rdoc
|
128
|
-
- NOTICE.txt
|
129
|
-
- Config.rb
|
130
|
-
- README.rdoc
|
131
172
|
- LICENSE.txt
|
173
|
+
- README.rdoc
|
174
|
+
- NOTICE.txt
|
132
175
|
homepage: http://rubyworks.github.com/hashery
|
133
176
|
licenses:
|
134
177
|
- BSD-2-Clause
|
@@ -151,8 +194,23 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
151
194
|
version: '0'
|
152
195
|
requirements: []
|
153
196
|
rubyforge_project:
|
154
|
-
rubygems_version: 1.8.
|
197
|
+
rubygems_version: 1.8.11
|
155
198
|
signing_key:
|
156
199
|
specification_version: 3
|
157
200
|
summary: Facets-bread collection of Hash-like classes.
|
158
|
-
test_files:
|
201
|
+
test_files:
|
202
|
+
- test/case_open_cascade.rb
|
203
|
+
- test/case_query_hash.rb
|
204
|
+
- test/helper.rb
|
205
|
+
- test/case_crud_hash.rb
|
206
|
+
- test/case_lru_hash.rb
|
207
|
+
- test/case_dictionary.rb
|
208
|
+
- test/case_ini_hash.rb
|
209
|
+
- test/case_core_ext.rb
|
210
|
+
- test/case_open_hash.rb
|
211
|
+
- test/case_key_hash.rb
|
212
|
+
- test/case_association.rb
|
213
|
+
- test/case_property_hash.rb
|
214
|
+
- test/case_casting_hash.rb
|
215
|
+
- test/case_linked_list.rb
|
216
|
+
has_rdoc:
|
data/Config.rb
DELETED
@@ -1,28 +0,0 @@
|
|
1
|
-
config 'rubytest' do
|
2
|
-
$:.unshift 'test'
|
3
|
-
$:.unshift 'lib'
|
4
|
-
end
|
5
|
-
|
6
|
-
profile 'coverage' do
|
7
|
-
config 'rubytest' do
|
8
|
-
$:.unshift 'test'
|
9
|
-
$:.unshift 'lib'
|
10
|
-
|
11
|
-
require 'simplecov'
|
12
|
-
SimpleCov.command_name 'RubyTest'
|
13
|
-
SimpleCov.start do
|
14
|
-
add_filter '/test/'
|
15
|
-
add_filter '/lib/hashery/ordered_hash.rb'
|
16
|
-
coverage_dir 'log/coverage'
|
17
|
-
end
|
18
|
-
end
|
19
|
-
|
20
|
-
config 'qed' do
|
21
|
-
require 'simplecov'
|
22
|
-
SimpleCov.command_name 'QED'
|
23
|
-
SimpleCov.start do
|
24
|
-
add_filter '/demo/'
|
25
|
-
coverage_dir 'log/coverage'
|
26
|
-
end
|
27
|
-
end
|
28
|
-
end
|