ice_nine 0.3.0 → 0.4.0
Sign up to get free protection for your applications and to get access to all the features.
- data/Gemfile +1 -1
- data/config/site.reek +1 -1
- data/lib/ice_nine.rb +1 -0
- data/lib/ice_nine/freezer.rb +9 -4
- data/lib/ice_nine/version.rb +1 -1
- data/spec/unit/ice_nine/class_methods/deep_freeze_spec.rb +27 -7
- metadata +4 -4
data/Gemfile
CHANGED
@@ -10,7 +10,7 @@ group :metrics do
|
|
10
10
|
gem 'flay', '~> 1.4.3'
|
11
11
|
gem 'flog', '~> 2.5.3'
|
12
12
|
gem 'map', '~> 5.4.0'
|
13
|
-
gem 'reek', '~> 1.2.8', :
|
13
|
+
gem 'reek', '~> 1.2.8', :github => 'dkubb/reek'
|
14
14
|
gem 'roodi', '~> 2.1.0'
|
15
15
|
gem 'tailor', '~> 0.1.5'
|
16
16
|
gem 'yardstick', '~> 0.4.0'
|
data/config/site.reek
CHANGED
data/lib/ice_nine.rb
CHANGED
data/lib/ice_nine/freezer.rb
CHANGED
@@ -8,6 +8,14 @@ module IceNine
|
|
8
8
|
# Configure const_get and const_defined? to not search ancestors
|
9
9
|
SKIP_ANCESTORS = (RUBY_VERSION < '1.9' ? [] : [false]).freeze
|
10
10
|
|
11
|
+
# Cache the Freezer classes returned for each type
|
12
|
+
@freezer_cache = Hash.new do |cache, mod|
|
13
|
+
mod.ancestors.each do |ancestor|
|
14
|
+
freezer = find(ancestor.name.to_s)
|
15
|
+
break cache[mod] = freezer if freezer
|
16
|
+
end
|
17
|
+
end
|
18
|
+
|
11
19
|
# Look up the Freezer descendant by object type
|
12
20
|
#
|
13
21
|
# @example
|
@@ -19,10 +27,7 @@ module IceNine
|
|
19
27
|
#
|
20
28
|
# @api public
|
21
29
|
def self.[](mod)
|
22
|
-
mod
|
23
|
-
freezer = find(ancestor.name.to_s)
|
24
|
-
return freezer if freezer
|
25
|
-
end
|
30
|
+
@freezer_cache[mod]
|
26
31
|
end
|
27
32
|
|
28
33
|
# Find a Freezer descendant by name
|
data/lib/ice_nine/version.rb
CHANGED
@@ -13,15 +13,35 @@ describe IceNine, '.deep_freeze' do
|
|
13
13
|
value.instance_eval { @a = '1' }
|
14
14
|
end
|
15
15
|
|
16
|
-
|
17
|
-
|
18
|
-
|
16
|
+
context 'when the object is not frozen' do
|
17
|
+
it 'returns the object' do
|
18
|
+
should be(value)
|
19
|
+
end
|
20
|
+
|
21
|
+
it 'freezes the object' do
|
22
|
+
expect { subject }.should change(value, :frozen?).from(false).to(true)
|
23
|
+
end
|
19
24
|
|
20
|
-
|
21
|
-
|
25
|
+
it 'freezes the instance variables in the Object' do
|
26
|
+
subject.instance_variable_get(:@a).should be_frozen
|
27
|
+
end
|
22
28
|
end
|
23
29
|
|
24
|
-
|
25
|
-
|
30
|
+
context 'when the object is frozen' do
|
31
|
+
before do
|
32
|
+
value.freeze
|
33
|
+
end
|
34
|
+
|
35
|
+
it 'returns the object' do
|
36
|
+
should be(value)
|
37
|
+
end
|
38
|
+
|
39
|
+
it 'does not freeze the object' do
|
40
|
+
expect { subject }.should_not change(value, :frozen?).from(true)
|
41
|
+
end
|
42
|
+
|
43
|
+
it 'does not freeze the instance variables in the Object' do
|
44
|
+
subject.instance_variable_get(:@a).should_not be_frozen
|
45
|
+
end
|
26
46
|
end
|
27
47
|
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:
|
4
|
+
hash: 15
|
5
5
|
prerelease:
|
6
6
|
segments:
|
7
7
|
- 0
|
8
|
-
-
|
8
|
+
- 4
|
9
9
|
- 0
|
10
|
-
version: 0.
|
10
|
+
version: 0.4.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-
|
18
|
+
date: 2012-04-01 00:00:00 Z
|
19
19
|
dependencies:
|
20
20
|
- !ruby/object:Gem::Dependency
|
21
21
|
name: rake
|