Organizing a complex gem

I need to organize a project into a gem, and would like some ideas about
the best way to do so.

Obviously, the main library file will go in “lib”, and any files that
are
necessarily loaded by it as its own library files should go in a
subdirectory of “lib”.

Just as obviously, the executable front-end utility should be stuck in
“bin”.

Tests will be in “test”.

Where should I put a config file?

Where should I put a set of optional modules that serve as extensions,
where the user of the project can use the config file to specify
extensions to load – or none at all, if preferred?

It uses some data files as a modular “database”, each file serving as a
plain text hierarchical database of its own. One such file is currently
part of the project; it is expected that a user will end up adding
dozens
more. Where should I put those?

Would it make sense to create a directory for each of these things at
the
project-root level, or to do so for some subset of them? Should they be
stuck in special directories that are subdirectories of other
directories
that already exist (such as “lib”, where extension might be in “lib/mod”
or “lib/ext”)?

Use dot directory:

$HOME/.yourappname/

In there the end-user can edit a config file (maybe config.yml, or
config.rb or whatever the appropriate extension). And also the data
files
you mention can go there too, e.g. $HOME/.yourappname/foo.dat.

Also, consider using XDG base directory standard, which would give your
end-user some flexibility in deciding where these files reside.

The modules themselves would go into lib/, e.g.
lib/myapp/extensions/.

On Thursday, January 5, 2012 2:21:18 AM UTC-5, Chad P. wrote:

Where would I store this within the gem/project directory hierarchy,
though? That’s the real question I have with regard to where to put my
config and data files right now, and not so much where to install them
later (which I was thinking of doing in a manner quite like what you
describe here).

Ah, you mean for a default setup? You should keep it in your project,
either in lib somewhere or if you what to be FHS strict use
data/foo/
which should be installed to /usr/share/foo/. However for the later,
RubyGems doesn’t install data to share, so you will have to access that
from the gem itself (maybe using RbConfig.datadir?) – which is why I
say
just using lib is much easier.

Then have your program setup the user defaults on an initial run.

On Thu, Jan 05, 2012 at 02:39:38PM +0900, Intransition wrote:

Use dot directory:

$HOME/.yourappname/

In there the end-user can edit a config file (maybe config.yml, or
config.rb or whatever the appropriate extension). And also the data files
you mention can go there too, e.g. $HOME/.yourappname/foo.dat.

Where would I store this within the gem/project directory hierarchy,
though? That’s the real question I have with regard to where to put my
config and data files right now, and not so much where to install them
later (which I was thinking of doing in a manner quite like what you
describe here).

Also, consider using XDG base directory standard, which would give your
end-user some flexibility in deciding where these files reside.

I’ll consider it. Thanks for the suggestion.

The modules themselves would go into lib/, e.g. lib/myapp/extensions/.

This seems like it might be suboptimal for cases where the gem is
installed system-wide but the modules should be available on a per-user
basis, but I guess just establishing a “standard” location for per-user
extensions in addition to the extensions provided with the default
install – which are in the system-wide location – would make sense.

On Fri, Jan 06, 2012 at 01:26:21AM +0900, Intransition wrote:

$HOME/.yourappname/foo.dat.
RubyGems doesn’t install data to share, so you will have to access that
from the gem itself (maybe using RbConfig.datadir?) – which is why I say
just using lib is much easier.

Then have your program setup the user defaults on an initial run.

It kinda looks like you’re still talking about post-installation paths.
Maybe I’m misunderstanding something.

What I was asking about was how to organize things in the project
directory, from which things are bundled in a gem archive for
distribution, so that things conform to expectations when people look at
the source of an unpacked gem archive or check the source in an online
DVCS code hosting repository.

On Fri, Jan 06, 2012 at 05:01:23AM +0900, Intransition wrote:

Ok then:

lib/foo/

or

data/foo/

~/src/project_name/data/foo ?

Is that a common practice, or some kind of guess?

https://github.com/rubyworks/setup/wiki/Creating-Packages

Ok then:

lib/foo/

or

data/foo/

On Thu, Jan 5, 2012 at 00:42, Chad P. [email protected] wrote:

Where should I put a config file?

If the user is expected to (be able to) edit it, then “etc”.

On Sat, Jan 07, 2012 at 04:33:40AM +0900, Intransition wrote:

https://github.com/rubyworks/setup/wiki/Creating-Packages

Thanks. That’s a big help.

This forum is not affiliated to the Ruby language, Ruby on Rails framework, nor any Ruby applications discussed here.

| Privacy Policy | Terms of Service | Remote Ruby Jobs