ice_nine 0.8.0 → 0.9.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.
- checksums.yaml +15 -0
- data/.rspec +5 -0
- data/.travis.yml +23 -12
- data/Gemfile +3 -65
- data/Gemfile.devtools +55 -0
- data/Rakefile +2 -6
- data/config/devtools.yml +2 -0
- data/config/flay.yml +2 -2
- data/config/flog.yml +1 -1
- data/config/mutant.yml +3 -0
- data/config/{site.reek → reek.yml} +63 -48
- data/config/rubocop.yml +62 -0
- data/config/yardstick.yml +1 -1
- data/lib/ice_nine.rb +1 -0
- data/lib/ice_nine/freezer.rb +3 -6
- data/lib/ice_nine/freezer/hash.rb +3 -2
- data/lib/ice_nine/freezer/module.rb +10 -0
- data/lib/ice_nine/support/recursion_guard.rb +5 -5
- data/lib/ice_nine/version.rb +1 -1
- data/spec/integration/ice_nine/class_methods/deep_freeze_spec.rb +16 -16
- data/spec/spec_helper.rb +18 -11
- data/spec/unit/ice_nine/class_methods/deep_freeze_spec.rb +2 -2
- data/spec/unit/ice_nine/freezer/array/class_methods/deep_freeze_spec.rb +1 -1
- data/spec/unit/ice_nine/freezer/class_methods/{element_reference_spec.rb → element_reader_spec.rb} +55 -4
- data/spec/unit/ice_nine/freezer/hash/class_methods/deep_freeze_spec.rb +12 -12
- data/spec/unit/ice_nine/freezer/module/class_methods/deep_freeze_spec.rb +24 -0
- data/spec/unit/ice_nine/freezer/no_freeze/class_methods/deep_freeze_spec.rb +1 -1
- data/spec/unit/ice_nine/freezer/object/class_methods/deep_freeze_spec.rb +1 -1
- data/spec/unit/ice_nine/freezer/range/class_methods/deep_freeze_spec.rb +2 -2
- data/spec/unit/ice_nine/freezer/struct/class_methods/deep_freeze_spec.rb +1 -1
- data/spec/unit/ice_nine/recursion_guard/class_methods/guard_spec.rb +2 -2
- metadata +16 -24
- data/spec/rcov.opts +0 -7
- data/spec/spec.opts +0 -3
- data/spec/support/heckle.rb +0 -8
- data/tasks/metrics/ci.rake +0 -9
- data/tasks/metrics/flay.rake +0 -45
- data/tasks/metrics/flog.rake +0 -44
- data/tasks/metrics/heckle.rake +0 -207
- data/tasks/metrics/metric_fu.rake +0 -31
- data/tasks/metrics/roodi.rake +0 -19
- data/tasks/metrics/yardstick.rake +0 -25
- data/tasks/spec.rake +0 -60
- data/tasks/yard.rake +0 -11
data/config/yardstick.yml
CHANGED
@@ -1,2 +1,2 @@
|
|
1
1
|
---
|
2
|
-
threshold: 100
|
2
|
+
threshold: 100
|
data/lib/ice_nine.rb
CHANGED
@@ -13,6 +13,7 @@ require 'ice_nine/freezer/false_class'
|
|
13
13
|
require 'ice_nine/freezer/hash'
|
14
14
|
require 'ice_nine/freezer/hash/state'
|
15
15
|
require 'ice_nine/freezer/nil_class'
|
16
|
+
require 'ice_nine/freezer/module'
|
16
17
|
require 'ice_nine/freezer/numeric'
|
17
18
|
require 'ice_nine/freezer/range'
|
18
19
|
require 'ice_nine/freezer/rubinius'
|
data/lib/ice_nine/freezer.rb
CHANGED
@@ -5,15 +5,14 @@ module IceNine
|
|
5
5
|
# The default class that handles freezing objects
|
6
6
|
class Freezer
|
7
7
|
|
8
|
-
# Configure const_get and const_defined? to not search ancestors
|
9
|
-
SKIP_ANCESTORS = (RUBY_VERSION < '1.9' ? [] : [false]).freeze
|
10
|
-
|
11
8
|
# Cache the Freezer classes returned for each type
|
12
9
|
@freezer_cache = Hash.new do |cache, mod|
|
10
|
+
cache[mod] = nil
|
13
11
|
mod.ancestors.each do |ancestor|
|
14
12
|
freezer = find(ancestor.name.to_s)
|
15
13
|
break cache[mod] = freezer if freezer
|
16
14
|
end
|
15
|
+
cache[mod]
|
17
16
|
end
|
18
17
|
|
19
18
|
# Look up the Freezer descendant by object type
|
@@ -60,9 +59,7 @@ module IceNine
|
|
60
59
|
#
|
61
60
|
# @api private
|
62
61
|
def self.const_lookup(namespace)
|
63
|
-
if const_defined?(namespace,
|
64
|
-
const_get(namespace, *SKIP_ANCESTORS)
|
65
|
-
end
|
62
|
+
const_get(namespace) if const_defined?(namespace, nil)
|
66
63
|
end
|
67
64
|
|
68
65
|
class << self
|
@@ -20,10 +20,11 @@ module IceNine
|
|
20
20
|
# @api public
|
21
21
|
def self.deep_freeze(hash)
|
22
22
|
IceNine.deep_freeze(hash.default_proc || hash.default)
|
23
|
-
|
23
|
+
hash.each do |key, value|
|
24
24
|
IceNine.deep_freeze(key)
|
25
25
|
IceNine.deep_freeze(value)
|
26
|
-
|
26
|
+
end
|
27
|
+
super
|
27
28
|
end
|
28
29
|
|
29
30
|
end # class Hash
|
@@ -12,19 +12,19 @@ module IceNine
|
|
12
12
|
# logic_which_may_recursively_call_the_containing_method
|
13
13
|
# end
|
14
14
|
#
|
15
|
-
# @param [Integer]
|
15
|
+
# @param [Integer] caller_object_id
|
16
16
|
#
|
17
17
|
# @return [Object]
|
18
18
|
#
|
19
19
|
# @api public
|
20
|
-
def self.guard(
|
20
|
+
def self.guard(caller_object_id)
|
21
21
|
objects = guarded_objects(caller.first)
|
22
|
-
return if objects.include?(
|
22
|
+
return if objects.include?(caller_object_id)
|
23
23
|
begin
|
24
|
-
objects <<
|
24
|
+
objects << caller_object_id
|
25
25
|
yield
|
26
26
|
ensure
|
27
|
-
objects.delete(
|
27
|
+
objects.delete(caller_object_id)
|
28
28
|
end
|
29
29
|
end
|
30
30
|
|
data/lib/ice_nine/version.rb
CHANGED
@@ -25,7 +25,7 @@ describe IceNine, '.deep_freeze' do
|
|
25
25
|
end
|
26
26
|
|
27
27
|
it 'freezes the instance variables in the Object' do
|
28
|
-
subject.instance_variable_get(:@a).
|
28
|
+
expect(subject.instance_variable_get(:@a)).to be_frozen
|
29
29
|
end
|
30
30
|
|
31
31
|
context 'with a circular reference' do
|
@@ -42,7 +42,7 @@ describe IceNine, '.deep_freeze' do
|
|
42
42
|
end
|
43
43
|
|
44
44
|
it 'freezes the instance variables in the Object' do
|
45
|
-
subject.instance_variable_get(:@a).
|
45
|
+
expect(subject.instance_variable_get(:@a)).to be_frozen
|
46
46
|
end
|
47
47
|
end
|
48
48
|
end
|
@@ -59,7 +59,7 @@ describe IceNine, '.deep_freeze' do
|
|
59
59
|
end
|
60
60
|
|
61
61
|
it 'freezes each element in the Array' do
|
62
|
-
subject.select(&:frozen?).
|
62
|
+
expect(subject.select(&:frozen?)).to eql(subject)
|
63
63
|
end
|
64
64
|
|
65
65
|
context 'with a circular reference' do
|
@@ -76,7 +76,7 @@ describe IceNine, '.deep_freeze' do
|
|
76
76
|
end
|
77
77
|
|
78
78
|
it 'freezes each element in the Array' do
|
79
|
-
subject.select(&:frozen?).
|
79
|
+
expect(subject.select(&:frozen?)).to eql(subject)
|
80
80
|
end
|
81
81
|
end
|
82
82
|
end
|
@@ -93,11 +93,11 @@ describe IceNine, '.deep_freeze' do
|
|
93
93
|
end
|
94
94
|
|
95
95
|
it 'freezes each key in the Hash' do
|
96
|
-
subject.keys.select(&:frozen?).
|
96
|
+
expect(subject.keys.select(&:frozen?)).to eql(subject.keys)
|
97
97
|
end
|
98
98
|
|
99
99
|
it 'freezes each value in the Hash' do
|
100
|
-
subject.values.select(&:frozen?).
|
100
|
+
expect(subject.values.select(&:frozen?)).to eql(subject.values)
|
101
101
|
end
|
102
102
|
|
103
103
|
context 'with a circular reference' do
|
@@ -114,11 +114,11 @@ describe IceNine, '.deep_freeze' do
|
|
114
114
|
end
|
115
115
|
|
116
116
|
it 'freezes each key in the Hash' do
|
117
|
-
subject.keys.select(&:frozen?).
|
117
|
+
expect(subject.keys.select(&:frozen?)).to eql(subject.keys)
|
118
118
|
end
|
119
119
|
|
120
120
|
it 'freezes each value in the Hash' do
|
121
|
-
subject.values.select(&:frozen?).
|
121
|
+
expect(subject.values.select(&:frozen?)).to eql(subject.values)
|
122
122
|
end
|
123
123
|
end
|
124
124
|
end
|
@@ -135,11 +135,11 @@ describe IceNine, '.deep_freeze' do
|
|
135
135
|
end
|
136
136
|
|
137
137
|
it 'freeze the first object in the Range' do
|
138
|
-
subject.begin.
|
138
|
+
expect(subject.begin).to be_frozen
|
139
139
|
end
|
140
140
|
|
141
141
|
it 'freeze the last object in the Range' do
|
142
|
-
subject.end.
|
142
|
+
expect(subject.end).to be_frozen
|
143
143
|
end
|
144
144
|
end
|
145
145
|
|
@@ -159,7 +159,7 @@ describe IceNine, '.deep_freeze' do
|
|
159
159
|
end
|
160
160
|
|
161
161
|
it 'freezes the instance variables in the String' do
|
162
|
-
subject.instance_variable_get(:@a).
|
162
|
+
expect(subject.instance_variable_get(:@a)).to be_frozen
|
163
163
|
end
|
164
164
|
|
165
165
|
context 'with a circular reference' do
|
@@ -176,7 +176,7 @@ describe IceNine, '.deep_freeze' do
|
|
176
176
|
end
|
177
177
|
|
178
178
|
it 'freezes the instance variables in the String' do
|
179
|
-
subject.instance_variable_get(:@a).
|
179
|
+
expect(subject.instance_variable_get(:@a)).to be_frozen
|
180
180
|
end
|
181
181
|
end
|
182
182
|
end
|
@@ -194,7 +194,7 @@ describe IceNine, '.deep_freeze' do
|
|
194
194
|
end
|
195
195
|
|
196
196
|
it 'freezes each value in the Struct' do
|
197
|
-
subject.values.select(&:frozen?).
|
197
|
+
expect(subject.values.select(&:frozen?)).to eql(subject.values)
|
198
198
|
end
|
199
199
|
|
200
200
|
context 'with a circular reference' do
|
@@ -211,7 +211,7 @@ describe IceNine, '.deep_freeze' do
|
|
211
211
|
end
|
212
212
|
|
213
213
|
it 'freezes each value in the Struct' do
|
214
|
-
subject.values.select(&:frozen?).
|
214
|
+
expect(subject.values.select(&:frozen?)).to eql(subject.values)
|
215
215
|
end
|
216
216
|
end
|
217
217
|
end
|
@@ -232,7 +232,7 @@ describe IceNine, '.deep_freeze' do
|
|
232
232
|
end
|
233
233
|
|
234
234
|
it 'freezes the instance variables in the SimpleDelegator' do
|
235
|
-
subject.instance_variable_get(:@a).
|
235
|
+
expect(subject.instance_variable_get(:@a)).to be_frozen
|
236
236
|
end
|
237
237
|
|
238
238
|
context 'with a circular reference' do
|
@@ -249,7 +249,7 @@ describe IceNine, '.deep_freeze' do
|
|
249
249
|
end
|
250
250
|
|
251
251
|
it 'freezes the instance variables in the SimpleDelegator' do
|
252
|
-
subject.instance_variable_get(:@a).
|
252
|
+
expect(subject.instance_variable_get(:@a)).to be_frozen
|
253
253
|
end
|
254
254
|
end
|
255
255
|
end
|
data/spec/spec_helper.rb
CHANGED
@@ -2,22 +2,29 @@
|
|
2
2
|
|
3
3
|
if ENV['COVERAGE'] == 'true'
|
4
4
|
require 'simplecov'
|
5
|
+
require 'coveralls'
|
6
|
+
|
7
|
+
SimpleCov.formatter = SimpleCov::Formatter::MultiFormatter[
|
8
|
+
SimpleCov::Formatter::HTMLFormatter,
|
9
|
+
Coveralls::SimpleCov::Formatter
|
10
|
+
]
|
5
11
|
|
6
12
|
SimpleCov.start do
|
7
|
-
command_name
|
8
|
-
|
9
|
-
add_filter
|
13
|
+
command_name 'spec:unit'
|
14
|
+
|
15
|
+
add_filter 'config'
|
16
|
+
add_filter 'spec'
|
17
|
+
add_filter 'vendor'
|
18
|
+
|
10
19
|
minimum_coverage 100
|
11
20
|
end
|
12
21
|
end
|
13
22
|
|
14
|
-
require '
|
15
|
-
require '
|
23
|
+
require 'ice_nine'
|
24
|
+
require 'devtools/spec_helper'
|
16
25
|
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
end
|
21
|
-
|
22
|
-
Spec::Runner.configure do |config|
|
26
|
+
RSpec.configure do |config|
|
27
|
+
config.expect_with :rspec do |expect_with|
|
28
|
+
expect_with.syntax = :expect
|
29
|
+
end
|
23
30
|
end
|
@@ -23,7 +23,7 @@ describe IceNine, '.deep_freeze' do
|
|
23
23
|
end
|
24
24
|
|
25
25
|
it 'freezes the instance variables in the Object' do
|
26
|
-
subject.instance_variable_get(:@a).
|
26
|
+
expect(subject.instance_variable_get(:@a)).to be_frozen
|
27
27
|
end
|
28
28
|
end
|
29
29
|
|
@@ -41,7 +41,7 @@ describe IceNine, '.deep_freeze' do
|
|
41
41
|
end
|
42
42
|
|
43
43
|
it 'does not freeze the instance variables in the Object' do
|
44
|
-
subject.instance_variable_get(:@a).
|
44
|
+
expect(subject.instance_variable_get(:@a)).to_not be_frozen
|
45
45
|
end
|
46
46
|
end
|
47
47
|
end
|
data/spec/unit/ice_nine/freezer/class_methods/{element_reference_spec.rb → element_reader_spec.rb}
RENAMED
@@ -45,12 +45,12 @@ describe IceNine::Freezer, '.[]' do
|
|
45
45
|
Object.send(:remove_const, :Application)
|
46
46
|
end
|
47
47
|
|
48
|
-
|
48
|
+
around do |example|
|
49
49
|
namespace.const_set(:User, freezer)
|
50
50
|
object.const_set(:Application, namespace)
|
51
|
-
end
|
52
51
|
|
53
|
-
|
52
|
+
example.run
|
53
|
+
|
54
54
|
namespace.send(:remove_const, :User)
|
55
55
|
object.send(:remove_const, :Application)
|
56
56
|
end
|
@@ -77,11 +77,62 @@ describe IceNine::Freezer, '.[]' do
|
|
77
77
|
end
|
78
78
|
end
|
79
79
|
|
80
|
-
describe 'when the module is anonymous' do
|
80
|
+
describe 'when the module is an anonymous class' do
|
81
81
|
let(:mod) { Class.new }
|
82
82
|
|
83
83
|
it 'returns the freezer' do
|
84
84
|
should be(freezer)
|
85
85
|
end
|
86
86
|
end
|
87
|
+
|
88
|
+
describe 'when the module is an anonymous module' do
|
89
|
+
let(:mod) { Module.new }
|
90
|
+
|
91
|
+
it 'returns the freezer' do
|
92
|
+
should be_nil
|
93
|
+
end
|
94
|
+
end
|
95
|
+
|
96
|
+
describe 'when the module is under a freezer namespace' do
|
97
|
+
let(:mod) { Hash::Test }
|
98
|
+
let(:freezer) { IceNine::Freezer::Hash }
|
99
|
+
|
100
|
+
around do |example|
|
101
|
+
class Hash::Test; end
|
102
|
+
example.run
|
103
|
+
Hash.send(:remove_const, :Test)
|
104
|
+
end
|
105
|
+
|
106
|
+
it 'returns the freezer' do
|
107
|
+
should be(freezer)
|
108
|
+
end
|
109
|
+
end
|
110
|
+
|
111
|
+
describe 'when the module has a name of a freezer in another namespace' do
|
112
|
+
let(:mod) { Mash::State }
|
113
|
+
let(:freezer) { Class.new(IceNine::Freezer::Hash) }
|
114
|
+
|
115
|
+
before :all do
|
116
|
+
module ::Mash
|
117
|
+
class State; end
|
118
|
+
end
|
119
|
+
end
|
120
|
+
|
121
|
+
after :all do
|
122
|
+
::Mash.send(:remove_const, :State)
|
123
|
+
Object.send(:remove_const, :Mash)
|
124
|
+
end
|
125
|
+
|
126
|
+
around do |example|
|
127
|
+
object.const_set(:Mash, freezer)
|
128
|
+
|
129
|
+
example.run
|
130
|
+
|
131
|
+
object.send(:remove_const, :Mash)
|
132
|
+
end
|
133
|
+
|
134
|
+
it 'returns the freezer' do
|
135
|
+
should be(freezer)
|
136
|
+
end
|
137
|
+
end
|
87
138
|
end
|
@@ -22,24 +22,24 @@ describe IceNine::Freezer::Hash, '.deep_freeze' do
|
|
22
22
|
end
|
23
23
|
|
24
24
|
it 'freezes the default proc' do
|
25
|
-
subject.default_proc.
|
25
|
+
expect(subject.default_proc).to be_frozen
|
26
26
|
end
|
27
27
|
|
28
28
|
it 'freezes each key in the Hash' do
|
29
|
-
subject.keys.select(&:frozen?).
|
29
|
+
expect(subject.keys.select(&:frozen?)).to eql(subject.keys)
|
30
30
|
end
|
31
31
|
|
32
32
|
it 'freezes each value in the Hash' do
|
33
|
-
subject.values.select(&:frozen?).
|
33
|
+
expect(subject.values.select(&:frozen?)).to eql(subject.values)
|
34
34
|
end
|
35
35
|
|
36
|
-
if RUBY_VERSION >= '1.9'
|
36
|
+
if RUBY_VERSION >= '1.9' && RUBY_ENGINE == 'rbx'
|
37
37
|
it 'does not freeze the Hash state' do
|
38
|
-
subject.instance_variable_get(:@state).
|
38
|
+
expect(subject.instance_variable_get(:@state)).to_not be_frozen
|
39
39
|
end
|
40
40
|
|
41
41
|
it 'does not freeze the Hash entries' do
|
42
|
-
subject.instance_variable_get(:@entries).
|
42
|
+
expect(subject.instance_variable_get(:@entries)).to_not be_frozen
|
43
43
|
end
|
44
44
|
end
|
45
45
|
end
|
@@ -58,24 +58,24 @@ describe IceNine::Freezer::Hash, '.deep_freeze' do
|
|
58
58
|
end
|
59
59
|
|
60
60
|
it 'freezes the default value' do
|
61
|
-
subject.default.
|
61
|
+
expect(subject.default).to be_frozen
|
62
62
|
end
|
63
63
|
|
64
64
|
it 'freezes each key in the Hash' do
|
65
|
-
subject.keys.select(&:frozen?).
|
65
|
+
expect(subject.keys.select(&:frozen?)).to eql(subject.keys)
|
66
66
|
end
|
67
67
|
|
68
68
|
it 'freezes each value in the Hash' do
|
69
|
-
subject.values.select(&:frozen?).
|
69
|
+
expect(subject.values.select(&:frozen?)).to eql(subject.values)
|
70
70
|
end
|
71
71
|
|
72
|
-
if RUBY_VERSION >= '1.9'
|
72
|
+
if RUBY_VERSION >= '1.9' && RUBY_ENGINE == 'rbx'
|
73
73
|
it 'does not freeze the Hash state' do
|
74
|
-
subject.instance_variable_get(:@state).
|
74
|
+
expect(subject.instance_variable_get(:@state)).to_not be_frozen
|
75
75
|
end
|
76
76
|
|
77
77
|
it 'does not freeze the Hash entries' do
|
78
|
-
subject.instance_variable_get(:@entries).
|
78
|
+
expect(subject.instance_variable_get(:@entries)).to_not be_frozen
|
79
79
|
end
|
80
80
|
end
|
81
81
|
end
|
@@ -0,0 +1,24 @@
|
|
1
|
+
# encoding: utf-8
|
2
|
+
|
3
|
+
require 'spec_helper'
|
4
|
+
require 'ice_nine/freezer'
|
5
|
+
require 'ice_nine/freezer/no_freeze'
|
6
|
+
require 'ice_nine/freezer/module'
|
7
|
+
|
8
|
+
describe IceNine::Freezer::Module, '.deep_freeze' do
|
9
|
+
subject { object.deep_freeze(value) }
|
10
|
+
|
11
|
+
let(:object) { described_class }
|
12
|
+
|
13
|
+
context 'with a Module object' do
|
14
|
+
let(:value) { Module.new }
|
15
|
+
|
16
|
+
it 'returns the object' do
|
17
|
+
should be(value)
|
18
|
+
end
|
19
|
+
|
20
|
+
it 'does not freeze the object' do
|
21
|
+
expect { subject }.to_not change(value, :frozen?).from(false)
|
22
|
+
end
|
23
|
+
end
|
24
|
+
end
|