Forum: Ruby Configuration Options in a new gem

Announcement (2017-05-07): is now read-only since I unfortunately do not have the time to support and maintain the forum any more. Please see and for other Rails- und Ruby-related community platforms.
4520451c5b8c7cb8d5f9a40db1d47d69?d=identicon&s=25 Peer Allan (Guest)
on 2007-05-07 22:39
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)

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.


This topic is locked and can not be replied to.