Skip to content

Commit

Permalink
Emit warning when contracts is loaded
Browse files Browse the repository at this point in the history
  • Loading branch information
denisdefreyne committed Feb 29, 2020
1 parent c3470b4 commit 9ccf3b0
Show file tree
Hide file tree
Showing 3 changed files with 28 additions and 1 deletion.
2 changes: 2 additions & 0 deletions common/spec/spec_helper_head_core.rb
Expand Up @@ -8,6 +8,8 @@
SimpleCov.formatter = SimpleCov::Formatter::Codecov
end

ENV['NANOC_DEV_MODE'] = 'true'

require 'fuubar'
require 'rspec/its'
require 'timecop'
Expand Down
20 changes: 20 additions & 0 deletions nanoc-core/lib/nanoc/core/contracts_support.rb
Expand Up @@ -103,6 +103,8 @@ def self.setup_once
::Contracts.const_set('Named', EnabledContracts::Named)
::Contracts.const_set('IterOf', EnabledContracts::IterOf)
::Contracts.const_set('AbsolutePathString', EnabledContracts::AbsolutePathString)

warn_about_performance
end

@_contracts_support__should_enable
Expand All @@ -126,6 +128,24 @@ def self.included(base)
base.const_set('C', DisabledContracts)
end
end

def self.warn_about_performance
return if ENV.key?('CI')
return if ENV.key?('NANOC_DEV_MODE')

puts '-' * 78
puts 'A NOTE ABOUT PERFORMANCE:'
puts 'The `contracts` gem is loaded, which enables extra run-time checks, but can drastically reduce Nanoc’s performance. The `contracts` gem is intended for development purposes, and is not recommended for day-to-day Nanoc usage.'
puts

if defined?(Bundler)
puts 'To speed up compilation, remove `contracts` from the Gemfile and run `bundle install`.'
else
puts 'To speed up compilation, either uninstall the `contracts` gem, or use Bundler (https://bundler.io/) with a Gemfile that doesn’t include `contracts`.'
end

puts '-' * 78
end
end
end
end
7 changes: 6 additions & 1 deletion nanoc-core/spec/meta_spec.rb
Expand Up @@ -76,7 +76,12 @@

it 'doesn’t log anything' do
# TODO: don’t have any exceptions
regular_files = Dir['lib/nanoc/core/**/*.rb'] - ['lib/nanoc/core/data_source.rb']
regular_files =
Dir['lib/nanoc/core/**/*.rb'] -
[
'lib/nanoc/core/data_source.rb',
'lib/nanoc/core/contracts_support.rb',
]

expect(regular_files).to all(satisfy do |fn|
content = File.read(fn)
Expand Down

0 comments on commit 9ccf3b0

Please sign in to comment.