#825 ✓resolved
Hussein Morsy

NameError Exception with dm-core (extlib) 0.9.11 and ActiveSuport

Reported by Hussein Morsy | March 30th, 2009 @ 07:42 AM

you can't use ActiveSupport with dm-core in version 0.9.11:


require 'rubygems'
require 'active_support'
require 'dm-core'      

=> Exception


NameError: method ‘to_time’ not defined in Time
method remove_method	in time.rb at line 26

The cause is the extlib: The same exception occur here:


require 'rubygems'
require 'active_support'
require 'exitlib'      

Comments and changes to this ticket

  • Hussein Morsy

    Hussein Morsy March 30th, 2009 @ 08:19 AM

    The Cause is commit 74c7e2 of datamapper/extlib

    file lib/extlib/datetime.rb #12 and lib/extlib/time.rb #12

    
    remove_method :to_time if method_defined?(:to_time) || private_method_defined?(:to_time)
    

    file lib/extlib/datetime.rb #25

    
     remove_method :to_datetime if method_defined?(:to_datetime) || private_method_defined?(:to_datetime)
    

    The Problem is, that method_defined? returns true no only if the named method is defined by the class, but also if the method is defined by its ancestors or its included modules.

    i transmitted a pull request.

    the following code solves the problem:

    
    remove_method :to_time if instance_methods.include?(:to_time)
    
  • joel hansson

    joel hansson April 3rd, 2009 @ 10:43 AM

    I can confirm this ticket.

    And the fix by Hussein Morsy works for me.

  • Dan Kubb (dkubb)

    Dan Kubb (dkubb) April 17th, 2009 @ 02:01 AM

    • State changed from “unconfirmed” to “confirmed”
    • Assigned user set to “Dan Kubb (dkubb)”

    Can you guys test out http://github.com/datamapper/ext... and let me know if it fixes the problems you were having?

  • Hussein Morsy

    Hussein Morsy April 18th, 2009 @ 11:36 AM

    sorry, same error:

    Example:

    
    # Module ExtTime defined be an other library
    module ExtTime
      def to_time
       #...
      end
    end
    
    # Class Time extended  by an other library e.g. ActiveSupport
    class Time
      include ExtTime
    end
    
    # Class Time extended by extlib
    class Time
      remove_method :to_time if instance_methods.any? { |m| m.to_sym == :to_time }
      def to_time
        #...
      end
    end
    

    Exception:NameError: method ‘to_time’ not defined in Time

    The cause is: The Method instance_methods by default return all also instance methods from its ancestors or its included modules. But instance_methods(false) returns only the instance methods directly defined in the class.:

    the following code works:

    
    # Class Time overridden by extlib
    class Time
      remove_method :to_time if instance_methods(false).any? { |m| m.to_sym == :to_time }
    end
    @@
    
    in my first post i forgot to mention the <code>false</code> paramter for the method <code>instance_methods</code>. Sorry. (see APIDock http://apidock.com/ruby/Module/instance_methods)
    
    By the way: Why is it necessary to remove the existing <code>to_time</code> method ? Is it not allowed to  simply overright the Method without removing it ?
    
  • Hussein Morsy

    Hussein Morsy April 18th, 2009 @ 11:52 AM

    the problem mentioned in the SproutCore Google Group:http://groups.google.com/group/sproutcore/browse_thread/thread/f4dfe044e9ac80c8

  • Dan Kubb (dkubb)

    Dan Kubb (dkubb) April 18th, 2009 @ 01:36 PM

    The reason for the removal of :to_time prior to patching it, is that I believe libraries should run clean with warnings turned on. I realize that's not a very common viewpoint but I think it should be for anyone who cares about the quality of their library.

    I began making extlib and DataMapper "warnings safe" since the last release, but I guess there are a few things still to be ironed out. Once I do I'll post a message someplace with what I learn about the process so that others can do the same to their gems if they wish.

  • Dan Kubb (dkubb)

    Dan Kubb (dkubb) April 20th, 2009 @ 12:48 AM

    @Hussein: I just committed the fix you mentioned in your last comment. Would you mind installing extlib from the "next" branch and let me know if it fixes your problem?

    If it does I can release a new extlib shortly to correct the incompatibility with ActiveSupport.

  • Hussein Morsy

    Hussein Morsy April 20th, 2009 @ 06:36 AM

    the problem with active support is now fixed. Thanks !!!

  • Bobby Wilson

    Bobby Wilson April 27th, 2009 @ 10:00 AM

    @Hussein what version of ActiveSupport are you running? I am running 2.3.2 and I still get the error with the 'next' branch of extlib.

  • Bobby Wilson

    Bobby Wilson April 27th, 2009 @ 10:22 AM

    Sorry, that last comment is incorrect, I was able to get it to work

  • Dan Kubb (dkubb)

    Dan Kubb (dkubb) April 29th, 2009 @ 12:44 AM

    • State changed from “confirmed” to “resolved”

    Awesome. I am marking this ticket as resolved.

    A new version of extlib will be released shortly.

Please Sign in or create a free account to add a new ticket.

With your very own profile, you can contribute to projects, track your activity, watch tickets, receive and update tickets through your email and much more.

New-ticket Create new ticket

Create your profile

Help contribute to this project by taking a few moments to create your personal profile. Create your profile »

Pages