hashery 2.0.0 → 2.0.1

Sign up to get free protection for your applications and to get access to all the features.
data/.ruby CHANGED
@@ -58,11 +58,10 @@ load_path:
58
58
  - lib
59
59
  - alt
60
60
  revision: 0
61
+ name: hashery
62
+ title: Hashery
61
63
  created: '2010-04-21'
62
64
  summary: Facets-bread collection of Hash-like classes.
63
- title: Hashery
64
- version: 2.0.0
65
- name: hashery
66
65
  description: ! 'The Hashery is a tight collection of Hash-like classes. Included among
67
66
  its many
68
67
 
@@ -73,4 +72,5 @@ description: ! 'The Hashery is a tight collection of Hash-like classes. Included
73
72
  of the CRUDHash which defines a CRUD model on top of Ruby''s standard Hash
74
73
 
75
74
  making it a snap to subclass and augment to fit any specific use case.'
76
- date: '2012-06-18'
75
+ version: 2.0.1
76
+ date: '2012-07-06'
@@ -1,5 +1,15 @@
1
1
  = RELEASE HISTORY
2
2
 
3
+ == 2.0.1 / 2012-07-06
4
+
5
+ This minor release fixes an issue with OpenCascade (#13).
6
+ The key_proc procedure wasn't being passed along to sub-cascades.
7
+
8
+ Changes:
9
+
10
+ * OpenCascade passes along key_proc to childern.
11
+
12
+
3
13
  == 2.0.0 / 2012-05-11
4
14
 
5
15
  This is a big release for Hashery which both culls some of it's
@@ -58,11 +58,10 @@ load_path:
58
58
  - lib
59
59
  - alt
60
60
  revision: 0
61
+ name: hashery
62
+ title: Hashery
61
63
  created: '2010-04-21'
62
64
  summary: Facets-bread collection of Hash-like classes.
63
- title: Hashery
64
- version: 2.0.0
65
- name: hashery
66
65
  description: ! 'The Hashery is a tight collection of Hash-like classes. Included among
67
66
  its many
68
67
 
@@ -73,4 +72,5 @@ description: ! 'The Hashery is a tight collection of Hash-like classes. Included
73
72
  of the CRUDHash which defines a CRUD model on top of Ruby''s standard Hash
74
73
 
75
74
  making it a snap to subclass and augment to fit any specific use case.'
76
- date: '2012-06-18'
75
+ version: 2.0.1
76
+ date: '2012-07-06'
@@ -72,7 +72,7 @@ module Hashery
72
72
  #
73
73
  # Read value given a +key+.
74
74
  #
75
- # key - Index keey to lookup.
75
+ # key - Index key to lookup.
76
76
  #
77
77
  # Returns value.
78
78
  #
@@ -124,7 +124,10 @@ module Hashery
124
124
  def cast_value(entry)
125
125
  case entry
126
126
  when Hash
127
- OpenCascade[entry] #self.class.new(val)
127
+ e = OpenCascade.new
128
+ e.key_proc = key_proc if key_proc
129
+ e.merge!(entry)
130
+ e
128
131
  when Array
129
132
  entry.map{ |e| cast_value(e) }
130
133
  else
@@ -136,6 +139,7 @@ module Hashery
136
139
 
137
140
  end
138
141
 
142
+
139
143
  #--
140
144
  # Last, when an entry is not found, 'null' is returned rather then 'nil'.
141
145
  # This allows for run-on entries withuot error. Eg.
@@ -0,0 +1,71 @@
1
+ require 'helper'
2
+
3
+ test_case CastingHash do
4
+
5
+ class_method :[] do
6
+ test do
7
+ h = CastingHash[:a=>1, :b=>2]
8
+ end
9
+ end
10
+
11
+ class_method :new do
12
+ test do
13
+ h = CastingHash.new
14
+ end
15
+
16
+ test 'with default' do
17
+ h = CastingHash.new(0)
18
+ h['a'].assert == 0
19
+ end
20
+
21
+ test 'with casting procedure' do
22
+ h = CastingHash.new{ |k,v| [k.to_sym, v] }
23
+ h['a'] = 1
24
+ h.assert == {:a=>1}
25
+ end
26
+
27
+ test 'with default and casting procedure' do
28
+ h = CastingHash.new(0){ |k,v| [k.to_sym, v] }
29
+ h['a'].assert == 0
30
+ h['b'] = 2
31
+ h.assert == {:b=>2}
32
+ end
33
+ end
34
+
35
+ method :recast! do
36
+ test do
37
+ h = CastingHash[:a=>1, :b=>2]
38
+ h.cast_proc{ |k,v| [k.to_s, v] }
39
+ h.recast!
40
+ h.assert == {'a'=>1, 'b'=>2}
41
+ end
42
+ end
43
+
44
+ method :cast_proc= do
45
+ test do
46
+ h = CastingHash[:a=>1, :b=>2]
47
+ h.cast_proc = Proc.new{ |k,v| [k.to_s, v] }
48
+ h.recast!
49
+ h.assert == {'a'=>1, 'b'=>2}
50
+ end
51
+ end
52
+
53
+ method :to_hash do
54
+ test do
55
+ h = CastingHash[:a=>1, :b=>2]
56
+ h.to_hash
57
+ ::Hash.assert === h
58
+ h.assert == {:a=>1, :b=>2}
59
+ end
60
+ end
61
+
62
+ method :to_h do
63
+ test do
64
+ h = CastingHash[:a=>1, :b=>2]
65
+ h.to_h
66
+ ::Hash.assert === h
67
+ h.assert == {:a=>1, :b=>2}
68
+ end
69
+ end
70
+
71
+ end
@@ -0,0 +1,79 @@
1
+ require 'helper'
2
+
3
+ test_case Hash do
4
+
5
+ method :rekey do
6
+
7
+ test "default" do
8
+ foo = { "a"=>1, "b"=>2 }
9
+ foo.rekey.assert == { :a=>1, :b=>2 }
10
+ foo.assert == { "a"=>1, "b"=>2 }
11
+ end
12
+
13
+ test "specific key" do
14
+ bar = { :a=>1, :b=>2 }
15
+ foo = bar.rekey(:a=>:c)
16
+ foo[:c].assert == 1
17
+ foo[:b].assert == 2
18
+ foo[:a].assert == nil
19
+ end
20
+
21
+ test "with block" do
22
+ bar = { :a=>1, :b=>2 }
23
+ foo = bar.rekey{ |k| k.to_s }
24
+ foo['a'].assert == 1
25
+ foo['b'].assert == 2
26
+ foo[:a].assert == nil
27
+ foo[:b].assert == nil
28
+ foo.assert == { 'a'=>1, 'b'=>2 }
29
+ end
30
+
31
+ test "symbol proc" do
32
+ foo = { :a=>1, :b=>2 }
33
+ foo.rekey(&:to_s).assert == { "a"=>1, "b"=>2 }
34
+ foo.assert == { :a =>1, :b=>2 }
35
+ end
36
+
37
+ end
38
+
39
+ method :rekey! do
40
+
41
+ test "default" do
42
+ foo = { "a"=>1, "b"=>2 }
43
+ foo.rekey!.assert == { :a=>1, :b=>2 }
44
+ foo.assert == { :a=>1, :b=>2 }
45
+ end
46
+
47
+ test "specific key" do
48
+ foo = { :a=>1, :b=>2 }
49
+ foo.rekey!(:a=>:c)
50
+ foo[:c].assert == 1
51
+ foo[:b].assert == 2
52
+ foo[:a].assert == nil
53
+ end
54
+
55
+ test "with block" do
56
+ foo = { :a=>1, :b=>2 }
57
+ foo.rekey!{ |k| k.to_s }
58
+ foo['a'].assert == 1
59
+ foo['b'].assert == 2
60
+ foo[:a].assert == nil
61
+ foo[:b].assert == nil
62
+ foo.assert == { 'a'=>1, 'b'=>2 }
63
+ end
64
+
65
+ test "symbol proc" do
66
+ foo = { :a=>1, :b=>2 }
67
+ foo.rekey!(&:to_s).assert == { "a"=>1, "b"=>2 }
68
+ foo.assert == { "a"=>1, "b"=>2 }
69
+ end
70
+
71
+ test "no conflict between keys" do
72
+ r = {1 => :a, 2 => :b}.rekey!{ |k| k + 1 }
73
+ r.refute = {3 => :a}
74
+ r.assert = {2 => :a, 3 => :b}
75
+ end
76
+
77
+ end
78
+
79
+ end
@@ -0,0 +1,29 @@
1
+ require 'helper'
2
+
3
+ test_case CRUDHash do
4
+
5
+ class_method :create do
6
+ test do
7
+ h = CRUDHash.create(:a=>1,:b=>2)
8
+ h.assert == {:a=>1,:b=>2}
9
+ end
10
+ end
11
+
12
+ class_method :auto do
13
+ test 'without a block' do
14
+ h = CRUDHash.auto
15
+ h[:a].assert == {}
16
+ end
17
+
18
+ test 'with a block' do
19
+ h = CRUDHash.auto{ [] }
20
+ h[:a].assert == []
21
+ end
22
+ end
23
+
24
+ end
25
+
26
+
27
+ #
28
+ # OT: Why not make `:a=>1` a Pair object?
29
+ #
@@ -0,0 +1,56 @@
1
+ require 'helper'
2
+
3
+ test_case IniHash do
4
+
5
+ class_method :new do
6
+ test do
7
+ h = IniHash.new('foo.ini', false)
8
+ end
9
+ end
10
+
11
+ method :[]= do
12
+ test do
13
+ h = IniHash.new('foo.ini', false)
14
+ h['a'] = '1'
15
+ h['a'].assert = '1'
16
+ end
17
+ end
18
+
19
+ method :[] do
20
+ test do
21
+ h = IniHash.new('foo.ini', false)
22
+ h['a'] = '1'
23
+ h['a'].assert = '1'
24
+ end
25
+ end
26
+
27
+ method :to_h do
28
+ test do
29
+ h = IniHash.new('foo.ini', false)
30
+ h['a'] = '1'
31
+ h.to_h.assert = {'a'=>'1'}
32
+ end
33
+ end
34
+
35
+ method :to_s do
36
+ test do
37
+ h = IniHash.new('foo.ini', false)
38
+ h['a'] = '1'
39
+ h.to_s.assert == "a=1\n"
40
+ end
41
+
42
+ test do
43
+ h = IniHash.new('foo.ini', false)
44
+ h['a'] = '1'
45
+ h['b'] = {'c'=>3}
46
+ h.to_s.assert == "a=1\n[b]\nc=3\n"
47
+ end
48
+ end
49
+
50
+ class_method :load do
51
+ h = IniHash.load('test/fixture/example.ini')
52
+ h['a'].assert == '1'
53
+ end
54
+
55
+ end
56
+
@@ -0,0 +1,167 @@
1
+ require 'helper'
2
+
3
+ test_case LinkedList do
4
+
5
+ class_method :new do
6
+ ll = LinkedList.new
7
+ LinkedList.assert === ll
8
+ end
9
+
10
+ method :to_a do
11
+ test 'empty' do
12
+ ll = LinkedList.new
13
+ ll.to_a.assert == []
14
+ end
15
+ test 'not empty' do
16
+ ll = LinkedList.new
17
+ ll.push :a
18
+ ll.to_a.assert == [:a]
19
+ end
20
+ end
21
+
22
+ method :empty? do
23
+ test do
24
+ ll = LinkedList.new
25
+ ll.assert.empty?
26
+ end
27
+ end
28
+
29
+ method :delete do
30
+ test do
31
+ ll = LinkedList.new
32
+ ll.push :a
33
+ ll.to_a.assert == [:a]
34
+ ll.delete(:a)
35
+ ll.to_a.assert == []
36
+ end
37
+
38
+ test do
39
+ ll = LinkedList.new
40
+ ll.push :a
41
+ ll.push :b
42
+ ll.push :c
43
+ ll.to_a.assert == [:a, :b, :c]
44
+ ll.delete(:b)
45
+ ll.to_a.assert == [:a, :c]
46
+ end
47
+ end
48
+
49
+ method :each do
50
+ test do
51
+ a = []
52
+ ll = LinkedList.new
53
+ ll.push :a
54
+ ll.each do |e|
55
+ a << e
56
+ end
57
+ a.assert == [:a]
58
+ end
59
+ end
60
+
61
+ method :length do
62
+ test do
63
+ ll = LinkedList.new
64
+ ll.push :a
65
+ ll.length.assert == 1
66
+ end
67
+ end
68
+
69
+ method :push do
70
+ test do
71
+ ll = LinkedList.new
72
+ ll.push :a
73
+ ll.to_a.assert == [:a]
74
+ end
75
+ end
76
+
77
+ method :unshift do
78
+ test do
79
+ ll = LinkedList.new
80
+ ll.unshift :a
81
+ ll.to_a.assert == [:a]
82
+ end
83
+ test do
84
+ ll = LinkedList.new
85
+ ll.push :a
86
+ ll.unshift :b
87
+ ll.to_a.assert == [:b, :a]
88
+ end
89
+ end
90
+
91
+ method :pop do
92
+ test do
93
+ ll = LinkedList.new
94
+ ll.push :a
95
+ ll.push :b
96
+ ll.to_a.assert == [:a, :b]
97
+ ll.pop
98
+ ll.to_a.assert == [:a]
99
+ end
100
+ end
101
+
102
+ method :shift do
103
+ test do
104
+ ll = LinkedList.new
105
+ ll.push :a
106
+ ll.push :b
107
+ ll.to_a.assert == [:a, :b]
108
+ ll.shift
109
+ ll.to_a.assert == [:b]
110
+ end
111
+ end
112
+
113
+ method :first do
114
+ test do
115
+ ll = LinkedList.new
116
+ ll.push :a
117
+ ll.push :b
118
+ ll.to_a.assert == [:a, :b]
119
+ ll.first.assert == :a
120
+ end
121
+ end
122
+
123
+ method :last do
124
+ test do
125
+ ll = LinkedList.new
126
+ ll.push :a
127
+ ll.push :b
128
+ ll.to_a.assert == [:a, :b]
129
+ ll.last.assert == :b
130
+ end
131
+ end
132
+
133
+ method :queue do
134
+ test do
135
+ ll = LinkedList.new
136
+ ll.push :a
137
+ ll.push :b
138
+ ll.queue.assert == [:a, :b]
139
+ end
140
+ end
141
+
142
+ method :[]= do
143
+ test do
144
+ ll = LinkedList.new
145
+ ll[:a] = :b
146
+ ll.to_a.assert == [:b]
147
+ ll[:a].assert == :b
148
+ end
149
+ end
150
+
151
+ method :[] do
152
+ test do
153
+ ll = LinkedList.new
154
+ ll.push :a
155
+ ll[:a].assert == :a
156
+ end
157
+
158
+ test do
159
+ ll = LinkedList.new
160
+ ll.push :a
161
+ ll.push :b
162
+ ll[:a].assert == :a
163
+ ll[:b].assert == :b
164
+ end
165
+ end
166
+
167
+ end
@@ -0,0 +1,21 @@
1
+ require 'helper'
2
+
3
+ test_case PropertyHash do
4
+
5
+ class_method :new do
6
+ test do
7
+ PropertyHash.new
8
+ end
9
+ end
10
+
11
+ method :update do
12
+ test do
13
+ h = PropertyHash.new
14
+ h.property :a
15
+ h.property :b
16
+ h.update(:a=>1, :b=>2)
17
+ h.assert == {:a=>1, :b=>2}
18
+ end
19
+ end
20
+
21
+ end
@@ -0,0 +1,8 @@
1
+ # top comment
2
+
3
+ a = 1
4
+
5
+ [section]
6
+ x = 2
7
+ y = 3
8
+
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.0
4
+ version: 2.0.1
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-06-19 00:00:00.000000000 Z
18
+ date: 2012-07-06 00:00:00.000000000 Z
19
19
  dependencies:
20
20
  - !ruby/object:Gem::Dependency
21
21
  name: detroit
22
- requirement: &19204020 !ruby/object:Gem::Requirement
22
+ requirement: !ruby/object:Gem::Requirement
23
23
  none: false
24
24
  requirements:
25
25
  - - ! '>='
@@ -27,10 +27,15 @@ dependencies:
27
27
  version: '0'
28
28
  type: :development
29
29
  prerelease: false
30
- version_requirements: *19204020
30
+ version_requirements: !ruby/object:Gem::Requirement
31
+ none: false
32
+ requirements:
33
+ - - ! '>='
34
+ - !ruby/object:Gem::Version
35
+ version: '0'
31
36
  - !ruby/object:Gem::Dependency
32
37
  name: qed
33
- requirement: &19203280 !ruby/object:Gem::Requirement
38
+ requirement: !ruby/object:Gem::Requirement
34
39
  none: false
35
40
  requirements:
36
41
  - - ! '>='
@@ -38,10 +43,15 @@ dependencies:
38
43
  version: '0'
39
44
  type: :development
40
45
  prerelease: false
41
- version_requirements: *19203280
46
+ version_requirements: !ruby/object:Gem::Requirement
47
+ none: false
48
+ requirements:
49
+ - - ! '>='
50
+ - !ruby/object:Gem::Version
51
+ version: '0'
42
52
  - !ruby/object:Gem::Dependency
43
53
  name: lemon
44
- requirement: &19222540 !ruby/object:Gem::Requirement
54
+ requirement: !ruby/object:Gem::Requirement
45
55
  none: false
46
56
  requirements:
47
57
  - - ! '>='
@@ -49,7 +59,12 @@ dependencies:
49
59
  version: '0'
50
60
  type: :development
51
61
  prerelease: false
52
- version_requirements: *19222540
62
+ version_requirements: !ruby/object:Gem::Requirement
63
+ none: false
64
+ requirements:
65
+ - - ! '>='
66
+ - !ruby/object:Gem::Version
67
+ version: '0'
53
68
  description: ! 'The Hashery is a tight collection of Hash-like classes. Included among
54
69
  its many
55
70
 
@@ -65,8 +80,8 @@ email:
65
80
  executables: []
66
81
  extensions: []
67
82
  extra_rdoc_files:
68
- - LICENSE.txt
69
83
  - NOTICE.txt
84
+ - LICENSE.txt
70
85
  - HISTORY.rdoc
71
86
  - DEMO.rdoc
72
87
  - README.rdoc
@@ -94,19 +109,26 @@ files:
94
109
  - lib/hashery.rb
95
110
  - lib/hashery.yml
96
111
  - test/case_association.rb
112
+ - test/case_casting_hash.rb
113
+ - test/case_core_ext.rb
114
+ - test/case_crud_hash.rb
97
115
  - test/case_dictionary.rb
116
+ - test/case_ini_hash.rb
98
117
  - test/case_key_hash.rb
118
+ - test/case_linked_list.rb
99
119
  - test/case_lru_hash.rb
100
120
  - test/case_open_cascade.rb
101
121
  - test/case_open_hash.rb
122
+ - test/case_property_hash.rb
102
123
  - test/case_query_hash.rb
124
+ - test/fixture/example.ini
103
125
  - test/helper.rb
104
126
  - HISTORY.rdoc
105
127
  - DEMO.rdoc
106
- - LICENSE.txt
107
- - README.rdoc
108
128
  - NOTICE.txt
109
129
  - Config.rb
130
+ - README.rdoc
131
+ - LICENSE.txt
110
132
  homepage: http://rubyworks.github.com/hashery
111
133
  licenses:
112
134
  - BSD-2-Clause
@@ -129,7 +151,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
129
151
  version: '0'
130
152
  requirements: []
131
153
  rubyforge_project:
132
- rubygems_version: 1.8.11
154
+ rubygems_version: 1.8.24
133
155
  signing_key:
134
156
  specification_version: 3
135
157
  summary: Facets-bread collection of Hash-like classes.