Get Rack to load config from Gem - ruby

Is it possible to run Rack and specify that it should look for config.ru from one of the project's Gem dependencies rather than the project's files on the local filesystem?
I'm sure this is a 'wrong' pattern, but we've got project A that has a load of front-end static resources. Project B is a Sinatra app that provides the backend services for that web UI to call upon. We separated them into two projects so A could depend on a particular version of B, and be insulated from breaking changes.
B contains the Sinatra app, and the config.ru which defines what Sinatra endpoints are mapped to which paths, and additionally that the static resources should be served too.
A has the thinnest sliver of Ruby, essentially just depending on B via a Gemfile.
We want someone to be able to clone project A, do a bundle install, and then run rackup and have Rack use the config.ru inside B's Gem to decide how to configure itself.

The "rackup" command can take options for the include path and a specific library as well as the path to the config file you want to run, so you should be able to pull it off…
Usage: rackup [ruby options] [rack options] [rackup config]
Ruby options:
...
-I, --include PATH specify $LOAD_PATH (may be used more than once)
-r, --require LIBRARY require the library, before executing your script
If that doesn't work for you, you may need to provide more details on what you are trying to do

Related

Rspec multiple spec folders

Im currently building a project using Rspec in which I sepparated in two different folders with domain code and infrastructure code. Both folders have their own specs in a spec folder. The domain/spec folder is the one containing the spec_helper.rb file, thats required from the tests inside the other folder infrastructure/spec
I'd like to know how to have a spec folder in the root of the project, including the spec_helper file and also tests, and being able to run all the tests with just one command (right now I do it running rspec domain/ infrastructure/)
RSpec is designed to work with all tests in one folder. By default, this folder is called spec/, but you can use a different name with the --default-path option.
So, your options as I see it are:
Edit the source code of rspec-core to let that configuration support multiple directories. Hopefully your PR will be approved and merged.
Or, write a simple wrapper script that runs rspec against both directories. For example, you could alias rspecs='rspec domain/ infrastructure/'.
Or (what I would recommend!), you could just restructure your tests slightly to use spec/domain/ and spec/infrastructure/ folders -- and then everything will just work, by convention, out of the box.

Good project layout for a ruby system project?

I am writing small Ruby program that is used to backup some folders and send to s3,
e.g.
backup.rb --folder /folder1 --folder /folder1 ...-c config.ini
Before I start writing this program from scratch, I want to know if there is some existing good sample project layout that I can reference?
e.g. how to layout the tests, libraries, classes, configs, doc etc
I am particularly interested in a layout that allow me to share the libraries so later I can easily re-use in other project., even submit to ruby gems
Would be helpful if anyone can send me some good examples from existing OSS.
This is a pretty standard structure. Drawn from RubyGem Tutorial
.
bin/ # Executables here
data/ # Assets here
doc/ # RDOC for the lib directory
lib/ # Code for the project
project_module.rb # Contains project module
project_module/ # Classes for project module
# Either
spec/ # RSpec Tests
test/ # Test::Unit Tests

Using Buildr within Docpad

I'm using DocPad to build my website, and in the docs it's saying that we can use an helper called buildr to bundle, compress files.
Is it possible to integrate buildr execution within the command docpad generate or docpad run?
Also does it needs it own config file buildr.coffee or it's possible to write the configs inside the docpad.config plugin section?
I imagine it would be more or less the same as this gist for grunt except with the grunt stuff changed to buildr.

Ruby - Where to put resource files that a module in lib relies on?

I am trying to structure my ruby project following best practices. I currently have something like this:
test_project/
bin/
test_project # My Executable
lib/
test_project/
my_module.rb
test_project.rb # Loads my_module.rb
I setup it up this way based on recommendations I found on the web.
My problem is I have some resource files, "resouce1.txt" and "resouce2.txt". My executable needs to open the file "resource1.txt". my_module.rb needs to be able to open the file "resource2.txt". Where do I put these plan text resource files in this directory structure and how to I open them (File.open) from the corresponding ruby files.
Since /lib has to do with specifically the Ruby that powers your gems, I would put it in a top-level directory in your gem named after their subject matter. If they are files with lists of species I would call it /species.
You could also go the Rails way and put it in an /assets folder if you have a lot of external assets like /assets/species. Either way, I would not be prone to put them in /lib.
I don't think there is a standard place for these, as for the most part it is operating system dependent (/var and /etc vs Program Files vs the Application Bundle). But your best bet (I think) is to either put them in the root of your hierarchy, put them in lib/ or, if they really are static text files, put them in your script.

Is there a JRuby-Rack Sinatra Warbler Project archtype?

Is there a project archetype (or whatever the ruby community calls it) for a jruby + rack + Sinatra project that creates a WAR deployment file with all required dependencies all ready to go?
What I want is the equivalent to "rails appname" that creates a ready to go project with ant/rake scripts and a basic directory hierarchy all ready to go.
Does such a beast exist?
I found this which shows how rack can be used with sinatra

Resources