[DRE-commits] [ruby-deprecated] 01/04: Imported Upstream version 3.0.1

Dmitry Borodaenko angdraug at alioth.debian.org
Sat Aug 10 22:27:35 UTC 2013


This is an automated email from the git hooks/post-receive script.

angdraug pushed a commit to branch master
in repository ruby-deprecated.

commit 28ecaa0dc239c868c25d6a760bbfab6bfecccd42
Author: Dmitry Borodaenko <angdraug at gmail.com>
Date:   Sat Aug 10 13:45:34 2013 -0700

    Imported Upstream version 3.0.1
---
 .gitignore              |    3 +
 MIT-LICENSE.txt         |   20 +++++
 README                  |   70 +++++++++++++++
 Rakefile                |   68 ++++++---------
 lib/deprecated.rb       |  220 +++++++++++++++++++++++------------------------
 metadata.yml            |   64 --------------
 test/test_deprecated.rb |  154 +++++++++++++++++----------------
 7 files changed, 308 insertions(+), 291 deletions(-)

diff --git a/.gitignore b/.gitignore
new file mode 100644
index 0000000..430fd22
--- /dev/null
+++ b/.gitignore
@@ -0,0 +1,3 @@
+.test-result
+pkg
+rdoc
diff --git a/MIT-LICENSE.txt b/MIT-LICENSE.txt
new file mode 100644
index 0000000..65209cc
--- /dev/null
+++ b/MIT-LICENSE.txt
@@ -0,0 +1,20 @@
+Copyright (c) Erik Hollensbe
+
+Permission is hereby granted, free of charge, to any person obtaining
+a copy of this software and associated documentation files (the
+"Software"), to deal in the Software without restriction, including
+without limitation the rights to use, copy, modify, merge, publish,
+distribute, sublicense, and/or sell copies of the Software, and to
+permit persons to whom the Software is furnished to do so, subject to
+the following conditions:
+
+The above copyright notice and this permission notice shall be
+included in all copies or substantial portions of the Software.
+
+THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
+EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
+MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
+NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
+LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
+OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
+WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
\ No newline at end of file
diff --git a/README b/README
new file mode 100644
index 0000000..ba74a83
--- /dev/null
+++ b/README
@@ -0,0 +1,70 @@
+Deprecated is a module to help you deprecate code BEFORE you remove it. Don't
+surprise your users, deprecate them!
+
+Usage is simple:
+
+    class Foo
+      include Deprecated
+
+      def moo
+        "cow"
+      end
+
+      deprecated :moo
+
+      def sheep
+        "baaa"
+      end
+
+      deprecated :sheep, "Sounds#baa"
+
+      protected
+
+      def bar
+        true
+      end
+
+      deprecated :bar
+    end
+    
+    Foo.new.moo # warns that the call is deprecated
+    
+    Deprecated.set_action(:raise)
+    Foo.new.moo # raises with the same message
+
+    Deprecated.set_action do |klass, sym, replacement|
+      email_boss(
+        "Someone tried to use #{klass}##{sym}! " +
+        "They should be using #{replacement} instead!"
+      )
+    end
+
+    Foo.new.sheep # do I really need to explain?
+
+    Foo.new.bar # still protected!
+
+Let's do it live!
+
+    class Bar
+      include Deprecated
+
+      # sets it just for this class
+      deprecated_set_action do |klass, sym, replacement|
+        email_boss(
+          "Someone tried to use #{klass}##{sym}! " +
+          "They should be using #{replacement} instead!"
+        )
+      end
+
+      def cow
+        "moo"
+      end
+
+      deprecate :cow # emails your boss when called!
+    end
+
+Please see Deprecated::Module#deprecated, Deprecated.set_action, and
+Deprecated::Module#deprecated_set_action for more information.
+
+This library is released under the MIT license:
+* http://www.opensource.org/licenses/MIT
\ No newline at end of file
diff --git a/Rakefile b/Rakefile
index 525d03c..d0e5010 100644
--- a/Rakefile
+++ b/Rakefile
@@ -2,18 +2,14 @@
 # Please see the COPYING file in the source distribution for copyright information.
 # 
 
-begin
-    require 'rubygems'
-    gem 'test-unit'
-rescue LoadError
-end
-
-$:.unshift 'lib'
+require 'rubygems'
+require 'rubygems/package_task'
 require 'rake/testtask'
-require 'rake/packagetask'
-require 'rake/gempackagetask'
 require 'rdoc/task'
+
+$:.unshift 'lib'
 require 'deprecated'
+$:.shift
 
 task :default => [ :dist ]
 
@@ -22,9 +18,9 @@ task :default => [ :dist ]
 #
 
 Rake::TestTask.new do |t|
-    t.libs << 'lib'
-    t.test_files = FileList['test/test*.rb']
-    t.verbose = true 
+  t.libs << 'lib'
+  t.test_files = FileList['test/test*.rb']
+  t.verbose = true 
 end
 
 #
@@ -35,21 +31,16 @@ task :dist      => [:test, :repackage, :gem, :rdoc]
 task :distclean => [:clobber_package, :clobber_rdoc]
 task :clean     => [:distclean]
 
-task :to_blog => [:clobber_rdoc, :rdoc] do
-    sh "rm -r $git/blog/content/docs/deprecated && mv rdoc $git/blog/content/docs/deprecated"
-end
-
-
 #
 # Documentation
 #
 
 RDoc::Task.new do |rd|
-    rd.rdoc_dir = "rdoc"
-    rd.main = "README"
-    rd.rdoc_files.include("README")
-    rd.rdoc_files.include("./lib/**/*.rb")
-    rd.options = %w(-a)
+  rd.rdoc_dir = "rdoc"
+  rd.main = "README"
+  rd.rdoc_files.include("README")
+  rd.rdoc_files.include("./lib/**/*.rb")
+  rd.options = %w(-a)
 end
 
 #
@@ -57,25 +48,20 @@ end
 # 
 
 spec = Gem::Specification.new do |s|
-    s.name = "deprecated"
-    s.version = Deprecated::VERSION
-    s.author = "Erik Hollensbe"
-    s.email = "erik at hollensbe.org"
-    s.summary = "An easy way to handle deprecating and conditionally running deprecated code"
-    s.has_rdoc = true
-    s.files = Dir['Rakefile'] + Dir['lib/deprecated.rb'] + Dir['test/test_deprecated.rb']
-    s.test_file = "test/test_deprecated.rb"
-    s.rubyforge_project = 'deprecated'
-end
-
-Rake::GemPackageTask.new(spec) do |s|
+  s.name = "deprecated"
+  s.version = Deprecated::VERSION
+  s.author = "Erik Hollensbe"
+  s.email = "erik at hollensbe.org"
+  s.summary = "An easy way to handle deprecating and conditionally running deprecated code"
+  s.has_rdoc = true
+  s.files = Dir['Rakefile'] + Dir['lib/deprecated.rb'] + Dir['test/test_deprecated.rb']
+  s.test_file = "test/test_deprecated.rb"
+  s.rubyforge_project = 'deprecated'
+  s.license = "MIT"
+  s.add_development_dependency "test-unit", ">= 0"
 end
 
-Rake::PackageTask.new(spec.name, spec.version) do |p|
-    p.need_tar_gz = true
-    p.need_zip = true
-    p.package_files.include("./setup.rb")
-    p.package_files.include("./Rakefile")
-    p.package_files.include("./lib/**/*.rb")
-    p.package_files.include("./test/**/*")
+Gem::PackageTask.new(spec) do |p|
+  p.need_tar_gz = true
+  p.need_zip = true
 end
diff --git a/lib/deprecated.rb b/lib/deprecated.rb
index ad3e734..b0eacdd 100644
--- a/lib/deprecated.rb
+++ b/lib/deprecated.rb
@@ -70,134 +70,134 @@ class DeprecatedError < StandardError; end
 # Deprecated::Module#deprecated_set_action for more information.
 #
 module Deprecated
-    VERSION = "3.0.0"
+  VERSION = "3.0.1"
 
-    def __deprecated_run_action__(sym, replacement)
-        if self.class.instance_eval { @__deprecated_run_action__ }
-            self.class.instance_eval { @__deprecated_run_action__ }.call(self.class, sym, replacement) 
-        else
-            Deprecated.run_action(self.class, sym, replacement)
-        end
+  def __deprecated_run_action__(sym, replacement)
+    if self.class.instance_eval { @__deprecated_run_action__ }
+      self.class.instance_eval { @__deprecated_run_action__ }.call(self.class, sym, replacement) 
+    else
+      Deprecated.run_action(self.class, sym, replacement)
     end
+  end
 
-    def self.build_message(klass, sym, replacement)
-        message = "#{klass}##{sym} is deprecated."
-
-        if replacement
-            message += " Please use #{replacement}."
-        end
+  def self.build_message(klass, sym, replacement)
+    message = "#{klass}##{sym} is deprecated."
 
-        return message
+    if replacement
+      message += " Please use #{replacement}."
     end
 
-    #
-    # set_action takes 3 "canned" arguments or an arbitrary block. If you
-    # provide the block, any canned argument is ignored.
-    #
-    # The canned arguments are:
-    #
-    # :warn:: display a warning
-    # :raise:: raise a DeprecatedError (a kind of StandardError) with the warning.
-    # :fail:: fail. die. kaput. it's over.
-    #
-    # Procs take three arguments:
-    #
-    # - The class of the method
-    # - The method name itself, a symbol
-    # - A replacement string which may be nil
-    #
-    def self.set_action(type=nil, &block)
-        @action = if block
-                      block
-                  else
-                      case type
-                      when :warn
-                          proc { |*args| warn build_message(*args) }
-                      when :fail
-                          proc { |*args| fail build_message(*args) }
-                      when :raise
-                          proc { |*args| raise DeprecatedError, build_message(*args) }
-                      else
-                          raise ArgumentError, "you must provide a symbol or a block to set_action()."
-                      end
-                  end
-    end
+    return message
+  end
 
-    # 
-    # Is called when an action needs to be run. Proably not in your best
-    # interest to run this directly.
-    #
-    def self.run_action(klass, sym, replacement)
-        raise "run_action has no associated hook" unless @action
-        @action.call(klass, sym, replacement)
-    end
+  #
+  # set_action takes 3 "canned" arguments or an arbitrary block. If you
+  # provide the block, any canned argument is ignored.
+  #
+  # The canned arguments are:
+  #
+  # :warn:: display a warning
+  # :raise:: raise a DeprecatedError (a kind of StandardError) with the warning.
+  # :fail:: fail. die. kaput. it's over.
+  #
+  # Procs take three arguments:
+  #
+  # - The class of the method
+  # - The method name itself, a symbol
+  # - A replacement string which may be nil
+  #
+  def self.set_action(type=nil, &block)
+    @action = if block
+                block
+              else
+                case type
+                when :warn
+                  proc { |*args| warn build_message(*args) }
+                when :fail
+                  proc { |*args| fail build_message(*args) }
+                when :raise
+                  proc { |*args| raise DeprecatedError, build_message(*args) }
+                else
+                  raise ArgumentError, "you must provide a symbol or a block to set_action()."
+                end
+              end
+  end
 
-    #
-    # Returns the current action; this may be block or Proc.
-    #
-    def self.action
-        @action
-    end
+  # 
+  # Is called when an action needs to be run. Proably not in your best
+  # interest to run this directly.
+  #
+  def self.run_action(klass, sym, replacement)
+    raise "run_action has no associated hook" unless @action
+    @action.call(klass, sym, replacement)
+  end
+
+  #
+  # Returns the current action; this may be block or Proc.
+  #
+  def self.action
+    @action
+  end
 end
 
 module Deprecated
-    module Module
+  module Module
 
-        #
-        # deprecated takes up to three arguments:
-        #
-        # - A symbol which is the name of the method you wish to deprecate
-        #   (required)
-        # - A string or symbol which is the replacement method. If you provide
-        #   this, your users will be instructed to use that method instead.
-        # - A symbol of :public, :private, or :protected which determines the
-        #   new scope of the method. If you do not provide one, it will be
-        #   searched for in the various collections, and scope will be chosen
-        #   that way.
-        # 
-        def deprecated(sym, replacement=nil, scope=nil)
-            unless sym.kind_of?(Symbol)
-                raise ArgumentError, "deprecated() requires symbols for its first argument." 
-            end
+    #
+    # deprecated takes up to three arguments:
+    #
+    # - A symbol which is the name of the method you wish to deprecate
+    #   (required)
+    # - A string or symbol which is the replacement method. If you provide
+    #   this, your users will be instructed to use that method instead.
+    # - A symbol of :public, :private, or :protected which determines the
+    #   new scope of the method. If you do not provide one, it will be
+    #   searched for in the various collections, and scope will be chosen
+    #   that way.
+    # 
+    def deprecated(sym, replacement=nil, scope=nil)
+      unless sym.kind_of?(Symbol)
+        raise ArgumentError, "deprecated() requires symbols for its first argument." 
+      end
 
-            meth = instance_method(sym)
-            unless scope
-                pub = public_instance_methods
-                pro = protected_instance_methods
-                pri = private_instance_methods
-                if pub.include?(sym) or pub.include?(sym.to_s)
-                    scope = :public
-                elsif pro.include?(sym) or pro.include?(sym.to_s)
-                    scope = :protected
-                elsif pri.include?(sym) or pri.include?(sym.to_s)
-                    scope = :private
-                end
-            end
+      meth = instance_method(sym)
+      unless scope
+        pub = public_instance_methods
+        pro = protected_instance_methods
+        pri = private_instance_methods
+        if pub.include?(sym) or pub.include?(sym.to_s)
+          scope = :public
+        elsif pro.include?(sym) or pro.include?(sym.to_s)
+          scope = :protected
+        elsif pri.include?(sym) or pri.include?(sym.to_s)
+          scope = :private
+        end
+      end
 
-            define_method(sym) do |*args|
-                dep_meth = method(sym).unbind
-                __deprecated_run_action__(sym, replacement)
-                retval = meth.bind(self).call(*args) 
-                dep_meth.bind(self)
-                return retval
-            end
+      define_method(sym) do |*args|
+        dep_meth = method(sym).unbind
+        __deprecated_run_action__(sym, replacement)
+        retval = meth.bind(self).call(*args) 
+        dep_meth.bind(self)
+        return retval
+      end
 
-            method(scope).call(sym) if scope
-            return scope
-        end
+      method(scope).call(sym) if scope
+      return scope
+    end
 
-        #
-        # Deprecated.set_action for class scope. See Deprecated.set_action.
-        #
-        def deprecated_set_action(&block)
-            raise "You must provide a block" unless block
-            @__deprecated_run_action__ = block
-        end
+    #
+    # Deprecated.set_action for class scope. See Deprecated.set_action.
+    #
+    def deprecated_set_action(&block)
+      raise "You must provide a block" unless block
+      @__deprecated_run_action__ = block
     end
+  end
     
-    def self.included(base)
-        base.extend(Module)
-    end
+  def self.included(base)
+    base.extend(Module)
+  end
 end
 
 Deprecated.set_action(:warn)
diff --git a/metadata.yml b/metadata.yml
deleted file mode 100644
index f83ce73..0000000
--- a/metadata.yml
+++ /dev/null
@@ -1,64 +0,0 @@
---- !ruby/object:Gem::Specification 
-name: deprecated
-version: !ruby/object:Gem::Version 
-  prerelease: false
-  segments: 
-  - 3
-  - 0
-  - 0
-  version: 3.0.0
-platform: ruby
-authors: 
-- Erik Hollensbe
-autorequire: 
-bindir: bin
-cert_chain: []
-
-date: 2010-05-05 00:00:00 -04:00
-default_executable: 
-dependencies: []
-
-description: 
-email: erik at hollensbe.org
-executables: []
-
-extensions: []
-
-extra_rdoc_files: []
-
-files: 
-- Rakefile
-- lib/deprecated.rb
-- test/test_deprecated.rb
-has_rdoc: true
-homepage: 
-licenses: []
-
-post_install_message: 
-rdoc_options: []
-
-require_paths: 
-- lib
-required_ruby_version: !ruby/object:Gem::Requirement 
-  requirements: 
-  - - ">="
-    - !ruby/object:Gem::Version 
-      segments: 
-      - 0
-      version: "0"
-required_rubygems_version: !ruby/object:Gem::Requirement 
-  requirements: 
-  - - ">="
-    - !ruby/object:Gem::Version 
-      segments: 
-      - 0
-      version: "0"
-requirements: []
-
-rubyforge_project: deprecated
-rubygems_version: 1.3.6
-signing_key: 
-specification_version: 3
-summary: An easy way to handle deprecating and conditionally running deprecated code
-test_files: 
-- test/test_deprecated.rb
diff --git a/test/test_deprecated.rb b/test/test_deprecated.rb
index a490837..1e65f20 100644
--- a/test/test_deprecated.rb
+++ b/test/test_deprecated.rb
@@ -3,111 +3,113 @@
 require 'rubygems'
 gem 'test-unit'
 require 'test/unit'
-require 'lib/deprecated.rb'
+$:.unshift 'lib'
+require 'deprecated.rb'
+$:.shift
 
 # this class is used to test the deprecate functionality
 class DummyClass
-    include Deprecated
+  include Deprecated
 
-    def monkey
-        return true
-    end
+  def monkey
+    return true
+  end
 
-    def monkey_bars
-        return true
-    end
+  def monkey_bars
+    return true
+  end
 
-    deprecated :monkey
-    deprecated :monkey_bars, "FooClass#fart"
+  deprecated :monkey
+  deprecated :monkey_bars, "FooClass#fart"
 
-    protected
+  protected
 
-    def my_protected 
-        return true
-    end
+  def my_protected 
+    return true
+  end
 
-    deprecated :my_protected
+  deprecated :my_protected
 
-    private
+  private
 
-    def my_private
-        return true
-    end
+  def my_private
+    return true
+  end
 
-    deprecated :my_private
+  deprecated :my_private
 end
 
 class DummyClass2
-    include Deprecated
+  include Deprecated
 
-    deprecated_set_action do |klass, sym, replacement|
-        raise DeprecatedError, "foo!"
-    end
+  deprecated_set_action do |klass, sym, replacement|
+    raise DeprecatedError, "foo!"
+  end
 
-    def monkey
-        return true
-    end
+  def monkey
+    return true
+  end
 
-    deprecated :monkey
+  deprecated :monkey
 end
 
 # we want exceptions for testing here.
 Deprecated.set_action(:raise)
 
 class DeprecateTest < Test::Unit::TestCase
-    def test_set_action
-        assert_raises(DeprecatedError) { DummyClass.new.monkey }
-
-        Deprecated.set_action { |klass, sym| raise DeprecatedError.new("#{klass}##{sym} is deprecated.") }
-        assert_raises(DeprecatedError.new("DummyClass#monkey is deprecated.")) do 
-            DummyClass.new.monkey 
-        end
+  def test_set_action
+    assert_raises(DeprecatedError) { DummyClass.new.monkey }
 
-        Deprecated.set_action(:raise)
-
-        assert_raises(DeprecatedError.new("DummyClass#monkey is deprecated.")) do 
-            DummyClass.new.monkey 
-        end
-
-        # set to warn and make sure our return values are getting through.
-        Deprecated.set_action(:warn)
-        assert(DummyClass.new.monkey)
-
-        Kernel.module_eval { 
-            def self.fail
-                raise "failed"
-            end
-        }
-        
-        Deprecated.set_action(:fail)
-
-        assert_raises("failed") { DummyClass.new.monkey }
+    Deprecated.set_action { |klass, sym| raise DeprecatedError.new("#{klass}##{sym} is deprecated.") }
+    assert_raises(DeprecatedError.new("DummyClass#monkey is deprecated.")) do 
+      DummyClass.new.monkey 
     end
 
-    def test_scope
-        assert(
-            DummyClass.public_instance_methods.include?(:monkey) ||
-            DummyClass.public_instance_methods.include?("monkey")
-        )
-        assert(
-            DummyClass.protected_instance_methods.include?(:my_protected) ||
-            DummyClass.protected_instance_methods.include?("my_protected")
-        )
-        assert(
-            DummyClass.private_instance_methods.include?(:my_private) ||
-            DummyClass.private_instance_methods.include?("my_private")
-        )
-    end
+    Deprecated.set_action(:raise)
 
-    def test_scoped_actions
-        assert_raises(DeprecatedError.new("foo!")) { DummyClass2.new.monkey }
+    assert_raises(DeprecatedError.new("DummyClass#monkey is deprecated.")) do 
+      DummyClass.new.monkey 
     end
 
-    def test_replacement
-        Deprecated.set_action(:raise)
-
-        assert_raises(DeprecatedError.new("DummyClass#monkey_bars is deprecated. Please use FooClass#fart.")) do 
-            DummyClass.new.monkey_bars
-        end
+    # set to warn and make sure our return values are getting through.
+    Deprecated.set_action(:warn)
+    assert(DummyClass.new.monkey)
+
+    Kernel.module_eval { 
+      def self.fail
+        raise "failed"
+      end
+    }
+
+    Deprecated.set_action(:fail)
+
+    assert_raises("failed") { DummyClass.new.monkey }
+  end
+
+  def test_scope
+    assert(
+      DummyClass.public_instance_methods.include?(:monkey) ||
+      DummyClass.public_instance_methods.include?("monkey")
+    )
+    assert(
+      DummyClass.protected_instance_methods.include?(:my_protected) ||
+      DummyClass.protected_instance_methods.include?("my_protected")
+    )
+    assert(
+      DummyClass.private_instance_methods.include?(:my_private) ||
+      DummyClass.private_instance_methods.include?("my_private")
+    )
+  end
+
+  def test_scoped_actions
+    assert_raises(DeprecatedError.new("foo!")) { DummyClass2.new.monkey }
+  end
+
+  def test_replacement
+    Deprecated.set_action(:raise)
+
+    assert_raises(DeprecatedError.new("DummyClass#monkey_bars is deprecated. Please use FooClass#fart.")) do 
+      DummyClass.new.monkey_bars
     end
+  end
 end

-- 
Alioth's /usr/local/bin/git-commit-notice on /srv/git.debian.org/git/pkg-ruby-extras/ruby-deprecated.git



More information about the Pkg-ruby-extras-commits mailing list