Using Ruby libraries and gems with a Shoes app
Asked Answered
A

2

14

I am writing a little Shoes app that requires a library I wrote with my regular Ruby installation. My library uses the 'net-ssh' gem and a bunch of other Ruby libraries.

When I run my library directly with regular ruby (it has its own command-line interface) like this:

ruby my_lib.rb

...all is fine. But when I try to require it within my Shoes app I get an 'no such file to load - net/ssh' error (because my_lib uses net-ssh).

I tried messing around with the $: include path variable in the Shoes app like this:

$:.unshift "C:/ruby/lib/ruby/1.8"
$:.unshift "C:/ruby/lib/ruby/site_ruby/1.8"
require 'rubygems'
gem 'net-ssh'
require 'my_lib.rb'

...but had no success. I get 'Could not find RubyGem net-ssh'.

Anyone has had the same problem? What's the best way to use your Ruby libraries and gems in a Shoes app?

Antagonize answered 4/2, 2009 at 17:46 Comment(0)
B
18

Hey, _why posted on his blog, hackety.org, about using gems within Shoes. I hope it helps!

Shoes.setup do
  gem 'json >= 1.1.1'
  gem 'activerecord'
end

require 'json'
require 'activerecord'

Shoes.app do
  @msg = para "ALL SYSTEMS GO"
  animate(20) { @msg.toggle }
end
Byler answered 4/2, 2009 at 17:55 Comment(1)
baxter, I found a somewhat ugly solution, which was simply to copy the 'net-ssh' gem files to the Shoes gem directory, which is exactly what the "Shoes.setup" is supposed to do, so, I guess I was not that far from the truth! Thanks! ;-)Antagonize
C
2

For shoes4, the Shoes.setup method is deprecated. You can install the gems you need by either:

  1. gem install net-ssh
  2. Using bundler and a Gemfile

Then, you only need to require 'net-ssh' in your application.

Cornett answered 30/3, 2014 at 15:8 Comment(1)
I have been experiencing the same issue. My local environments were all rvm based but certain gems (pdf-reader) were not found when running in launch mode or packaged. I had to package my app. Then copy the gems directly into lib/gems dir that is part of Mac OS X apps content (not sure if same on windows ). Then zip up that content for distribution. Worked fine. I'm sure you could script the packager to do this. Out changes our currently infrequent. Mac OS X 10.10. Shoes federalesQueri

© 2022 - 2024 — McMap. All rights reserved.