Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP

Comparing changes

Choose two branches to see what's changed or to start a new pull request. If you need to, you can also compare across forks.

Open a pull request

Create a new pull request by comparing changes across two branches. If you need to, you can also compare across forks.
base: e9eaf5a3a9
...
compare: cf57c5771f
Checking mergeability… Don't worry, you can still create the pull request.
  • 11 commits
  • 12 files changed
  • 0 commit comments
  • 1 contributor
View
0  spec/rcov.opts → .rcov
File renamed without changes
View
4 .rspec
@@ -0,0 +1,4 @@
+--color
+--order random
+--format progress
+--profile
View
2  Gemfile
@@ -10,7 +10,7 @@ group :metrics do
gem 'flay', '~> 1.4.3'
gem 'flog', '~> 2.5.3'
gem 'map', '~> 5.4.0'
- gem 'reek', '~> 1.2.8', :git => 'git://github.com/dkubb/reek.git'
+ gem 'reek', '~> 1.2.8', :github => 'dkubb/reek'
gem 'roodi', '~> 2.1.0'
gem 'tailor', '~> 0.1.5'
gem 'yardstick', '~> 0.4.0'
View
3  TODO
@@ -0,0 +1,3 @@
+* Add a utility method that allows "NoFreeze" subclasses to be easily added for
+ any constant.
+ * Refactor the existing NoFreeze subclasses to use the method.
View
2  config/site.reek
@@ -11,7 +11,7 @@ LargeClass:
max_methods: 1
exclude: []
enabled: true
- max_instance_variables: 0
+ max_instance_variables: 1
UncommunicativeMethodName:
accept: []
exclude: []
View
2  ice_nine.gemspec
@@ -9,7 +9,7 @@ Gem::Specification.new do |gem|
gem.email = [ 'dan.kubb@gmail.com' ]
gem.description = 'Deep Freeze Ruby Objects'
gem.summary = gem.description
- gem.homepage = "https://github.com/dkubb/ice_nine"
+ gem.homepage = 'https://github.com/dkubb/ice_nine'
gem.require_paths = %w[ lib ]
gem.files = `git ls-files`.split("\n")
View
1  lib/ice_nine.rb
@@ -37,6 +37,7 @@ module IceNine
#
# @api public
def self.deep_freeze(object)
+ return object if object.frozen?
RecursionGuard.guard(object.object_id) do
Freezer[object.class].deep_freeze(object)
end
View
13 lib/ice_nine/freezer.rb
@@ -8,6 +8,14 @@ class Freezer
# Configure const_get and const_defined? to not search ancestors
SKIP_ANCESTORS = (RUBY_VERSION < '1.9' ? [] : [false]).freeze
+ # Cache the Freezer classes returned for each type
+ @freezer_cache = Hash.new do |cache, mod|
+ mod.ancestors.each do |ancestor|
+ freezer = find(ancestor.name.to_s)
+ break cache[mod] = freezer if freezer
+ end
+ end
+
# Look up the Freezer descendant by object type
#
# @example
@@ -19,10 +27,7 @@ class Freezer
#
# @api public
def self.[](mod)
- mod.ancestors.each do |ancestor|
- freezer = find(ancestor.name.to_s)
- return freezer if freezer
- end
+ @freezer_cache[mod]
end
# Find a Freezer descendant by name
View
2  lib/ice_nine/version.rb
@@ -3,6 +3,6 @@
module IceNine
# Current gem version
- VERSION = '0.3.0'
+ VERSION = '0.5.0'
end # module IceNine
View
3  spec/spec.opts
@@ -1,3 +0,0 @@
---color
---loadby random
---format profile
View
34 spec/unit/ice_nine/class_methods/deep_freeze_spec.rb
@@ -13,15 +13,35 @@
value.instance_eval { @a = '1' }
end
- it 'returns the object' do
- should be(value)
- end
+ context 'when the object is not frozen' do
+ it 'returns the object' do
+ should be(value)
+ end
+
+ it 'freezes the object' do
+ expect { subject }.should change(value, :frozen?).from(false).to(true)
+ end
- it 'freezes the object' do
- expect { subject }.should change(value, :frozen?).from(false).to(true)
+ it 'freezes the instance variables in the Object' do
+ subject.instance_variable_get(:@a).should be_frozen
+ end
end
- it 'freezes the instance variables in the Object' do
- subject.instance_variable_get(:@a).should be_frozen
+ context 'when the object is frozen' do
+ before do
+ value.freeze
+ end
+
+ it 'returns the object' do
+ should be(value)
+ end
+
+ it 'does not freeze the object' do
+ expect { subject }.should_not change(value, :frozen?).from(true)
+ end
+
+ it 'does not freeze the instance variables in the Object' do
+ subject.instance_variable_get(:@a).should_not be_frozen
+ end
end
end
View
2  tasks/spec.rake
@@ -27,7 +27,7 @@ begin
RSpec::Core::RakeTask.new(:coverage) do |t|
t.rcov = true
t.pattern = 'spec/unit/**/*_spec.rb'
- t.rcov_opts = File.read('spec/rcov.opts').split(/\s+/)
+ t.rcov_opts = File.read('.rcov').split(/\s+/)
end
else
desc 'Generate code coverage'

No commit comments for this range

Something went wrong with that request. Please try again.