-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
closes #3
- Loading branch information
Mike Blumtritt
committed
Feb 17, 2015
1 parent
62f31f1
commit 8ffb2b6
Showing
14 changed files
with
384 additions
and
436 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
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,6 +1,6 @@ | ||
require File.expand_path('../lib/deprecations/version', __FILE__) | ||
|
||
GemSpec= Gem::Specification.new do |spec| | ||
GemSpec = Gem::Specification.new do |spec| | ||
spec.required_rubygems_version = Gem::Requirement.new('>= 1.3.6') | ||
spec.platform = Gem::Platform::RUBY | ||
spec.required_ruby_version = '>= 2.0.0' | ||
|
@@ -9,20 +9,22 @@ GemSpec= Gem::Specification.new do |spec| | |
spec.authors = ['Mike Blumtritt'] | ||
spec.email = %w[[email protected]] | ||
spec.summary = 'Deprecation support for your project.' | ||
spec.description = 'This gem provides transparent declaration of deprecated methods and classes.' | ||
spec.description = "This gem provides transparent declaration of deprecated methods and classes. "\ | ||
"It's easy, small, has no dependencies and no overhead." | ||
spec.homepage = 'https://github.com/mblumtritt/deprecations' | ||
spec.date = Time.now.strftime('%Y-%m-%d') | ||
spec.require_paths = %w[lib] | ||
spec.files = %x[git ls-files].split($/) | ||
spec.test_files = spec.files.grep(%r[^test/]) | ||
spec.extra_rdoc_files = %w[README.md] | ||
spec.test_files = spec.files.grep(%r[^spec/]) | ||
spec.extra_rdoc_files = %w[README.md CHANGELOG.md] | ||
spec.has_rdoc = false # TODO! | ||
spec.add_development_dependency 'rake' | ||
spec.add_development_dependency 'rspec', '>= 3.0.0' | ||
spec.add_development_dependency 'guard' | ||
spec.add_development_dependency 'guard-rspec' | ||
if /darwin|mac os/i =~ RUBY_PLATFORM | ||
spec.add_development_dependency 'rb-fsevent' | ||
spec.add_development_dependency 'terminal-notifier' | ||
spec.add_development_dependency 'terminal-notifier-guard' | ||
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,40 +1,14 @@ | ||
|
||
DeprecationError = Class.new(ScriptError) | ||
|
||
module Deprecations | ||
autoload(:VERSION, "#{__FILE__[/.*(?=\..+$)/]}/version") | ||
require_relative 'deprecations/configuration' | ||
require_relative 'deprecations/extension' | ||
require_relative 'deprecations/behavior' | ||
|
||
class << self | ||
|
||
def call(subject, alternative, outdated) | ||
case configuration.behavior | ||
when :warn | ||
warn(subject, alternative, outdated) | ||
when :raise | ||
throw!(subject, alternative) | ||
end | ||
self | ||
end | ||
|
||
private | ||
|
||
def throw!(subject, alternative) | ||
msg = "`#{subject}` is deprecated" | ||
alternative and msg << " - use #{alternative} instead" | ||
ex = DeprecationError.new(msg) | ||
ex.set_backtrace(caller(3)) | ||
raise(ex) | ||
end | ||
|
||
def warn(subject, alternative, outdated) | ||
location = ::Kernel.caller_locations(3,1).last and location = "#{location.path}:#{location.lineno}: " | ||
msg = "#{location}[DEPRECATION] `#{subject}` is deprecated" | ||
msg << (outdated ? " and will be outdated #{outdated}." : '.') | ||
alternative and msg << " Please use `#{alternative}` instead." | ||
::Kernel.warn(msg) | ||
end | ||
|
||
def self.call(subject, alternative, outdated) | ||
@behavior.call(subject, alternative, outdated) | ||
self | ||
end | ||
|
||
self.behavior = :warn | ||
end | ||
|
||
DeprecationError = Class.new(ScriptError) |
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 |
---|---|---|
@@ -0,0 +1,55 @@ | ||
module Deprecations | ||
class << self | ||
|
||
def behavior | ||
BEHAVIOR.key(@behavior) || @behavior | ||
end | ||
|
||
def behavior=(behavior) | ||
@behavior = as_behavior(behavior) | ||
end | ||
|
||
def set_behavior(behavior) | ||
behavior = as_behavior(behavior) | ||
block_given? or raise(ArgumentError, 'block expected') | ||
current_behavior = @behavior | ||
begin | ||
@behavior = behavior | ||
yield | ||
ensure | ||
@behavior = current_behavior | ||
end | ||
end | ||
|
||
private | ||
|
||
def as_behavior(arg) | ||
defined?(arg.call) ? arg : BEHAVIOR.fetch(arg) do | ||
raise(ArgumentError, "invalid parameter - behavior has to be #{valid_behavior} or need to respond to `call`") | ||
end | ||
end | ||
|
||
def valid_behavior | ||
BEHAVIOR.keys.map(&:inspect).join(' | ') | ||
end | ||
|
||
BEHAVIOR = { | ||
silence: ->(*){}, | ||
raise: proc do |subject, alternative| | ||
msg = "`#{subject}` is deprecated" | ||
alternative and msg << " - use #{alternative} instead" | ||
ex = ::DeprecationError.new(msg) | ||
ex.set_backtrace(caller(4)) | ||
raise(ex) | ||
end, | ||
warn: proc do |subject, alternative, outdated | | ||
location = caller_locations(4, 1).last and location = "#{location.path}:#{location.lineno}: " | ||
msg = "#{location}[DEPRECATION] `#{subject}` is deprecated" | ||
msg << (outdated ? " and will be outdated #{outdated}." : '.') | ||
alternative and msg << " Please use `#{alternative}` instead." | ||
::Kernel.warn(msg) | ||
end | ||
} | ||
|
||
end | ||
end |
This file was deleted.
Oops, something went wrong.
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,3 +1,3 @@ | ||
module Deprecations | ||
VERSION = '1.0.6' | ||
VERSION = '2.0.0pre' | ||
end |
Oops, something went wrong.