Sha256: e39311129137226e29f5d454bd034fb0e54536cef2ae0a21e6debb3c691af551

Contents?: true

Size: 1.67 KB

Versions: 10

Compression:

Stored size: 1.67 KB

Contents

module ActsAsFerret
  if defined?(BasicObject)
    # Ruby 1.9.x
    class BlankSlate < BasicObject
    end
  elsif defined?(BlankSlate)
    # Rails 2.x has it already
    class BlankSlate < ::BlankSlate
    end
  else
    # 'backported' for Rails pre 2.0
    #
    #--
    # Copyright 2004, 2006 by Jim Weirich (jim@weirichhouse.org).
    # All rights reserved.

    # Permission is granted for use, copying, modification, distribution,
    # and distribution of modified versions of this work as long as the
    # above copyright notice is included.
    #++

    ######################################################################
    # BlankSlate provides an abstract base class with no predefined
    # methods (except for <tt>\_\_send__</tt> and <tt>\_\_id__</tt>).
    # BlankSlate is useful as a base class when writing classes that
    # depend upon <tt>method_missing</tt> (e.g. dynamic proxies).
    #
    class BlankSlate
      class << self
        # Hide the method named +name+ in the BlankSlate class.  Don't
        # hide +instance_eval+ or any method beginning with "__".
        def hide(name)
          if instance_methods.include?(name.to_s) and name !~ /^(__|instance_eval|methods)/
            @hidden_methods ||= {}
            @hidden_methods[name.to_sym] = instance_method(name)
            undef_method name
          end
        end

        # Redefine a previously hidden method so that it may be called on a blank
        # slate object.
        #
        # no-op here since we don't hide the methods we reveal where this is
        # used in this implementation
        def reveal(name)
        end
      end

      instance_methods.each { |m| hide(m) }

    end

  end
end

Version data entries

10 entries across 10 versions & 2 rubygems

Version Path
watson-acts_as_ferret-0.4.8.2 lib/blank_slate.rb
acts_as_ferret-0.5.2 lib/acts_as_ferret/blank_slate.rb
acts_as_ferret-0.4.8.2 lib/blank_slate.rb
acts_as_ferret-0.4.8.1 lib/blank_slate.rb
acts_as_ferret-0.5.1 lib/acts_as_ferret/blank_slate.rb
acts_as_ferret-0.5 lib/acts_as_ferret/blank_slate.rb
acts_as_ferret-0.4.8.rails3 lib/blank_slate.rb
acts_as_ferret-0.4.8 lib/blank_slate.rb
acts_as_ferret-0.4.7 lib/blank_slate.rb
acts_as_ferret-0.4.6 lib/blank_slate.rb