Configuration Options in a new gem

P

Peer Allan

Hi all,

I am learning how to create my own gems today, but I have not been able
to find out how to configure the gem to accept configuration arguments.
If that didn't make any sense let me show you what I mean

In my gem I have a base class, that is setup like this:

Module MyGem
class Base

@@config_file = ''
cattr_accessor :config_file

def initialize
@@config = YAML.load_file(@@config_file)
end
end
end


I want to be able to set the option for the config at the top of a
script so that I don't have to do it for each class instance. Something
like this:

MyGem::Base.config_file = '../my_config.yml'

This is not working. I realized the the cattr_accessor needs
activesupport and I have added the necessary requires, but I am getting
an "undefined method" error when I try to use the gem. If there is
another way to do this I would love to know.

Sorry, if this doesn't make any sense. If you would like more details
please let me know.

Thanks

Peer
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
474,161
Messages
2,570,891
Members
47,423
Latest member
henerygril

Latest Threads

Top