hashery 1.5.0 → 2.0.0
Sign up to get free protection for your applications and to get access to all the features.
- data/.ruby +30 -17
- data/.yardopts +1 -0
- data/Config.rb +28 -0
- data/{QED.rdoc → DEMO.rdoc} +0 -0
- data/HISTORY.rdoc +37 -0
- data/LICENSE.txt +26 -0
- data/NOTICE.txt +46 -0
- data/README.rdoc +10 -7
- data/lib/hashery.rb +6 -6
- data/lib/hashery.yml +30 -17
- data/lib/hashery/association.rb +169 -109
- data/lib/hashery/casting_hash.rb +128 -135
- data/lib/hashery/core_ext.rb +89 -61
- data/lib/hashery/crud_hash.rb +365 -0
- data/lib/hashery/dictionary.rb +545 -345
- data/lib/hashery/fuzzy_hash.rb +177 -125
- data/lib/hashery/ini_hash.rb +321 -0
- data/lib/hashery/key_hash.rb +54 -179
- data/lib/hashery/linked_list.rb +245 -191
- data/lib/hashery/lru_hash.rb +292 -202
- data/lib/hashery/open_cascade.rb +133 -78
- data/lib/hashery/open_hash.rb +127 -61
- data/lib/hashery/ordered_hash.rb +128 -122
- data/lib/hashery/path_hash.rb +238 -0
- data/lib/hashery/property_hash.rb +144 -80
- data/lib/hashery/query_hash.rb +85 -29
- data/lib/hashery/stash.rb +7 -3
- data/lib/hashery/static_hash.rb +46 -41
- data/test/case_association.rb +65 -4
- data/test/case_dictionary.rb +149 -5
- data/test/{case_keyhash.rb → case_key_hash.rb} +20 -14
- data/test/case_lru_hash.rb +162 -0
- data/test/{case_opencascade.rb → case_open_cascade.rb} +4 -8
- data/test/case_open_hash.rb +87 -0
- data/test/case_query_hash.rb +226 -0
- data/test/helper.rb +8 -0
- metadata +33 -63
- data/COPYING.rdoc +0 -45
- data/lib/hashery/basic_object.rb +0 -74
- data/lib/hashery/basic_struct.rb +0 -288
- data/lib/hashery/basicobject.rb +0 -1
- data/lib/hashery/basicstruct.rb +0 -1
- data/lib/hashery/castinghash.rb +0 -1
- data/lib/hashery/fuzzyhash.rb +0 -1
- data/lib/hashery/ini.rb +0 -268
- data/lib/hashery/keyhash.rb +0 -1
- data/lib/hashery/linkedlist.rb +0 -1
- data/lib/hashery/lruhash.rb +0 -1
- data/lib/hashery/memoizer.rb +0 -64
- data/lib/hashery/open_object.rb +0 -1
- data/lib/hashery/opencascade.rb +0 -1
- data/lib/hashery/openhash.rb +0 -1
- data/lib/hashery/openobject.rb +0 -1
- data/lib/hashery/orderedhash.rb +0 -1
- data/lib/hashery/ostructable.rb +0 -186
- data/lib/hashery/propertyhash.rb +0 -1
- data/lib/hashery/queryhash.rb +0 -1
- data/lib/hashery/statichash.rb +0 -1
- data/qed/01_openhash.rdoc +0 -57
- data/qed/02_queryhash.rdoc +0 -21
- data/qed/03_castinghash.rdoc +0 -13
- data/qed/04_statichash.rdoc +0 -22
- data/qed/05_association.rdoc +0 -59
- data/qed/06_opencascade.rdoc +0 -58
- data/qed/07_fuzzyhash.rdoc +0 -141
- data/qed/08_properyhash.rdoc +0 -38
- data/qed/09_ostructable.rdoc +0 -56
- data/qed/applique/ae.rb +0 -1
- data/test/case_basicstruct.rb +0 -192
- data/test/case_openhash.rb +0 -22
data/qed/applique/ae.rb
DELETED
@@ -1 +0,0 @@
|
|
1
|
-
require 'ae/should'
|
data/test/case_basicstruct.rb
DELETED
@@ -1,192 +0,0 @@
|
|
1
|
-
require 'lemon'
|
2
|
-
require 'ae'
|
3
|
-
require 'ae/legacy'
|
4
|
-
|
5
|
-
require 'hashery/basic_struct'
|
6
|
-
|
7
|
-
testcase BasicStruct do
|
8
|
-
include AE::Legacy::Assertions
|
9
|
-
|
10
|
-
method :respond_to? do
|
11
|
-
test do
|
12
|
-
o = BasicStruct.new
|
13
|
-
t = o.respond_to?(:key?)
|
14
|
-
assert t
|
15
|
-
end
|
16
|
-
end
|
17
|
-
|
18
|
-
method :is_a? do
|
19
|
-
test do
|
20
|
-
assert BasicStruct[{}].is_a?(Hash)
|
21
|
-
assert BasicStruct[{}].is_a?(BasicStruct)
|
22
|
-
end
|
23
|
-
end
|
24
|
-
|
25
|
-
method :[] do
|
26
|
-
test "subhash access" do
|
27
|
-
o = BasicStruct[:a=>1,:b=>{:x=>9}]
|
28
|
-
assert( o[:b][:x] == 9 )
|
29
|
-
assert( o.b[:x] == 9 )
|
30
|
-
end
|
31
|
-
|
32
|
-
test "indifferent key access" do
|
33
|
-
o = BasicStruct["a"=>1,"b"=>{:x=>9}]
|
34
|
-
assert( o["a"] == 1 )
|
35
|
-
assert( o[:a] == 1 )
|
36
|
-
assert( o["b"] == {:x=>9} )
|
37
|
-
assert( o[:b] == {:x=>9} )
|
38
|
-
assert( o["b"][:x] == 9 )
|
39
|
-
assert( o[:b]["x"] == nil )
|
40
|
-
end
|
41
|
-
end
|
42
|
-
|
43
|
-
method :[]= do
|
44
|
-
test "setting first entry" do
|
45
|
-
f0 = BasicStruct.new
|
46
|
-
f0[:a] = 1
|
47
|
-
assert( f0.to_h == {:a=>1} )
|
48
|
-
end
|
49
|
-
|
50
|
-
test "setting an additional entry" do
|
51
|
-
f0 = BasicStruct[:a=>1]
|
52
|
-
f0[:b] = 2
|
53
|
-
assert( f0.to_h == {:a=>1,:b=>2} )
|
54
|
-
end
|
55
|
-
end
|
56
|
-
|
57
|
-
method :method_missing do
|
58
|
-
test "reading entries" do
|
59
|
-
f0 = BasicStruct[:class=>1]
|
60
|
-
assert( f0.class == 1 )
|
61
|
-
end
|
62
|
-
|
63
|
-
test "setting entries" do
|
64
|
-
fo = BasicStruct.new
|
65
|
-
9.times{ |i| fo.__send__("n#{i}=", 1) }
|
66
|
-
9.times{ |i|
|
67
|
-
assert( fo.__send__("n#{i}") == 1 )
|
68
|
-
}
|
69
|
-
end
|
70
|
-
|
71
|
-
test "using bang" do
|
72
|
-
o = BasicStruct.new
|
73
|
-
o.a = 10
|
74
|
-
o.b = 20
|
75
|
-
h = {}
|
76
|
-
o.each!{ |k,v| h[k] = v + 10 }
|
77
|
-
assert( h == {:a=>20, :b=>30} )
|
78
|
-
end
|
79
|
-
end
|
80
|
-
|
81
|
-
#method :as_hash do
|
82
|
-
# test do
|
83
|
-
# f0 = BasicStruct[:f0=>"f0"]
|
84
|
-
# h0 = { :h0=>"h0" }
|
85
|
-
# assert( BasicStruct[:f0=>"f0", :h0=>"h0"] == f0.as_hash.merge(h0) )
|
86
|
-
# assert( {:f0=>"f0", :h0=>"h0"} == h0.merge(f0) )
|
87
|
-
# end
|
88
|
-
#end
|
89
|
-
|
90
|
-
method :as_hash do
|
91
|
-
test do
|
92
|
-
f1 = BasicStruct[:f1=>"f1"]
|
93
|
-
h1 = { :h1=>"h1" }
|
94
|
-
f1.as_hash.update(h1)
|
95
|
-
assert( f1 == BasicStruct[:f1=>"f1", :h1=>"h1"] )
|
96
|
-
end
|
97
|
-
end
|
98
|
-
|
99
|
-
#method :as_hash do
|
100
|
-
# test do
|
101
|
-
# f1 = BasicStruct[:f1=>"f1"]
|
102
|
-
# h1 = { :h1=>"h1" }
|
103
|
-
# f1.as_hash.update(h1)
|
104
|
-
# h1.update(f1)
|
105
|
-
# assert( f1 == BasicStruct[:f1=>"f1", :h1=>"h1"] )
|
106
|
-
# assert( h1 == {:f1=>"f1", :h1=>"h1"} )
|
107
|
-
# end
|
108
|
-
#end
|
109
|
-
|
110
|
-
method :<< do
|
111
|
-
test "passing a hash" do
|
112
|
-
fo = BasicStruct.new
|
113
|
-
fo << {:a=>1,:b=>2}
|
114
|
-
assert( fo.to_h == {:a=>1, :b=>2} )
|
115
|
-
end
|
116
|
-
|
117
|
-
test "passing a pair" do
|
118
|
-
fo = BasicStruct.new
|
119
|
-
fo << [:a, 1]
|
120
|
-
fo << [:b, 2]
|
121
|
-
assert( fo.to_h == {:a=>1, :b=>2} )
|
122
|
-
end
|
123
|
-
end
|
124
|
-
|
125
|
-
method :to_h do
|
126
|
-
test do
|
127
|
-
ho = {}
|
128
|
-
fo = BasicStruct.new
|
129
|
-
5.times{ |i| ho["n#{i}".to_sym] = 1 }
|
130
|
-
5.times{ |i| fo.__send__("n#{i}=", 1) }
|
131
|
-
assert( fo.to_h == ho )
|
132
|
-
end
|
133
|
-
test "BasicStruct within BasicStruct" do
|
134
|
-
o = BasicStruct.new
|
135
|
-
o.a = 10
|
136
|
-
o.b = 20
|
137
|
-
o.x = BasicStruct.new
|
138
|
-
o.x.a = 100
|
139
|
-
o.x.b = 200
|
140
|
-
o.x.c = 300
|
141
|
-
assert( o.to_h == {:a=>10, :b=>20, :x=>{:a=>100, :b=>200, :c=>300}} )
|
142
|
-
end
|
143
|
-
end
|
144
|
-
|
145
|
-
method :to_proc do
|
146
|
-
test do
|
147
|
-
#p = Proc.new{ |x| x.word = "Hello" }
|
148
|
-
o = BasicStruct[:a=>1,:b=>2]
|
149
|
-
assert( Proc === o.to_proc )
|
150
|
-
end
|
151
|
-
end
|
152
|
-
|
153
|
-
end
|
154
|
-
|
155
|
-
TestCase Hash do
|
156
|
-
|
157
|
-
method :to_basicstruct do
|
158
|
-
test do
|
159
|
-
h = {'a'=>1, 'b'=>2}
|
160
|
-
o = h.to_basicstruct
|
161
|
-
assert( o.a == 1 )
|
162
|
-
assert( o.b == 2 )
|
163
|
-
end
|
164
|
-
end
|
165
|
-
|
166
|
-
method :update do
|
167
|
-
test "by BasicStruct" do
|
168
|
-
raise NotImplementedError, "Ruby 1.8 does not know #to_hash."
|
169
|
-
|
170
|
-
h1 = { :h1=>"h1" }
|
171
|
-
f1 = BasicStruct[:f1=>"f1"]
|
172
|
-
h1.update(f1)
|
173
|
-
assert( h1 == {:f1=>"f1", :h1=>"h1"} )
|
174
|
-
end
|
175
|
-
end
|
176
|
-
|
177
|
-
end
|
178
|
-
|
179
|
-
=begin
|
180
|
-
TestCase Proc do
|
181
|
-
|
182
|
-
method :to_basicstruct do
|
183
|
-
test do
|
184
|
-
p = lambda { |x| x.word = "Hello" }
|
185
|
-
o = p.to_basicstruct
|
186
|
-
assert( o.word == "Hello" )
|
187
|
-
end
|
188
|
-
end
|
189
|
-
|
190
|
-
end
|
191
|
-
=end
|
192
|
-
|
data/test/case_openhash.rb
DELETED
@@ -1,22 +0,0 @@
|
|
1
|
-
require 'lemon'
|
2
|
-
require 'ae'
|
3
|
-
|
4
|
-
require 'hashery/open_hash'
|
5
|
-
|
6
|
-
testcase OpenHash do
|
7
|
-
|
8
|
-
class_method :new do
|
9
|
-
test do
|
10
|
-
o = OpenHash.new(:a=>1, :b=>2)
|
11
|
-
o.a.assert == 1
|
12
|
-
o.b.assert == 2
|
13
|
-
end
|
14
|
-
test do
|
15
|
-
o = OpenHash.new(:a=>1, :b=>2)
|
16
|
-
o.a.assert == 1
|
17
|
-
o.b.assert == 2
|
18
|
-
end
|
19
|
-
end
|
20
|
-
|
21
|
-
end
|
22
|
-
|