hashery 1.1.0 → 1.2.0
Sign up to get free protection for your applications and to get access to all the features.
- data/HISTORY +22 -0
- data/README.rdoc +24 -9
- data/lib/hashery/dictionary.rb +12 -21
- data/lib/hashery/lruhash.rb +2 -3
- data/lib/hashery/opencascade.rb +28 -12
- data/lib/hashery/openhash.rb +12 -0
- data/lib/hashery/sparsearray.rb +21 -30
- metadata +13 -23
- data/meta/authors +0 -3
- data/meta/created +0 -1
- data/meta/description +0 -5
- data/meta/homepage +0 -1
- data/meta/license +0 -1
- data/meta/name +0 -1
- data/meta/release +0 -1
- data/meta/repository +0 -1
- data/meta/suite +0 -1
- data/meta/summary +0 -1
- data/meta/version +0 -1
data/HISTORY
CHANGED
@@ -1,5 +1,26 @@
|
|
1
1
|
= RELEASE HISTORY
|
2
2
|
|
3
|
+
== 1.2.0 // 2010-06-04
|
4
|
+
|
5
|
+
This release makes two signifficant changes to the Hashery.
|
6
|
+
First, we have a new shiny library called FuzzyHash by
|
7
|
+
Joshua Hull. It's a cool idea that allows hash keys to be
|
8
|
+
regular expressions. Secondly, OpenCascade is now a subclass
|
9
|
+
of OpenHash rather than OpenObject (to go along with the
|
10
|
+
changes of the last release), and it now support cascading
|
11
|
+
within Arrays.
|
12
|
+
|
13
|
+
Changes:
|
14
|
+
|
15
|
+
* 1 New Library
|
16
|
+
|
17
|
+
* FuzzyHash by Joshua Hull
|
18
|
+
|
19
|
+
* 1 Major Enhancement
|
20
|
+
|
21
|
+
* OpenCascade subclasses OpenHash and handles Array cascading.
|
22
|
+
|
23
|
+
|
3
24
|
== 1.1.0 // 2010-04-28
|
4
25
|
|
5
26
|
A follow-up release of Hashery that adds two new libraries:
|
@@ -34,3 +55,4 @@ diverge to target slightly different use cases.
|
|
34
55
|
Changes:
|
35
56
|
|
36
57
|
* Happy Birthday!
|
58
|
+
|
data/README.rdoc
CHANGED
@@ -1,19 +1,21 @@
|
|
1
|
-
=
|
1
|
+
= Hashery
|
2
2
|
|
3
3
|
* home: http://rubyworks.github.com/hashery
|
4
4
|
* work: http://github.com/rubyworks/hashery
|
5
5
|
|
6
|
+
|
6
7
|
== DESCRIPTION
|
7
8
|
|
8
9
|
Among Ruby Facets most common additions were an assortment
|
9
|
-
of Hash-like classes. To better support this collection
|
10
|
+
of Hash-like classes. To better support this collection
|
10
11
|
of libraries it was deemed prudent to create a side project
|
11
|
-
specifically for them. Hence the Facets Hashery.
|
12
|
+
specifically for them. Hence the "Facets" Hashery.
|
12
13
|
|
13
|
-
Included in this
|
14
|
+
Included in this collection are the widely used OrderedHash,
|
14
15
|
the related but more featured Dictionary class, a number
|
15
|
-
of _open_ classes,
|
16
|
-
|
16
|
+
of _open_ classes, similar to the standard OpenStruct,
|
17
|
+
plus a few variations of the standard Hash and a few
|
18
|
+
other yummy morsels.
|
17
19
|
|
18
20
|
|
19
21
|
== RELEASE NOTES
|
@@ -34,14 +36,27 @@ To install with RubyGems simply open a console and type:
|
|
34
36
|
$ sudo gem install hashery
|
35
37
|
|
36
38
|
Tarball packages are available for manual site installations
|
37
|
-
via
|
39
|
+
via {Ruby Setup}[http://proutils.github.com/setup].
|
38
40
|
|
39
41
|
|
40
42
|
== LICENSE
|
41
43
|
|
42
|
-
Copyright (c) 2005,2010 Thomas Sawyer
|
44
|
+
Copyright (c) 2005, 2010 Thomas Sawyer
|
43
45
|
|
44
|
-
This
|
46
|
+
This library is distributed under the terms of the MIT license.
|
45
47
|
|
46
48
|
See LICENSE file for details.
|
47
49
|
|
50
|
+
Some libraries included in the Hashery have special copyrights
|
51
|
+
attributing specific authors. Please see each file for details.
|
52
|
+
|
53
|
+
Contributing authors include:
|
54
|
+
|
55
|
+
* Kirk Haines
|
56
|
+
* Joshua Hull
|
57
|
+
* Robert Klemme
|
58
|
+
* Jan Molic
|
59
|
+
* George Moschovitis
|
60
|
+
* Jeena Paradies
|
61
|
+
* Erik Veenstra
|
62
|
+
|
data/lib/hashery/dictionary.rb
CHANGED
@@ -1,24 +1,3 @@
|
|
1
|
-
# = Dictionary.rb
|
2
|
-
#
|
3
|
-
# Copyright (c) 2005, 2009 Jan Molic, Thomas Sawyer
|
4
|
-
#
|
5
|
-
# Ruby License
|
6
|
-
#
|
7
|
-
# This module is free software. You may use, modify, and/or redistribute this
|
8
|
-
# software under the same terms as Ruby.
|
9
|
-
#
|
10
|
-
# This program is distributed in the hope that it will be useful, but WITHOUT
|
11
|
-
# ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
|
12
|
-
# FOR A PARTICULAR PURPOSE.
|
13
|
-
#
|
14
|
-
# == Acknowledgments
|
15
|
-
#
|
16
|
-
# * Andrew Johnson (merge, to_a, inspect, shift and Hash[])
|
17
|
-
# * Jeff Sharpe (reverse and reverse!)
|
18
|
-
# * Thomas Leitner (has_key? and key?)
|
19
|
-
#
|
20
|
-
# Ported from OrderHash 2.0, Copyright (c) 2005 Jan Molic
|
21
|
-
|
22
1
|
# = Dictionary
|
23
2
|
#
|
24
3
|
# The Dictionary class is a Hash that preserves order.
|
@@ -62,6 +41,18 @@
|
|
62
41
|
# * Use ::auto which creates Dictionay sub-entries as needed.
|
63
42
|
# * And ::alpha which creates a new Dictionary sorted by key.
|
64
43
|
#
|
44
|
+
# == Acknowledgments
|
45
|
+
#
|
46
|
+
# Dictionary is a ported of OrderHash 2.0 Copyright (c) 2005 Jan Molic.
|
47
|
+
#
|
48
|
+
# People who have contributed to this class since then include:
|
49
|
+
#
|
50
|
+
# * Andrew Johnson (merge, to_a, inspect, shift and Hash[])
|
51
|
+
# * Jeff Sharpe (reverse and reverse!)
|
52
|
+
# * Thomas Leitner (has_key? and key?)
|
53
|
+
#
|
54
|
+
# Copyright (c) 2005, 2009 Jan Molic, Thomas Sawyer
|
55
|
+
|
65
56
|
class Dictionary
|
66
57
|
|
67
58
|
include Enumerable
|
data/lib/hashery/lruhash.rb
CHANGED
@@ -1,12 +1,11 @@
|
|
1
|
-
# LRU based Hash
|
2
|
-
|
3
1
|
require 'enumerator'
|
4
2
|
|
5
3
|
# Hash with LRU expiry policy. There are at most max_size elements in a
|
6
4
|
# LRUHash. When adding more elements old elements are removed according
|
7
5
|
# to LRU policy.
|
8
6
|
#
|
9
|
-
#
|
7
|
+
# http://github.com/rklemme/muppet-laboratories/blob/master/lib/lruhash.rb
|
8
|
+
# Copyright (c) 2010 Robert Klemme
|
10
9
|
|
11
10
|
class LRUHash
|
12
11
|
|
data/lib/hashery/opencascade.rb
CHANGED
@@ -1,7 +1,4 @@
|
|
1
|
-
|
2
|
-
|
3
|
-
require 'hashery/openobject'
|
4
|
-
#require 'facets/boolean' # bool
|
1
|
+
require 'hashery/openhash'
|
5
2
|
#require 'facets/nullclass'
|
6
3
|
|
7
4
|
# = OpenCascade
|
@@ -32,6 +29,13 @@ require 'hashery/openobject'
|
|
32
29
|
#
|
33
30
|
# c.a.z? #=> nil
|
34
31
|
#
|
32
|
+
# OpenCascade also transforms Hashes within Arrays.
|
33
|
+
#
|
34
|
+
# h = { :x=>[ {:a=>1}, {:a=>2} ], :y=>1 }
|
35
|
+
# c = OpenCascade[h]
|
36
|
+
# c.x.first.a.assert == 1
|
37
|
+
# c.x.last.a.assert == 2
|
38
|
+
#
|
35
39
|
# Finally, you can set a node and get the reciever back using
|
36
40
|
# the !-mark.
|
37
41
|
#
|
@@ -54,8 +58,9 @@ require 'hashery/openobject'
|
|
54
58
|
# So be sure to take that into account.
|
55
59
|
#++
|
56
60
|
|
57
|
-
class OpenCascade <
|
61
|
+
class OpenCascade < OpenHash
|
58
62
|
|
63
|
+
#
|
59
64
|
def method_missing(sym, *args, &blk)
|
60
65
|
type = sym.to_s[-1,1]
|
61
66
|
name = sym.to_s.gsub(/[=!?]$/, '').to_sym
|
@@ -63,21 +68,32 @@ class OpenCascade < OpenObject
|
|
63
68
|
when '='
|
64
69
|
self[name] = args.first
|
65
70
|
when '!'
|
66
|
-
|
71
|
+
#@hash.__send__(name, *args, &blk)
|
72
|
+
__send__(name, *args, &blk)
|
67
73
|
when '?'
|
68
74
|
self[name]
|
69
75
|
else
|
70
76
|
if key?(name)
|
71
|
-
|
72
|
-
if Hash === val
|
73
|
-
self[name] = OpenCascade.new(val) #self.class.new(val)
|
74
|
-
else
|
75
|
-
self[name]
|
76
|
-
end
|
77
|
+
self[name] = transform_entry(self[name])
|
77
78
|
else
|
78
79
|
self[name] = OpenCascade.new #self.class.new
|
79
80
|
end
|
80
81
|
end
|
81
82
|
end
|
82
83
|
|
84
|
+
private
|
85
|
+
|
86
|
+
#
|
87
|
+
def transform_entry(entry)
|
88
|
+
case entry
|
89
|
+
when Hash
|
90
|
+
OpenCascade.new(entry) #self.class.new(val)
|
91
|
+
when Array
|
92
|
+
entry.map{ |e| transform_entry(e) }
|
93
|
+
else
|
94
|
+
entry
|
95
|
+
end
|
96
|
+
end
|
97
|
+
|
83
98
|
end
|
99
|
+
|
data/lib/hashery/openhash.rb
CHANGED
@@ -15,6 +15,18 @@ class OpenHash < Hash
|
|
15
15
|
merge!(data)
|
16
16
|
end
|
17
17
|
|
18
|
+
#
|
19
|
+
def <<(x)
|
20
|
+
case x
|
21
|
+
when Hash
|
22
|
+
update(x)
|
23
|
+
when Array
|
24
|
+
x.each_slice(2) do |(k,v)|
|
25
|
+
self[k] = v
|
26
|
+
end
|
27
|
+
end
|
28
|
+
end
|
29
|
+
|
18
30
|
#
|
19
31
|
def respond_to?(name)
|
20
32
|
key?(name.to_sym) || super(name)
|
data/lib/hashery/sparsearray.rb
CHANGED
@@ -1,24 +1,3 @@
|
|
1
|
-
#--
|
2
|
-
# SparseArray
|
3
|
-
#
|
4
|
-
# Copyright (c) 2004,2005 Thomas Sawyer
|
5
|
-
#
|
6
|
-
# Ruby License
|
7
|
-
#
|
8
|
-
# This module is free software. You may use, modify, and/or redistribute this
|
9
|
-
# software under the same terms as Ruby.
|
10
|
-
#
|
11
|
-
# This program is distributed in the hope that it will be useful, but WITHOUT
|
12
|
-
# ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
|
13
|
-
# FOR A PARTICULAR PURPOSE.
|
14
|
-
#
|
15
|
-
# ==========================================================================
|
16
|
-
# Revision History ::
|
17
|
-
# --------------------------------------------------------------------------
|
18
|
-
# 04.09 Trans * 99% Compatible with Array
|
19
|
-
# ==========================================================================
|
20
|
-
#++
|
21
|
-
|
22
1
|
# = SparseArray
|
23
2
|
#
|
24
3
|
# SparseArray is an implemenation of the Array class using only Hashes.
|
@@ -28,17 +7,29 @@
|
|
28
7
|
# Ruby 1.9 that need to be added, and negative indexes are not quite fully
|
29
8
|
# supported yet.
|
30
9
|
#
|
31
|
-
#
|
32
|
-
#
|
33
|
-
#
|
34
|
-
#
|
10
|
+
# Benchmarks comparing Ruby 1.6 circa 2004 compared to Ruby 1.8.7
|
11
|
+
# circa 2010, show that Ruby's Array implementation has improved quite
|
12
|
+
# a bit. Where as Array was about 2-4 times faster than SparseArray in 2004,
|
13
|
+
# it is now over 10x faster, and able to handle large sparse arrays quite
|
14
|
+
# easily. Though surely SparseArray could still be improved, <b>SparseArray
|
15
|
+
# is little more than an interesting novelty at this point</b>, as opposed
|
16
|
+
# to a useful class, but we will keep her nonetheless for simple interests
|
17
|
+
# sake.
|
18
|
+
#
|
19
|
+
# NOTE: SparseArray is also the first piece of code I used TDD to create.
|
20
|
+
#
|
21
|
+
# Copyright (c) 2004 Thomas Sawyer
|
35
22
|
#
|
23
|
+
#--
|
24
|
+
# TODO: Add auto-array features if needed (see work/autoarray).
|
25
|
+
#++
|
26
|
+
|
36
27
|
class SparseArray < Hash
|
37
28
|
|
38
29
|
def self.[](*args)
|
39
|
-
|
40
|
-
args.each
|
41
|
-
|
30
|
+
s = new
|
31
|
+
args.each{ |e| s << e }
|
32
|
+
s
|
42
33
|
end
|
43
34
|
|
44
35
|
def self.new_h(hsh)
|
@@ -267,11 +258,11 @@ class SparseArray < Hash
|
|
267
258
|
end
|
268
259
|
|
269
260
|
def each
|
270
|
-
(0...self.length).each
|
261
|
+
(0...self.length).each{ |i| yield(get(i)) }
|
271
262
|
end
|
272
263
|
|
273
264
|
def each_index
|
274
|
-
(0...self.length).each
|
265
|
+
(0...self.length).each{ |i| yield(i) }
|
275
266
|
end
|
276
267
|
|
277
268
|
# empty? okay as is
|
metadata
CHANGED
@@ -4,35 +4,34 @@ version: !ruby/object:Gem::Version
|
|
4
4
|
prerelease: false
|
5
5
|
segments:
|
6
6
|
- 1
|
7
|
-
-
|
7
|
+
- 2
|
8
8
|
- 0
|
9
|
-
version: 1.
|
9
|
+
version: 1.2.0
|
10
10
|
platform: ruby
|
11
11
|
authors:
|
12
12
|
- Thomas Sawyer
|
13
|
+
- Kirk Haines
|
14
|
+
- Robert Klemme
|
13
15
|
- Jan Molic
|
14
16
|
- George Moschovitis
|
17
|
+
- Jeena Paradies
|
18
|
+
- Erik Veenstra
|
15
19
|
autorequire:
|
16
20
|
bindir: bin
|
17
21
|
cert_chain: []
|
18
22
|
|
19
|
-
date: 2010-04
|
23
|
+
date: 2010-06-04 00:00:00 -04:00
|
20
24
|
default_executable:
|
21
25
|
dependencies: []
|
22
26
|
|
23
|
-
description:
|
24
|
-
|
25
|
-
from the original Ruby Facets library. Included are the widely
|
26
|
-
used OrderedHash, the related but more featured Dictionary
|
27
|
-
class, a number of _open_ classes, similiar to the standard
|
28
|
-
OpenStruct and variations on the standard Hash.
|
29
|
-
email:
|
27
|
+
description: The Hashery is a collection of Hash-like classes, spun-off from the original Ruby Facets library. Included are the widely used OrderedHash, the related but more featured Dictionary class, a number of open classes, similiar to the standard OpenStruct and a few variations on the standard Hash.
|
28
|
+
email: transfire@gmail.com
|
30
29
|
executables: []
|
31
30
|
|
32
31
|
extensions: []
|
33
32
|
|
34
|
-
extra_rdoc_files:
|
35
|
-
|
33
|
+
extra_rdoc_files:
|
34
|
+
- README.rdoc
|
36
35
|
files:
|
37
36
|
- lib/hashery/association.rb
|
38
37
|
- lib/hashery/castinghash.rb
|
@@ -51,17 +50,6 @@ files:
|
|
51
50
|
- lib/hashery/stash.rb
|
52
51
|
- lib/hashery/statichash.rb
|
53
52
|
- lib/hashery.rb
|
54
|
-
- meta/authors
|
55
|
-
- meta/created
|
56
|
-
- meta/description
|
57
|
-
- meta/homepage
|
58
|
-
- meta/license
|
59
|
-
- meta/name
|
60
|
-
- meta/release
|
61
|
-
- meta/repository
|
62
|
-
- meta/suite
|
63
|
-
- meta/summary
|
64
|
-
- meta/version
|
65
53
|
- test/case_association.rb
|
66
54
|
- test/case_dictionary.rb
|
67
55
|
- test/case_opencascade.rb
|
@@ -80,6 +68,8 @@ post_install_message:
|
|
80
68
|
rdoc_options:
|
81
69
|
- --title
|
82
70
|
- Hashery API
|
71
|
+
- --main
|
72
|
+
- README.rdoc
|
83
73
|
require_paths:
|
84
74
|
- lib
|
85
75
|
required_ruby_version: !ruby/object:Gem::Requirement
|
data/meta/authors
DELETED
data/meta/created
DELETED
@@ -1 +0,0 @@
|
|
1
|
-
2010-04-21
|
data/meta/description
DELETED
@@ -1,5 +0,0 @@
|
|
1
|
-
The Facets Hashery is collection of Hash-like classes, spun-off
|
2
|
-
from the original Ruby Facets library. Included are the widely
|
3
|
-
used OrderedHash, the related but more featured Dictionary
|
4
|
-
class, a number of _open_ classes, similiar to the standard
|
5
|
-
OpenStruct and variations on the standard Hash.
|
data/meta/homepage
DELETED
@@ -1 +0,0 @@
|
|
1
|
-
http://rubyworks.github.com/hashery
|
data/meta/license
DELETED
@@ -1 +0,0 @@
|
|
1
|
-
MIT
|
data/meta/name
DELETED
@@ -1 +0,0 @@
|
|
1
|
-
hashery
|
data/meta/release
DELETED
@@ -1 +0,0 @@
|
|
1
|
-
2009-06-26
|
data/meta/repository
DELETED
@@ -1 +0,0 @@
|
|
1
|
-
git://github.com/rubyworks/hashery.git
|
data/meta/suite
DELETED
@@ -1 +0,0 @@
|
|
1
|
-
rubyworks
|
data/meta/summary
DELETED
@@ -1 +0,0 @@
|
|
1
|
-
Facets bread collection of Hash-like classes.
|
data/meta/version
DELETED
@@ -1 +0,0 @@
|
|
1
|
-
1.1.0
|