SitePoint Sponsor

User Tag List

Results 1 to 3 of 3

Threaded View

  1. #1
    SitePoint Zealot
    Join Date
    Jul 2004
    Location
    NC
    Posts
    194
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Problems w/ class_inheritable_accessor - setting base class vars

    Hello,
    I'm overriding the initialize method of a base class and I'm trying to get a class_inheritable_accessor class variable to register in the base class but I'm failing miserably.

    Here's my code:

    Code:
    class Base
      include Options
      class_inheritable_accessor :spec
    
      def initialize(runtime_args, runtime_options = {})
        @args = runtime_args
        parse!(@args, runtime_options)
      
        # Derive source and destination paths.
        @source_root = options[:source] || File.join(spec.path, 'templates')
      end
    end
    
    class MediaModuleGenerator < Rails::Generator::Base 
      def initialize(runtime_args, runtime_options = {})
         self.spec.path = File.dirname(__FILE__) + '/generators/media_module'    
         super
      end
    end
    When I run my generator, I get this error:

    You have a nil object when you didn't expect it! (NoMethodError) The error occurred while evaluating nil.path

    So when I set the self.spec.path var to File.dirname(__FILE__) + '/generators/media_module', it's not registering in the base class.

    Any ideas?
    Last edited by clem_c_rock; May 29, 2009 at 21:24.


Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •