ice_nine 0.3.0 → 0.4.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.
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', :git => 'git://github.com/dkubb/reek.git'
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'
@@ -11,7 +11,7 @@ LargeClass:
11
11
  max_methods: 1
12
12
  exclude: []
13
13
  enabled: true
14
- max_instance_variables: 0
14
+ max_instance_variables: 1
15
15
  UncommunicativeMethodName:
16
16
  accept: []
17
17
  exclude: []
@@ -37,6 +37,7 @@ module IceNine
37
37
  #
38
38
  # @api public
39
39
  def self.deep_freeze(object)
40
+ return object if object.frozen?
40
41
  RecursionGuard.guard(object.object_id) do
41
42
  Freezer[object.class].deep_freeze(object)
42
43
  end
@@ -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.ancestors.each do |ancestor|
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
@@ -3,6 +3,6 @@
3
3
  module IceNine
4
4
 
5
5
  # Current gem version
6
- VERSION = '0.3.0'
6
+ VERSION = '0.4.0'
7
7
 
8
8
  end # module IceNine
@@ -13,15 +13,35 @@ describe IceNine, '.deep_freeze' do
13
13
  value.instance_eval { @a = '1' }
14
14
  end
15
15
 
16
- it 'returns the object' do
17
- should be(value)
18
- end
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
- it 'freezes the object' do
21
- expect { subject }.should change(value, :frozen?).from(false).to(true)
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
- it 'freezes the instance variables in the Object' do
25
- subject.instance_variable_get(:@a).should be_frozen
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: 19
4
+ hash: 15
5
5
  prerelease:
6
6
  segments:
7
7
  - 0
8
- - 3
8
+ - 4
9
9
  - 0
10
- version: 0.3.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-03-29 00:00:00 Z
18
+ date: 2012-04-01 00:00:00 Z
19
19
  dependencies:
20
20
  - !ruby/object:Gem::Dependency
21
21
  name: rake