Location of db/config.yml on a ruby app using standalone-migrations - ruby

I'm working on an command-line application that uses the standalone_migrations gem. I have the db/config.yml file and everything works fine when I run the app from the root dir, but when I run it from other dirs (e.g. directly running a script in the /bin directory), the gem cannot find the db/config.yml.
I looked at the gem's source, specifically in the lib/configurator.rb file, but couldn't find a way to set the correct .yml path.
Any help? Thanks.

StandaloneMigrations::Configurator uses relative paths, it loads configuration files on line #23.
This is a bug in the code. A workaround could be to change the working directory to the root before you execute the script. You didn't mention what kind of script you have under /bin, but for example if it is a Bash script, you can do something like:
cd /project/directory && rake db:migrate ...

Related

Running an app from Terminal with a path

If I can run an app (built in Go but not really necessary) like so from its own directory:
./some_app
How can I run it from a different directory?
You should just be able to add the path to the app you are trying to run to your command. For example if the app is stored in /Users/example/apps/some_app, then you can just directly run "/Users/example/apps/some_app". You can find which directory your app is sitting in (if you are currently in that directory) with the pwd command.
Say you are in the home directory, and the app is under ~/app/some_app then you can run it with app/some_app
If you want to be able to call it with only some_app, it has to be accessible in your $PATH variable.
In go, when you do go install ./... the executable will end up in $GOPATH/bin/ which is normally part of your path if you have a correct configuration.

How execute "rackup" from a remote path?

Running a rack service written in ruby, I need to execute "rackup" from an external path, without browsing into the code's directory previously.
classically:
cd /Volumes/Code/my_service; rackup
i'd like to:
rackup cd /Volumes/Code/my_service
which obv does not work because rackup doesnt not take this parameter.
You can specify the config file to use as an argument to rackup. If you don’t include one it will default to config.ru and will just look in the current directory.
In your case you should be able to run:
rackup /Volumes/Code/my_service/config.ru
You will need to make sure your app doesn’t assume that the current directory is the same as the apps directory, apart from that everything should work okay.

Trying to access the "current dir" in a packaged Shoes app

I need to build an app which reads a file which is external to the Shoes package I'll be distributing it in.
In my app, Dir.pwd points to the temp dir (at least in Windows) where the script is unpacked to be ran. I've been trying to get the directory where the exe is running from, that is, the package I'm distributing.
The app needs to read a file which is distributed besides this package and then write another one in the same directory.
It seems that the Shoes runtime does not set any env variable with this directory either. Any pointers?
nachokb
I run into this problem a while ago and hadn't file a straight solution. I ended up with two workarounds:
At application installation time, put the files at a directory inside of the user home dir ~/ (the home indirection also works in windows)
Package the files together with the shoes generated executable so that it is unzip at the same place as the app and therefore accessible with Dir.pwd
If you find another way, please point it out.
Have you tried something like the following:
DIR = File.expand_path __FILE__
__FILE__ is a reference to the current file and File.expand_path gives you the full system path. Works in my shoes apps :-)
Shoes on!
Tobi

How execute a self contained rake build?

We have an application which is compiled using Rake (on windows). We have a new requirement that one of our clients needs to compile the source code in their own environment using a bat file.
So I need to find a way to execute a rake build without installing anything on the host environment (i.e. everything required to do the build needs to be in the source directory, ruby, gems, etc...) from a batch file.
Anyone have any clues how I could get started with this?
Download and install ruby to a folder inside your project (do not add it to your PATH). After go to this folder and delete any "uninstall" file. Go to the folder again with the console (cmd and then use cd path\to\ruby\folder) and run gem install ... to install everything you need. After add a .bat file to run your app. Something like:
#echo off
rubyfolder\bin\ruby.exe myscript.rb
This is a fully portable ruby installation, you can put it in any computer and it will work as well. (I use it as a portable ruby in my pendrive to let me play everywhere with ruby!)
PS.: rake is a script from bin, you can open it with:
rubyfolder\bin\ruby.exe rubyfolder\bin\rake

Deploying a Ruby project

I have a finished Ruby project that has the standard structure for a multiple file Ruby program:
project/
lib/ # Files the driver program uses go here.
bin/ # Driver program goes here.
tests/ # Unit tests go here.
What I want to be able to do is type in project into the command line from any directory and have my program run (which means it needs to be in my $PATH). My question is how do I do add a multiple file Ruby project to my PATH so that I can call by name in the terminal? (Or perhaps my approach is wrong, and I should do something else like make it into a Gem? I just don't know what is normally done).
package it as a gem and install that gem. If not and you're on linux then you can set your shebang line to be the right ruby, and chmod to make your script executable, and add your bin dir to your path (or what not).
You could go the quick and dirty route, and write a bash script that calls your main function to run the project, and then stick the bash script over in /usr/bin.

Resources