Hello,
I'm overriding the initialize method of a base class and I'm trying
to set a Base class variable in the overridden method and have it
register in the Base class (hope that makes sense).
Here's my code:
[code]
in Rails::Generator::Base:
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
[/code]
I should mention that spec is a module w/in the Rails framework IE:
Rails::Generator::Spec
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?
--
Posted via http://www.ruby-forum.com/.
--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups "Ruby
on Rails: Talk" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to
[email protected]
For more options, visit this group at
http://groups.google.com/group/rubyonrails-talk?hl=en
-~----------~----~----~----~------~----~------~--~---