Skip to content

Commit

Permalink
Remove contracts.ruby as runtime dependency
Browse files Browse the repository at this point in the history
  • Loading branch information
denisdefreyne committed Jun 19, 2016
1 parent e343195 commit e256df3
Show file tree
Hide file tree
Showing 6 changed files with 52 additions and 13 deletions.
1 change: 1 addition & 0 deletions Gemfile
Expand Up @@ -3,6 +3,7 @@ source 'https://rubygems.org'
gemspec

group :devel do
gem 'contracts', '~> 0.14'
gem 'coveralls', require: false
gem 'guard-rake'
gem 'fuubar'
Expand Down
1 change: 0 additions & 1 deletion lib/nanoc.rb
Expand Up @@ -33,7 +33,6 @@ def self.on_windows?
require 'time'
require 'yaml'
require 'English'
require 'contracts'

# Load Nanoc
require 'nanoc/version'
Expand Down
59 changes: 51 additions & 8 deletions lib/nanoc/base/contracts_support.rb
@@ -1,17 +1,60 @@
require 'singleton'

module Nanoc::Int
# @api private
module ContractsSupport
def self.included(base)
return if base.include?(::Contracts::Core)
class Ignorer
include Singleton

def method_missing(*_args)
self
end
end

module DisabledContracts
Any = Ignorer.instance
Bool = Ignorer.instance
Num = Ignorer.instance
KeywordArgs = Ignorer.instance
Optional = Ignorer.instance
Maybe = Ignorer.instance
None = Ignorer.instance
ArrayOf = Ignorer.instance
Or = Ignorer.instance
Func = Ignorer.instance
RespondTo = Ignorer.instance

base.include(::Contracts::Core)
base.extend(self)
base.const_set('C', ::Contracts)
def contract(*args)
end
end

def contract(*args)
return unless ENV['CONTRACTS'] || $CONTRACTS
Contract(*args)
module EnabledContracts
def contract(*args)
Contract(*args)
end
end

def self.included(base)
contracts_loadable =
begin
require 'contracts'
true
rescue LoadError
false
end

should_enable = contracts_loadable && !ENV.key?('DISABLE_CONTRACTS')

if should_enable
unless base.include?(::Contracts::Core)
base.include(::Contracts::Core)
base.extend(EnabledContracts)
base.const_set('C', ::Contracts)
end
else
base.extend(DisabledContracts)
base.const_set('C', DisabledContracts)
end
end
end
end
1 change: 0 additions & 1 deletion nanoc.gemspec
Expand Up @@ -25,7 +25,6 @@ Gem::Specification.new do |s|
s.required_ruby_version = '>= 2.1.0'

s.add_runtime_dependency('cri', '~> 2.3')
s.add_runtime_dependency('contracts', '~> 0.14')

s.add_development_dependency('bundler', '>= 1.7.10', '< 2.0')
end
2 changes: 0 additions & 2 deletions spec/spec_helper.rb
@@ -1,5 +1,3 @@
$CONTRACTS = true

require 'simplecov'
SimpleCov.start

Expand Down
1 change: 0 additions & 1 deletion test/helper.rb
@@ -1,5 +1,4 @@
$VERBOSE = false
$CONTRACTS = true

require 'simplecov'
SimpleCov.start
Expand Down

0 comments on commit e256df3

Please sign in to comment.