Not imposing your dependencies in Ruby

A

Anselm

Hello,

I was wondering about not imposing some dependencies when I release a
Ruby library. Say I have a class used to detect the (natural) language
of a text. To run, objects of this class need some data files, the
location of which must be known. It is fine to have this location as a
class-wide settings (all objects will use the same data files), so I
make the setting as a class instance variable :

class LanguageDetect
@path_to_ngrams = "data/ngrams"

class<<self
attr_accessor :path_to_ngrams
end
# [......]
end

Now, I'd rather use my own Config library ; which allows me to set the
default value, the command line switch to look for, get the value
directly from config files, etc. I'd have something like this :

class LanguageDetect
extend Configurable
config_option :path_to_ngrams {
default "data/ngrams"
switch "--path-to-ngrams"
}

# [....]
end

This is much more practical for me to use in my own applications.
However, if I release the LanguageDetect class on it's own, I don't
want to impose the dependency on my Config library to everyone else (as
people might want to integrate it in their own application which works
differently).

What is the best way to achieve this ? I could think of several
solutions :

1. Just change the code when releasing the library on it's own
2. Keep the 'config_option' call in a separate file, that depends on
the application rather than the library
3. include some light version of the Config library with the
LanguageDetect library which would create the class instance variable
but not try to link to command line switch and config files.

But none of those are quite satisfying. Any ideas ? Or am I just
looking at this from the wrong angle ?

Thanks,
Anselm
 

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
473,744
Messages
2,569,484
Members
44,903
Latest member
orderPeak8CBDGummies

Latest Threads

Top