ice_nine 0.2.0 → 0.3.0

Sign up to get free protection for your applications and to get access to all the features.
data/Gemfile CHANGED
@@ -23,7 +23,7 @@ group :metrics do
23
23
 
24
24
  platforms :mri_18, :rbx do
25
25
  gem 'heckle', '~> 1.4.3'
26
- gem 'json', '~> 1.6.5'
26
+ gem 'json', '~> 1.6.6'
27
27
  gem 'mspec', '~> 1.5.17'
28
28
  gem 'ruby2ruby', '= 1.2.2'
29
29
  end
data/TODO CHANGED
@@ -1,3 +0,0 @@
1
- * Move some of spec/unit/ice_nine/class_methods/deep_freeze_spec.rb into an
2
- integration test.
3
- * Keep some minimal unit tests just for the functionality in the method.
data/config/flay.yml CHANGED
@@ -1,3 +1,3 @@
1
1
  ---
2
2
  threshold: 6
3
- total_score: 44.0
3
+ total_score: 39.0
data/config/flog.yml CHANGED
@@ -1,2 +1,2 @@
1
1
  ---
2
- threshold: 11.3
2
+ threshold: 9.4
data/ice_nine.gemspec CHANGED
@@ -9,7 +9,7 @@ Gem::Specification.new do |gem|
9
9
  gem.email = [ 'dan.kubb@gmail.com' ]
10
10
  gem.description = 'Deep Freeze Ruby Objects'
11
11
  gem.summary = gem.description
12
- gem.homepage = "https://github.com/dkubb/ice_nine"
12
+ gem.homepage = 'https://github.com/dkubb/ice_nine'
13
13
 
14
14
  gem.require_paths = %w[ lib ]
15
15
  gem.files = `git ls-files`.split("\n")
@@ -0,0 +1,29 @@
1
+ # encoding: utf-8
2
+
3
+ module IceNine
4
+ class Freezer
5
+
6
+ # A freezer class for handling Enumerable objects
7
+ class Enumerable < Object
8
+
9
+ # Deep Freeze an Enumerable
10
+ #
11
+ # @example
12
+ # enumerable = IceNine:Freezer::Enumerable.deep_freeze(%w[a b c])
13
+ # enumerable.select(&:frozen?) # => ['a', 'b', 'c']
14
+ #
15
+ # @param [Enumerable] enumerable
16
+ #
17
+ # @return [Enumerable]
18
+ #
19
+ # @todo use super on #each when Struct#each returns self in Rubinius
20
+ #
21
+ # @api public
22
+ def self.deep_freeze(enumerable)
23
+ enumerable.each { |entry| IceNine.deep_freeze(entry) }
24
+ super enumerable
25
+ end
26
+
27
+ end # class Enumerable
28
+ end # class Freezer
29
+ end # module IceNine
@@ -0,0 +1,10 @@
1
+ # encoding: utf-8
2
+
3
+ module IceNine
4
+ class Freezer
5
+
6
+ # Skip freezing false objects
7
+ class FalseClass < NoFreeze; end
8
+
9
+ end # class Freezer
10
+ end # module IceNine
@@ -0,0 +1,12 @@
1
+ # encoding: utf-8
2
+
3
+ module IceNine
4
+ class Freezer
5
+ class Hash
6
+
7
+ # Skip freezing Hash::State objects on Rubinius
8
+ class State < NoFreeze; end
9
+
10
+ end # class Hash
11
+ end # class Freezer
12
+ end # module IceNine
@@ -0,0 +1,10 @@
1
+ # encoding: utf-8
2
+
3
+ module IceNine
4
+ class Freezer
5
+
6
+ # Skip freezing nil objects
7
+ class NilClass < NoFreeze; end
8
+
9
+ end # class Freezer
10
+ end # module IceNine
@@ -22,27 +22,5 @@ module IceNine
22
22
  end
23
23
 
24
24
  end # class NoFreeze
25
-
26
- # Skip freezing nil objects
27
- class NilClass < NoFreeze; end
28
-
29
- # Skip freezing true objects
30
- class TrueClass < NoFreeze; end
31
-
32
- # Skip freezing false objects
33
- class FalseClass < NoFreeze; end
34
-
35
- # Skip freezing Symbol objects
36
- class Symbol < NoFreeze; end
37
-
38
- # Skip freezing Numeric objects
39
- class Numeric < NoFreeze; end
40
-
41
- # Skip freezing Rubinius objects
42
- class Rubinius < NoFreeze; end
43
-
44
- # Skip freezing Hash::State objects on Rubinius
45
- class Hash::State < NoFreeze; end
46
-
47
25
  end # class Freezer
48
26
  end # module IceNine
@@ -0,0 +1,10 @@
1
+ # encoding: utf-8
2
+
3
+ module IceNine
4
+ class Freezer
5
+
6
+ # Skip freezing Numeric objects
7
+ class Numeric < NoFreeze; end
8
+
9
+ end # class Freezer
10
+ end # module IceNine
@@ -0,0 +1,10 @@
1
+ # encoding: utf-8
2
+
3
+ module IceNine
4
+ class Freezer
5
+
6
+ # Skip freezing Rubinius objects
7
+ class Rubinius < NoFreeze; end
8
+
9
+ end # class Freezer
10
+ end # module IceNine
@@ -0,0 +1,10 @@
1
+ # encoding: utf-8
2
+
3
+ module IceNine
4
+ class Freezer
5
+
6
+ # A freezer class for handling String objects
7
+ class String < Object; end
8
+
9
+ end # class Freezer
10
+ end # module IceNine
@@ -4,26 +4,7 @@ module IceNine
4
4
  class Freezer
5
5
 
6
6
  # A freezer class for handling Struct objects
7
- class Struct < Object
7
+ class Struct < Enumerable; end
8
8
 
9
- # Deep Freeze a Struct
10
- #
11
- # @example
12
- # struct = IceNine:Freezer::Struct.deep_freeze(klass.new('1'))
13
- # struct.values.select(&:frozen?) # => ['1']
14
- #
15
- # @param [Struct] struct
16
- #
17
- # @return [Struct]
18
- #
19
- # @todo use super on Struct#each once it returns self in Rubinius
20
- #
21
- # @api public
22
- def self.deep_freeze(struct)
23
- struct.each(&IceNine.method(:deep_freeze))
24
- super struct
25
- end
26
-
27
- end # class Struct
28
9
  end # class Freezer
29
10
  end # module IceNine
@@ -0,0 +1,10 @@
1
+ # encoding: utf-8
2
+
3
+ module IceNine
4
+ class Freezer
5
+
6
+ # Skip freezing Symbol objects
7
+ class Symbol < NoFreeze; end
8
+
9
+ end # class Freezer
10
+ end # module IceNine
@@ -0,0 +1,10 @@
1
+ # encoding: utf-8
2
+
3
+ module IceNine
4
+ class Freezer
5
+
6
+ # Skip freezing true objects
7
+ class TrueClass < NoFreeze; end
8
+
9
+ end # class Freezer
10
+ end # module IceNine
@@ -1,5 +1,8 @@
1
1
  # encoding: utf-8
2
2
 
3
3
  module IceNine
4
- VERSION = '0.2.0'
5
- end
4
+
5
+ # Current gem version
6
+ VERSION = '0.3.0'
7
+
8
+ end # module IceNine
data/lib/ice_nine.rb CHANGED
@@ -6,13 +6,20 @@ require 'ice_nine/support/recursion_guard'
6
6
 
7
7
  require 'ice_nine/freezer'
8
8
  require 'ice_nine/freezer/object'
9
+ require 'ice_nine/freezer/no_freeze'
10
+ require 'ice_nine/freezer/enumerable'
9
11
 
10
- require 'ice_nine/freezer/array'
12
+ require 'ice_nine/freezer/false_class'
11
13
  require 'ice_nine/freezer/hash'
14
+ require 'ice_nine/freezer/hash/state'
15
+ require 'ice_nine/freezer/nil_class'
16
+ require 'ice_nine/freezer/numeric'
12
17
  require 'ice_nine/freezer/range'
18
+ require 'ice_nine/freezer/rubinius'
19
+ require 'ice_nine/freezer/string'
13
20
  require 'ice_nine/freezer/struct'
14
-
15
- require 'ice_nine/freezer/no_freeze'
21
+ require 'ice_nine/freezer/symbol'
22
+ require 'ice_nine/freezer/true_class'
16
23
 
17
24
  require 'ice_nine/version'
18
25
 
@@ -0,0 +1,193 @@
1
+ # encoding: utf-8
2
+
3
+ require 'spec_helper'
4
+ require 'ice_nine'
5
+
6
+ describe IceNine, '.deep_freeze' do
7
+ subject { object.deep_freeze(value) }
8
+
9
+ let(:object) { IceNine }
10
+
11
+ context 'with an Object' do
12
+ let(:value) { Object.new }
13
+
14
+ before do
15
+ value.instance_eval { @a = '1' }
16
+ end
17
+
18
+ it 'returns the object' do
19
+ should be(value)
20
+ end
21
+
22
+ it 'freezes the object' do
23
+ expect { subject }.should change(value, :frozen?).from(false).to(true)
24
+ end
25
+
26
+ it 'freezes the instance variables in the Object' do
27
+ subject.instance_variable_get(:@a).should be_frozen
28
+ end
29
+
30
+ context 'with a circular reference' do
31
+ before do
32
+ value.instance_eval { @self = self }
33
+ end
34
+
35
+ it 'returns the object' do
36
+ should be(value)
37
+ end
38
+
39
+ it 'freezes the object' do
40
+ expect { subject }.should change(value, :frozen?).from(false).to(true)
41
+ end
42
+
43
+ it 'freezes the instance variables in the Object' do
44
+ subject.instance_variable_get(:@a).should be_frozen
45
+ end
46
+ end
47
+ end
48
+
49
+ context 'with an Array' do
50
+ let(:value) { %w[a] }
51
+
52
+ it 'returns the object' do
53
+ should be(value)
54
+ end
55
+
56
+ it 'freezes the object' do
57
+ expect { subject }.should change(value, :frozen?).from(false).to(true)
58
+ end
59
+
60
+ it 'freezes each element in the Array' do
61
+ subject.select(&:frozen?).should == subject
62
+ end
63
+
64
+ context 'with a circular reference' do
65
+ before do
66
+ value << value
67
+ end
68
+
69
+ it 'returns the object' do
70
+ should be(value)
71
+ end
72
+
73
+ it 'freezes the object' do
74
+ expect { subject }.should change(value, :frozen?).from(false).to(true)
75
+ end
76
+
77
+ it 'freezes each element in the Array' do
78
+ subject.select(&:frozen?).should == subject
79
+ end
80
+ end
81
+ end
82
+
83
+ context 'with a Hash' do
84
+ let(:value) { { Object.new => Object.new } }
85
+
86
+ it 'returns the object' do
87
+ should be(value)
88
+ end
89
+
90
+ it 'freezes the object' do
91
+ expect { subject }.should change(value, :frozen?).from(false).to(true)
92
+ end
93
+
94
+ it 'freezes each key in the Hash' do
95
+ subject.keys.select(&:frozen?).should == subject.keys
96
+ end
97
+
98
+ it 'freezes each value in the Hash' do
99
+ subject.values.select(&:frozen?).should == subject.values
100
+ end
101
+
102
+ context 'with a circular reference' do
103
+ before do
104
+ value[value] = value
105
+ end
106
+
107
+ it 'returns the object' do
108
+ should be(value)
109
+ end
110
+
111
+ it 'freezes the object' do
112
+ expect { subject }.should change(value, :frozen?).from(false).to(true)
113
+ end
114
+
115
+ it 'freezes each key in the Hash' do
116
+ subject.keys.select(&:frozen?).should == subject.keys
117
+ end
118
+
119
+ it 'freezes each value in the Hash' do
120
+ subject.values.select(&:frozen?).should == subject.values
121
+ end
122
+ end
123
+ end
124
+
125
+ context 'with a Range' do
126
+ let(:value) { 'a'..'z' }
127
+
128
+ it 'returns the object' do
129
+ should be(value)
130
+ end
131
+
132
+ it 'freezes the object' do
133
+ expect { subject }.should change(value, :frozen?).from(false).to(true)
134
+ end
135
+
136
+ it 'freeze the first object in the Range' do
137
+ subject.begin.should be_frozen
138
+ end
139
+
140
+ it 'freeze the last object in the Range' do
141
+ subject.end.should be_frozen
142
+ end
143
+ end
144
+
145
+ context 'with a Struct' do
146
+ let(:value) { klass.new(%w[ 1 2 ]) }
147
+ let(:klass) { Struct.new(:a) }
148
+
149
+ it 'returns the object' do
150
+ should be(value)
151
+ end
152
+
153
+ it 'freezes the object' do
154
+ expect { subject }.should change(value, :frozen?).from(false).to(true)
155
+ end
156
+
157
+ it 'freezes each value in the Struct' do
158
+ subject.values.select(&:frozen?).should == subject.values
159
+ end
160
+
161
+ context 'with a circular reference' do
162
+ before do
163
+ value.a = value
164
+ end
165
+
166
+ it 'returns the object' do
167
+ should be(value)
168
+ end
169
+
170
+ it 'freezes the object' do
171
+ expect { subject }.should change(value, :frozen?).from(false).to(true)
172
+ end
173
+
174
+ it 'freezes each value in the Struct' do
175
+ subject.values.select(&:frozen?).should == subject.values
176
+ end
177
+ end
178
+ end
179
+
180
+ [0.0, 0, 0x7fffffffffffffff, true, false, nil, :symbol].each do |value|
181
+ context "with a #{value.class}" do
182
+ let(:value) { value }
183
+
184
+ it 'returns the object' do
185
+ should be(value)
186
+ end
187
+
188
+ it 'does not freeze the object' do
189
+ expect { subject }.should_not change(value, :frozen?).from(false)
190
+ end
191
+ end
192
+ end
193
+ end
@@ -6,188 +6,22 @@ require 'ice_nine'
6
6
  describe IceNine, '.deep_freeze' do
7
7
  subject { object.deep_freeze(value) }
8
8
 
9
- let(:object) { IceNine }
9
+ let(:object) { IceNine }
10
+ let(:value) { Object.new }
10
11
 
11
- context 'with an Object' do
12
- let(:value) { Object.new }
13
-
14
- before do
15
- value.instance_eval { @a = '1' }
16
- end
17
-
18
- it 'returns the object' do
19
- should be(value)
20
- end
21
-
22
- it 'freezes the object' do
23
- expect { subject }.should change(value, :frozen?).from(false).to(true)
24
- end
25
-
26
- it 'freezes the instance variables in the Object' do
27
- subject.instance_variable_get(:@a).should be_frozen
28
- end
29
-
30
- context 'with a circular reference' do
31
- before do
32
- value.instance_eval { @self = self }
33
- end
34
-
35
- it 'returns the object' do
36
- should be(value)
37
- end
38
-
39
- it 'freezes the object' do
40
- expect { subject }.should change(value, :frozen?).from(false).to(true)
41
- end
42
-
43
- it 'freezes the instance variables in the Object' do
44
- subject.instance_variable_get(:@a).should be_frozen
45
- end
46
- end
12
+ before do
13
+ value.instance_eval { @a = '1' }
47
14
  end
48
15
 
49
- context 'with an Array' do
50
- let(:value) { %w[a] }
51
-
52
- it 'returns the object' do
53
- should be(value)
54
- end
55
-
56
- it 'freezes the object' do
57
- expect { subject }.should change(value, :frozen?).from(false).to(true)
58
- end
59
-
60
- it 'freezes each element in the Array' do
61
- subject.select(&:frozen?).should == subject
62
- end
63
-
64
- context 'with a circular reference' do
65
- before do
66
- value << value
67
- end
68
-
69
- it 'returns the object' do
70
- should be(value)
71
- end
72
-
73
- it 'freezes the object' do
74
- expect { subject }.should change(value, :frozen?).from(false).to(true)
75
- end
76
-
77
- it 'freezes each element in the Array' do
78
- subject.select(&:frozen?).should == subject
79
- end
80
- end
16
+ it 'returns the object' do
17
+ should be(value)
81
18
  end
82
19
 
83
- context 'with a Hash' do
84
- let(:value) { { Object.new => Object.new } }
85
-
86
- it 'returns the object' do
87
- should be(value)
88
- end
89
-
90
- it 'freezes the object' do
91
- expect { subject }.should change(value, :frozen?).from(false).to(true)
92
- end
93
-
94
- it 'freezes each key in the Hash' do
95
- subject.keys.select(&:frozen?).should == subject.keys
96
- end
97
-
98
- it 'freezes each value in the Hash' do
99
- subject.values.select(&:frozen?).should == subject.values
100
- end
101
-
102
- context 'with a circular reference' do
103
- before do
104
- value[value] = value
105
- end
106
-
107
- it 'returns the object' do
108
- should be(value)
109
- end
110
-
111
- it 'freezes the object' do
112
- expect { subject }.should change(value, :frozen?).from(false).to(true)
113
- end
114
-
115
- it 'freezes each key in the Hash' do
116
- subject.keys.select(&:frozen?).should == subject.keys
117
- end
118
-
119
- it 'freezes each value in the Hash' do
120
- subject.values.select(&:frozen?).should == subject.values
121
- end
122
- end
123
- end
124
-
125
- context 'with a Range' do
126
- let(:value) { 'a'..'z' }
127
-
128
- it 'returns the object' do
129
- should be(value)
130
- end
131
-
132
- it 'freezes the object' do
133
- expect { subject }.should change(value, :frozen?).from(false).to(true)
134
- end
135
-
136
- it 'freeze the first object in the Range' do
137
- subject.begin.should be_frozen
138
- end
139
-
140
- it 'freeze the last object in the Range' do
141
- subject.end.should be_frozen
142
- end
143
- end
144
-
145
- context 'with a Struct' do
146
- let(:value) { klass.new('1') }
147
- let(:klass) { Struct.new(:a) }
148
-
149
- it 'returns the object' do
150
- should be(value)
151
- end
152
-
153
- it 'freezes the object' do
154
- expect { subject }.should change(value, :frozen?).from(false).to(true)
155
- end
156
-
157
- it 'freezes each value in the Struct' do
158
- subject.values.select(&:frozen?).should == subject.values
159
- end
160
-
161
- context 'with a circular reference' do
162
- before do
163
- value.a = value
164
- end
165
-
166
- it 'returns the object' do
167
- should be(value)
168
- end
169
-
170
- it 'freezes the object' do
171
- expect { subject }.should change(value, :frozen?).from(false).to(true)
172
- end
173
-
174
- it 'freezes each value in the Struct' do
175
- subject.values.select(&:frozen?).should == subject.values
176
- end
177
- end
20
+ it 'freezes the object' do
21
+ expect { subject }.should change(value, :frozen?).from(false).to(true)
178
22
  end
179
23
 
180
- [0.0, 0, 0x7fffffffffffffff, true, false, nil, :symbol].each do |value|
181
- context "with a #{value.class}" do
182
- let(:value) { value }
183
-
184
- it 'returns the object' do
185
- should be(value)
186
- end
187
-
188
- it 'does not freeze the object' do
189
- expect { subject }.should_not change(value, :frozen?).from(false)
190
- end
191
- end
24
+ it 'freezes the instance variables in the Object' do
25
+ subject.instance_variable_get(:@a).should be_frozen
192
26
  end
193
27
  end
@@ -2,7 +2,7 @@
2
2
 
3
3
  require 'spec_helper'
4
4
  require 'ice_nine/freezer'
5
- require 'ice_nine/freezer/struct'
5
+ require 'ice_nine/freezer/enumerable'
6
6
 
7
7
  describe IceNine::Freezer, '.[]' do
8
8
  subject { object[mod] }
@@ -2,14 +2,14 @@
2
2
 
3
3
  require 'spec_helper'
4
4
  require 'ice_nine/freezer'
5
- require 'ice_nine/freezer/array'
5
+ require 'ice_nine/freezer/enumerable'
6
6
 
7
- describe IceNine::Freezer::Array, '.deep_freeze' do
7
+ describe IceNine::Freezer::Enumerable, '.deep_freeze' do
8
8
  subject { object.deep_freeze(value) }
9
9
 
10
10
  let(:object) { described_class }
11
11
 
12
- context 'with an Array object' do
12
+ context 'with an Enumerable object' do
13
13
  let(:value) { %w[a] }
14
14
 
15
15
  it 'returns the object' do
@@ -20,7 +20,7 @@ describe IceNine::Freezer::Array, '.deep_freeze' do
20
20
  expect { subject }.should change(value, :frozen?).from(false).to(true)
21
21
  end
22
22
 
23
- it 'freezes each element in the Array' do
23
+ it 'freezes each entry in the Enumerable' do
24
24
  subject.select(&:frozen?).should == subject
25
25
  end
26
26
  end
metadata CHANGED
@@ -1,13 +1,13 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: ice_nine
3
3
  version: !ruby/object:Gem::Version
4
- hash: 23
4
+ hash: 19
5
5
  prerelease:
6
6
  segments:
7
7
  - 0
8
- - 2
8
+ - 3
9
9
  - 0
10
- version: 0.2.0
10
+ version: 0.3.0
11
11
  platform: ruby
12
12
  authors:
13
13
  - Dan Kubb
@@ -15,7 +15,7 @@ autorequire:
15
15
  bindir: bin
16
16
  cert_chain: []
17
17
 
18
- date: 2012-03-27 00:00:00 Z
18
+ date: 2012-03-29 00:00:00 Z
19
19
  dependencies:
20
20
  - !ruby/object:Gem::Dependency
21
21
  name: rake
@@ -81,20 +81,29 @@ files:
81
81
  - lib/ice_nine.rb
82
82
  - lib/ice_nine/core_ext/object.rb
83
83
  - lib/ice_nine/freezer.rb
84
- - lib/ice_nine/freezer/array.rb
84
+ - lib/ice_nine/freezer/enumerable.rb
85
+ - lib/ice_nine/freezer/false_class.rb
85
86
  - lib/ice_nine/freezer/hash.rb
87
+ - lib/ice_nine/freezer/hash/state.rb
88
+ - lib/ice_nine/freezer/nil_class.rb
86
89
  - lib/ice_nine/freezer/no_freeze.rb
90
+ - lib/ice_nine/freezer/numeric.rb
87
91
  - lib/ice_nine/freezer/object.rb
88
92
  - lib/ice_nine/freezer/range.rb
93
+ - lib/ice_nine/freezer/rubinius.rb
94
+ - lib/ice_nine/freezer/string.rb
89
95
  - lib/ice_nine/freezer/struct.rb
96
+ - lib/ice_nine/freezer/symbol.rb
97
+ - lib/ice_nine/freezer/true_class.rb
90
98
  - lib/ice_nine/support/recursion_guard.rb
91
99
  - lib/ice_nine/version.rb
100
+ - spec/integration/ice_nine/class_methods/deep_freeze_spec.rb
92
101
  - spec/rcov.opts
93
102
  - spec/spec.opts
94
103
  - spec/spec_helper.rb
95
104
  - spec/unit/ice_nine/class_methods/deep_freeze_spec.rb
96
- - spec/unit/ice_nine/freezer/array/class_methods/deep_freeze_spec.rb
97
105
  - spec/unit/ice_nine/freezer/class_methods/element_reference_spec.rb
106
+ - spec/unit/ice_nine/freezer/enumerable/class_methods/deep_freeze_spec.rb
98
107
  - spec/unit/ice_nine/freezer/false_class/class_methods/deep_freeze_spec.rb
99
108
  - spec/unit/ice_nine/freezer/hash/class_methods/deep_freeze_spec.rb
100
109
  - spec/unit/ice_nine/freezer/nil_class/class_methods/deep_freeze_spec.rb
@@ -1,26 +0,0 @@
1
- # encoding: utf-8
2
-
3
- module IceNine
4
- class Freezer
5
-
6
- # A freezer class for handling Array objects
7
- class Array < Object
8
-
9
- # Deep Freeze an Array
10
- #
11
- # @example
12
- # array = IceNine:Freezer::Array.deep_freeze(%w[a b c])
13
- # array.select(&:frozen?) # => ['a', 'b', 'c']
14
- #
15
- # @param [Array] array
16
- #
17
- # @return [Array]
18
- #
19
- # @api public
20
- def self.deep_freeze(array)
21
- super array.each(&:freeze)
22
- end
23
-
24
- end # class Array
25
- end # class Freezer
26
- end # module IceNine