Not imposing your dependencies in Ruby

Discussion in 'Ruby' started by Anselm, May 30, 2006.

  1. Anselm

    Anselm Guest

    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
    Anselm, May 30, 2006
    #1
    1. Advertising

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

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Bob Dubery
    Replies:
    1
    Views:
    452
  2. Philipp Schumann
    Replies:
    2
    Views:
    1,372
  3. D.C.
    Replies:
    0
    Views:
    647
  4. Mel
    Replies:
    1
    Views:
    567
  5. Otto Hemmi

    Local Ruby Gem Dependencies.

    Otto Hemmi, Feb 25, 2008, in forum: Ruby
    Replies:
    2
    Views:
    106
    Eric Hodel
    Feb 25, 2008
Loading...

Share This Page