How to produce a self contained Ruby "executable"? - ruby

I have some simple Ruby scripts that I would like to distribute to coworkers. They are not very complex, but they involve many files and a directory architecture, thus I would like to be able to automatically "group" all of that in a single file to ease the distribution.
Is there any Ruby tool that would automate that ? I don't need a binary, that can be another Ruby script.

You can use ocra. It will package your script into an executable. It is windows-only though. http://ocra.rubyforge.org/

Related

Combine a set of shell scripts with internal dependencies into one?

I'm developing a set of shell scripts and for ease of development, the functions are often split across various files.
So the final binary scripts which I expect the end user to use require them to have all the relevant "library" scripts installed in the right location.
I am trying to find a way that allows me to develop the scripts with the same logical split in files, but then I can merge them all into a single binary script.
In the naive case, it would recursively go through all the sourced files and include them in the same file (similar to the pre-processing step in C compilers). The more involved version would also identify which functions are unused and trim them out.
Does anything like this exist? If not, I might consider writing it, but would be happy to hear about potential pitfalls that I should account for
I have seen this before, in Arch Linux' devtools repo. They use m4 to process .in files.
It's just templating though. And you might not need anything more.

Would it make sense to package a ruby shell script as a gem?

I've written a shell script that I find very useful and would like to reuse. Basically, it reads an excel file (via the RubyXL gem) and then allows users to take certain rows and export them as json objects. However, because it relies on passing many arguments (columns, rows, ect.), I'm wondering if packaging this as a gem would be a good use. I haven't published a gem but I've read through and it seems like it wouldn't be that difficult. I'm wondering how useful or if a shell script is really the right format?
I'd say yes to making it a gem, but only if you expose the functionality as Ruby classes and/or methods, so that your functionality could be called by other Ruby scripts, and not just the command line.
This would enable you to better organize your code; your lib directory would contain the core logic, a spec or test directory would have unit tests, and the bin directory would have your command line script, which would probably be just a tiny wrapper that called the lib code.

How can I completely compile a bash project to be distributed?

I am trying to compile a bash project into a distributable binary. I tried shc, and it worked, except all my source statements were broken. I have numerous source statements to keep the code base cleaner, but they are broken when compiled with shc. How can I compile down my bash project so that instead of having a bunch of .sh files, the end user can just have one single file?
Shc is an obfuscator, not a compiler. At the end of the day, it still invokes /bin/sh or whatever, and feeds it your original script. It has not a slightest idea what your script actually does. If it needs an additional file to source, you have to supply it at an appropriate location.
You may want to investigate things like SHAR. Build anarchive, then compile it with shc if you want.
It sounds like all you're missing is a facility to expand all your source statements. That should be fairly easy to write if your codebase is fairly consistent in its use of those statements: just write a script to expand them inline and away you go.
Alternatively, just put all your scripts into a single Zip file or tarball and tell the user to extract the contents of that one file, or if even that is too much I'm sure you can imagine a way to encode the zipped contents of all the non-main files into a giant comment at the bottom of the main file, and have it extract what it needs before proceeding.
Or, you know, use the appropriate installer for your system. Build an RPM for RHEL or a Debian package or a Windows MSI or whatever....

How to create a Ruby executable using ocra or rubyscript2exe gems but including needed Excel files?

I have a dozen of selenium webdriver scripts written in Ruby and I have used both rubyscript2exe and ocra gems in an attempt to end up with a 'bundled' executable but to no avail. Problem is, my scripts are grabbing test data from Excel files; and this is causing havoc when trying to create the executable.
It works fine on the machine which has the original excel file but when taken home away from its native path it 'll just refuse to run. Do I need to declare my paths in my code in a relative way and not explicitly? Is there a command in Ruby like 'require' but for an Excel file for example?
I will be grateful if anyone knows a way to make a ruby executable (or even an installer/application builder) which will somehow include the Excel files running in parallel with the script.
* Resolved *
Admins you can close this one if you want.
It was pretty simple but couldn't figure it out on the first place. If you want to included additional non ruby files in your final executable you can use the line below..:
ocra yourscript.rb test.xls docs\documentantion.doc excel\additional.xls
Once you package an exe using Ocra the files are locked inside it, and if they're intended to be immutable you may as well store the data in the script and write it out directly from there. If you absolutely can't do it without an excel file you'd might also consider creating one via the script.
If you're using an external excel file which is distributed with the exe, then you'd be best off referencing the excel file's path relative to the script (Dir.pwd). Also, wouldn't it be more efficient to gather the data from a delimited text file rather than excel?

Providing my Ruby program as an all-in-one installer

I have written a short program in a ruby file that runs correctly on my PC. However I need to find a way to give this to my colleagues to use. They have no knowledge of ruby. The program requires various non standard gems. What is the best way to provide them with a one click installer for my program, including all the gems and ruby itself.
Try OCRA - it packages everything into a single executable (no installation required).
When you run the executable, it extracts everything into a temporary directory (including the ruby interpreter) and runs your script from this directory.
I havn't use it (so I don't know if it works), but you can try to use RubyScript2Exe

Resources