Debugging Ruby initializer


I am trying to implement custom file path shortcuts according to the example in the documentation, but our project directory names are not so straightforward. So I need to run a shell command to grab some additional information from the filesystem in order to populate the list of paths, but it’s not working as I expect it to.

Is there a way to debug custom Ruby code like this, either by looking at a Ruby execution log, or by running the initializer as a standalone script? I tried doing the latter, but it’s clear that I’m missing some package imports. Say that I wanted to run the initializer in the documentation as a standalone script, and print debug statements to STDOUT. What packages would I have to import to get that to run?

I realize that this is a little light on details, but I would prefer not to share the code. Really, I’m just looking for some recommendations on debugging Ruby code that runs within OOD.


Great question. I got this to work with these imports. If you don’t have ood_support, just run gem install ood_support and you’ll install it in ~/.gem (same for pathname).

require 'ood_support'
require 'pathname'
require '/var/www/ood/apps/sys/dashboard/app/apps/ood_files_app'
require '/var/www/ood/apps/sys/dashboard/app/models/user'

In 1.7 (for readers in the future) you’ll also need:

require '/var/www/ood/apps/sys/dashboard/app/apps/favorite_path'

Since you want to debug some code, the simplest way would be to launch the Rails console for the app you are adding the initializer to. For example on one of the test vms that we have OnDemand running I can do this:

$ scl enable ondemand -- bash
$ cd /var/www/ood/apps/sys/dashboard
$ RAILS_ENV=production bin/rails c
Rails Error: Unable to access log file. Please ensure that /var/www/ood/apps/sys/dashboard/log/production.log exists and is writable (ie, make it writable for user and group: chmod 0664 /var/www/ood/apps/sys/dashboard/log/production.log). The log level has been raised to WARN and the output directed to STDERR until the problem is fixed.
Loading production environment (Rails
=> Unable to load pry
irb(main):001:0> OodSupport
=> OodSupport

There you have a Ruby interpreter you can test out commands line by line, that includes all the libraries that should be available to the initializer.

Thank you both! @efranz’s solution – running the Ruby interpreter in the production Rails environment – was very helpful, and I have already identified and fixed the issue with my initializer.

@jeff.ohrstrom, your solution looked good too, but it was still failing with a strange error trace, even after installing the ood_support gem. I am by no means a Ruby expert, but the trace makes it look like something in ood_support is failing prior to even running my code? Here it is if you’re interested:

/usr/share/rubygems/rubygems/core_ext/kernel_require.rb:55:in `require': /usr/local/share/gems/gems/ood_support-0.0.3/lib/ood_support/acl.rb:26: syntax error, unexpected ',' (SyntaxError)
    def initialize(entries:, default: false)
/usr/local/share/gems/gems/ood_support-0.0.3/lib/ood_support/acl.rb:34: syntax error, unexpected ')'
/usr/local/share/gems/gems/ood_support-0.0.3/lib/ood_support/acl.rb:88: syntax error, unexpected keyword_end, expecting end-of-input
	from /usr/share/rubygems/rubygems/core_ext/kernel_require.rb:55:in `require'
	from /usr/local/share/gems/gems/ood_support-0.0.3/lib/ood_support.rb:6:in `<top (required)>'
	from /usr/share/rubygems/rubygems/core_ext/kernel_require.rb:135:in `require'
	from /usr/share/rubygems/rubygems/core_ext/kernel_require.rb:135:in `rescue in require'
	from /usr/share/rubygems/rubygems/core_ext/kernel_require.rb:144:in `require'
	from ood.rb:1:in `<main>'   

I’m going to mark the second reply as the solution, but I do have one more question:

With the file path shortcuts, is there a way to give them a nickname, similar to the way that the user’s home directory displays simply as “Home Directory” rather than the full pathname?

Thanks again,

@ndusek I think @jeff.ohrstrom’s solution would work if you are sure to first do scl enable ondemand -- bash. My guess is def initialize(entries:, default: false) not working is due to use of the older system Ruby, not the OnDemand Ruby 2.5 that has support for keyword args.

Gotcha, that makes sense.


Re: Custom names for file path shortcuts, I see that this is in the roadmap for 1.7.