CLI tool built using commander gem doesn't execute correctly when used after being installed - ruby

So, I have a CLI tool I'm building using the commander gem.
The executable successfully executes correctly when used directly from the bin folder (bin/dynamised), but when I install the gem locally and then run it from the command line (dynamised) it doesn't seem to do anything.
If I add puts 'WORKING' to the top of the file, I see that but nothing else.
EDIT:
output of puts [$0, __FILE__].inspect:
from bin:
["bin/dynamised", "bin/dynamised"]
from installed gem:
["/Users/---------/.rbenv/versions/2.3.0/bin/dynamised", "/Users/---------/.rbenv/versions/2.3.0/lib/ruby/gems/2.3.0/gems/Dynamised-0.1.4/bin/dynamised"]
Link to gist containing executable.
Not quite sure what's wrong.

Change the very last line of your script to:
Dynamised::CLI.new.run if File.basename($0) == File.basename(__FILE__)
or simply remove this redundant check:
Dynamised::CLI.new.run

Related

Executing a .rb file (Ruby file) with PRY in Windows 7

I was wondering how I can load a Ruby file into PRY to use the debugger function on my Windows 7 computer with Command Prompt. I want to use PRY to go through my program step by step and following the tutorials online on how to do it aren't working for me (probably because all of them are using Mac Terminal)
I use SublimeText 2 to write everything up and then save it as a .rb file and I was told that if I wanted to debug the file I just made, I need to run it through IRB or PRY. Not, I already ran "gem install debugger". And the Ruby I have installed is 1.9.3 - p545. Do I need to add an extra line of code that says "binding.pry" (I saw that in some of the samples that I could find on stackoverflow). All I'm looking for is a simple step-by-step process. Thank you for reading this, I look forward to the responses.
Make sure you've installed pry and pry-debugger gems
At the top of your file, add statements for require 'pry' and require 'pry-debugger'
In your code, wherever you want to start ddebugging, just add a statement binding.pry
Now, you can run your file like ruby filename.rb and the debugger should open

Making an executable from ruby files using Ocra, LoadError?

I'm trying to make an executable from a couple ruby files on Windows, so I installed Ocra. I thought I understood the process of how Ocra works, but can't seem to get the executable working correctly. The problem I am having arises with "requiring" other ruby files.
The ruby program by itself compiles correctly and functions how I want it to, and Ocra seems to create a working executable, however, when I attempt to run the executable, I get the following error:
*/custom_require.rb:36:in 'require': cannot load such file -- MainMenuDialog.rb (LoadError)*
My main program is called 'JobManager.rb' and it is creating a new MainMenuDialog object, therefore I include MainMenuDialog.rb in the top of the file as such:
$: << File.expand_path(File.dirname(__FILE__) + "/../lib")
# Other requires here
require("MainMenuDialog.rb")
Again, the program compiles and runs perfectly fine by itself (including the require statements), and when I run the command ocra JobManager.rb it successfully runs the programs, checks for dependencies, and creates the executable. I just can't run the executable because of the "LoadError" described above.
Any thoughts on what I'm doing wrong? Thanks in advance!!!
With ruby >= 1.9 you may try require_relative.
Explanation: ocra stores all files in its own subdirectories.
If you manipulate the load pathes ($:) you can't be sure, what ocra uses during execution.
This question is old and answered, but I wanted to include this little nugget I found in Ocra documentation, because the correct answer here did not resolve my issue:
OCRA does not set up the include path. Use $:.unshift
File.dirname($0) at the start of your script if you need to 'require'
additional source files from the same directory as your main script.

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

Need help with starting RoR: Command "rails server" does not result in "Booting WEBrick"?

I need help to get started with RoR.
I currently follow this guideline:
http://allaboutruby.wordpress.com/2009/07/20/installing-rails-on-windows-3-years-later/#comment-11099
I followed step 1 through 3 w/o problems.
In step 5: I can get the webserver through WEBrick working.
When i put
"rails server"
instead of getting "Booting Webrick", i get "rails new_path option"
thus when i try 127.0.0.1:3000 in the browser... it does work.
Can anyone guide me on this on how to get it up and runnning? (Im a total newb for now...so i need specific explanations! thanks!)
In your tutorial i can't see the command 'bundle install' - it's checking and installing all necessary gems in your system. So why you don't use another great rails tutorial - http://ruby.railstutorial.org/ruby-on-rails-tutorial-book
I'm guessing you are running windows, on which rails can be a little awkward. You'll probably need to run the rails server command by pointing ruby at the server script. On windows, your rails "commmand" is actually just a .bat file that lives in the /bin file of your ruby installation, and that .bat file just passes the arguments to ruby. If you look at the rails gem that is installed on your machine, you'll see the files that correspond to the normal first argument of a rails command (console, generate, server, etc). You might find it helpful to copy these to the /script directory of your application, and when you want to run a rails command you can just run "ruby script\server" from your application's main directory, though there may be more accepted ways of getting the same result.

I can't install Haml/Sass on Windows using RubyInstaller for Windows

I never used ruby before, I just wanted to play around with HAML and SASS. I downloaded and installed Ruby's Windows installer (v1.9.1). Then, I clicked ruby.exe (the icon with a black window and a multicolored gem in the picture). Finally, I typed gem install haml and pressed Enter. But nothing happened. Am I doing something wrong?
Reference picture:
alt text http://img707.imageshack.us/img707/9863/haml.png
You might need to put the path to Ruby into the PATH environment variable to do this, but this is how I do it:
I open up the command line utility. I then type ruby -S gem install <whatever>. This works like a charm.
I tried running Ruby and it shows a blank screen but lets me type code. When I press CTRL + C to cancel it then executes my code as well. Maybe you need to do that in the manner you are trying to right now. I just find it easier to just ruby -S <statement> instead. IronRuby gives me the REPL no problems though.
ruby.exe is the Ruby interpreter. If you want to type code into it, you obviously need to type Ruby code into it, not DOS command code.
The gem command is a DOS batch file (gem.bat). DOS batch files need to be run from the DOS command interpreter.
Installing Ruby using RubyInstaller, you get an shortcut in the Programs menu that let you open a command prompt with Ruby in the PATH
You use that in case you didn't select the option to add Ruby to the PATH.
Either case, the gem command you typed in should be entered at the command prompt, and not inside Ruby itself.
The latest build (rubyinstaller-1.9.2-p136.exe) had a problem. Rename the folder: c:\ruby192\lib\ruby\site_ruby or delete it altogether and this fixes "gem"
You can do "gem install compass" or if you're behind a proxy you might need to do.
gem install –http-proxy compass
Here's a blog post with all the details:
http://francisshanahan.com/index.php/2011/how-to-theme-sencha-touch-sass-windows/
Hope that helps,
-fs
this is how i installed ruby and sass on my windows machine: How to install ruby and sass on windows?

Resources