Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Remove contracts.ruby as runtime dependency
- Loading branch information
1 parent
e343195
commit e256df3
Showing
6 changed files
with
52 additions
and
13 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,3 @@ | ||
$CONTRACTS = true | ||
|
||
require 'simplecov' | ||
SimpleCov.start | ||
|
||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,4 @@ | ||
$VERBOSE = false | ||
$CONTRACTS = true | ||
|
||
require 'simplecov' | ||
SimpleCov.start | ||
|