Browse Source

Retire lib/prepend.rb

We do not support Ruby 1.9 any more.
Akinori MUSHA 9 years ago
parent
commit
51e8414257
3 changed files with 0 additions and 110 deletions
  1. 0 22
      app/concerns/sortable_events.rb
  2. 0 3
      lib/ar_mysql_column_charset.rb
  3. 0 85
      lib/prepend.rb

+ 0 - 22
app/concerns/sortable_events.rb

@@ -158,26 +158,4 @@ module SortableEvents
       orders
     ).collect!(&:last)
   end
-
-  # The emulation of Module#prepend provided by lib/prepend.rb does
-  # not work for methods defined after a call of prepend.
-  if Module.method(:prepend).source_location
-    module ClassMethods
-      def can_order_created_events!
-        raise if cannot_create_events?
-        @can_order_created_events = true
-      end
-
-      def can_order_created_events?
-        !!@can_order_created_events
-      end
-    end
-
-    def initialize(*args)
-      if self.class.instance_variable_get(:@can_order_created_events)
-        self.class.__send__ :prepend, SortableEvents::AutomaticSorter
-      end
-      super
-    end
-  end
 end

+ 0 - 3
lib/ar_mysql_column_charset.rb

@@ -1,6 +1,3 @@
-# Module#prepend support for Ruby 1.9
-require 'prepend' unless Module.method_defined?(:prepend)
-
 require 'active_support'
 
 ActiveSupport.on_load :active_record do

+ 0 - 85
lib/prepend.rb

@@ -1,85 +0,0 @@
-# Fake implementation of prepend(), which does not support overriding
-# inherited methods nor methods that are formerly overridden by
-# another invocation of prepend().
-#
-# Here's what <Original>.prepend(<Wrapper>) does:
-#
-# - Create an anonymous stub module (hereinafter <Stub>) and define
-#   <Stub>#<method> that calls #<method>_without_<Wrapper> for each
-#   instance method of <Wrapper>.
-#
-# - Rename <Original>#<method> to #<method>_without_<Wrapper> for each
-#   instance method of <Wrapper>.
-#
-# - Include <Stub> and <Wrapper> into <Original> in that order.
-#
-# This way, a call of <Original>#<method> is dispatched to
-# <Wrapper><method>, which may call super which is dispatched to
-# <Stub>#<method>, which finally calls
-# <Original>#<method>_without_<Wrapper> which is used to be called
-# <Original>#<method>.
-#
-# Usage:
-#
-#     class Mechanize
-#       # module with methods that overrides those of X
-#       module Y
-#       end
-#
-#       unless X.respond_to?(:prepend, true)
-#         require 'mechanize/prependable'
-#         X.extend(Prependable)
-#       end
-#
-#       class X
-#         prepend Y
-#       end
-#     end
-class Module
-  def prepend(mod)
-    stub = Module.new
-
-    mod_id = (mod.name || 'Module__%d' % mod.object_id).gsub(/::/, '__')
-
-    mod.instance_methods.each { |name|
-      method_defined?(name) or next
-
-      original = instance_method(name)
-      next if original.owner != self
-
-      name = name.to_s
-      name_without = name.sub(/(?=[?!=]?\z)/) { '_without_%s' % mod_id }
-
-      arity = original.arity
-      arglist = (
-        if arity >= 0
-          (1..arity).map { |i| 'x%d' % i }
-        else
-          (1..(-arity - 1)).map { |i| 'x%d' % i } << '*a'
-        end << '&b'
-      ).join(', ')
-
-      if name.end_with?('=')
-        stub.module_eval %{
-          def #{name}(#{arglist})
-            __send__(:#{name_without}, #{arglist})
-          end
-        }
-      else
-        stub.module_eval %{
-          def #{name}(#{arglist})
-            #{name_without}(#{arglist})
-          end
-        }
-      end
-      module_eval {
-        alias_method name_without, name
-        remove_method name
-      }
-    }
-
-    include stub
-    include mod
-  end
-  private :prepend
-end unless Module.method_defined?(:prepend) || Module.private_method_defined?(:prepend)