including gems with standalone app

E

Eric Peterson

Morning,

I have a situation where I do not have the ability to add gems into
production. I can provide a ruby script to be ran by the Operations
Team, but I can't ask that they install a gem I use. Also, stuck at
Ruby v.1.8.5.

Is it possible to 'package' a gem into a directory structure with my
app? For example:

\<appfolder>
app.rb
config.yml
README.txt
...
\gem
\fastercsv
...
\ruby-sqlite3
...
\lib
\sqlite3
...

How would I go about telling my app to use these gems in my directory
structure and not any that might happen to be available in the system
(or not)? Then I could zip up the whole directory, send to operations,
where they would install this app and run according to instructions.

I hope I described this right. If not let me know how I can add to
this confusion. :)


Thanks
Eric
 
G

Gordon Thiesfeld

Morning,

=A0I have a situation where I do not have the ability to add gems into
production. =A0I can provide a ruby script to be ran by the Operations
Team, but I can't ask that they install a gem I use. =A0Also, stuck at
Ruby v.1.8.5.

=A0Is it possible to 'package' a gem into a directory structure with my
app? =A0For example:

\<appfolder>
=A0app.rb
=A0config.yml
=A0README.txt
=A0...
=A0\gem
=A0 =A0\fastercsv
=A0 =A0...
=A0 =A0\ruby-sqlite3
=A0 =A0...
=A0\lib
=A0 =A0\sqlite3
=A0 =A0...

=A0How would I go about telling my app to use these gems in my directory
structure and not any that might happen to be available in the system
(or not)? =A0Then I could zip up the whole directory, send to operations,
where they would install this app and run according to instructions.

=A0I hope I described this right. =A0If not let me know how I can add to
this confusion. :)

I'm not sure if it's the best way, but you could manipulate
ENV['gem_home'] from your script.

C:\>cd myapp

C:\myapp>gem list fastercsv

*** LOCAL GEMS *** # fastercsv not installed

C:\myapp>type myapp.rb

ENV['GEM_HOME'] =3D './gem'
require 'rubygems'
require 'fastercsv'

C:\myapp>gem in fastercsv -i gem #install fastercsv inside app/gem folder
Successfully installed fastercsv-1.5.0
1 gem installed
Installing ri documentation for fastercsv-1.5.0...
Installing RDoc documentation for fastercsv-1.5.0...

C:\myapp>dir /b gem
cache
doc
gems
specifications

C:\myapp>ruby myapp.rb
 
E

Eric Peterson

hmm.. well, something went wrong. I already have fastercsv installed,
so I found a different gem to test this. Installation to this defined
directory works fine.

C:\InWork\myApp>mkdir gem
C:\InWork\myApp>gem install html-table --install-dir gem
Successfully installed strongtyping-2.0.6-x86-mswin32-60
Successfully installed test-unit-2.0.3
Successfully installed structured_warnings-0.1.1
Successfully installed html-table-1.3.3
4 gems installed


C:\InWork\myApp>cat foo.rb

require 'rubygems'
$LOAD_PATH << File.expand_path( File.dirname( __FILE__ ) + '/gem' )
ENV['GEM_HOME'] = 'gem'
require 'html-table'
include HTML

Table.html_case = "lower"
Table::Row.end_tags = false
Table::Row::Data.end_tags = false
table = Table.new
tr1 = Table::Row.new
tr2 = Table::Row.new
tr3 = Table::Row.new
tr1.content = "foo", "bar", "baz"
tr2.content = 1, 2, 3
tr3.content = %w/hello world/
table.push( tr1, tr2, tr3 )
table[0][1].align = "left"
puts table.html



C:\InWork\myApp>ruby foo.rb

C:/Ruby/lib/ruby/site_ruby/1.8/rubygems/custom_require.rb:31:in
`gem_original_require': no such file to load -- html-table (LoadError)
from
C:/Ruby/lib/ruby/site_ruby/1.8/rubygems/custom_require.rb:31:in
`require'
from foo.rb:5


Appears to be ignoring the $LOAD_PATH I set before require this gem.

Eric
 
E

Eric Peterson

Also tried, but still get no such file to load -- html-table (LoadError)
when I attempt to require it.



Gem.clear_paths
ENV['GEM_HOME'] = File.join( 'C:', 'Ruby', 'lib', 'ruby', 'site_ruby',
'1.8' )
ENV['GEM_PATH'] = File.join( 'C:', 'InWork', 'myApp', 'gem' )
Gem.use_paths( ENV['GEM_PATH'], [ENV['GEM_HOME']] )
require 'rubygems'
require 'html-table'
 
B

bbiker

Also tried, but still get no such file to load -- html-table (LoadError)
when I attempt to require it.

  Gem.clear_paths
  ENV['GEM_HOME'] = File.join( 'C:', 'Ruby', 'lib', 'ruby', 'site_ruby',
'1.8' )
  ENV['GEM_PATH'] = File.join( 'C:', 'InWork', 'myApp', 'gem' )
  Gem.use_paths( ENV['GEM_PATH'], [ENV['GEM_HOME']] )
  require 'rubygems'
  require 'html-table'
since you appear to be on Windows, I suggest that you look into
"ocra". This will package your code, gems that you use and ruby
interpreter as a stand alone executable program.
 
E

Eric Peterson

Yes, I am developing on this Windows box. Not happy about that. Soon I
expect to get a Mac laptop. But my QA_test/production boxes are Solaris
unix. I think one of the production app serves is a linux variant. I
don't know which as I don't have access to production. That is why I am
trying to make this be an all inclusive app delivery, since I can't have
gems installed in all these places.

Confusing I know.


Eric
 
G

Gordon Thiesfeld

hmm.. well, something went wrong. =A0I already have fastercsv installed,
so I found a different gem to test this. Installation to this defined
directory works fine.

C:\InWork\myApp>mkdir gem
C:\InWork\myApp>gem install html-table --install-dir gem
Successfully installed strongtyping-2.0.6-x86-mswin32-60
Successfully installed test-unit-2.0.3
Successfully installed structured_warnings-0.1.1
Successfully installed html-table-1.3.3
4 gems installed


C:\InWork\myApp>cat foo.rb

=A0require 'rubygems'
=A0$LOAD_PATH << File.expand_path( File.dirname( __FILE__ ) + '/gem' )
=A0ENV['GEM_HOME'] =3D 'gem'
=A0require 'html-table'
=A0include HTML

=A0Table.html_case =3D "lower"
=A0Table::Row.end_tags =3D false
=A0Table::Row::Data.end_tags =3D false
=A0table =3D Table.new
=A0tr1 =3D Table::Row.new
=A0tr2 =3D Table::Row.new
=A0tr3 =3D Table::Row.new
=A0tr1.content =3D "foo", "bar", "baz"
=A0tr2.content =3D 1, 2, 3
=A0tr3.content =3D %w/hello world/
=A0table.push( tr1, tr2, tr3 )
=A0table[0][1].align =3D "left"
=A0puts table.html



C:\InWork\myApp>ruby foo.rb

C:/Ruby/lib/ruby/site_ruby/1.8/rubygems/custom_require.rb:31:in
`gem_original_require': no such file to load -- html-table (LoadError)
=A0 =A0 =A0 =A0from
C:/Ruby/lib/ruby/site_ruby/1.8/rubygems/custom_require.rb:31:in
`require'
=A0 =A0 =A0 =A0from foo.rb:5


Appears to be ignoring the $LOAD_PATH I set before require this gem.

Eric

Try setting ENV['GEM_HOME'] before requiring rubygems. Also, I don't
think you require html-table, I think it's html/table.

C:\myapp>gem install html-table -i gem
Building native extensions. This could take a while...
Successfully installed strongtyping-2.0.6
Successfully installed test-unit-2.0.3
Successfully installed structured_warnings-0.1.1
Successfully installed html-table-1.3.3
4 gems installed

C:\myapp>cat foo.rb

# $LOAD_PATH << File.expand_path( File.dirname( __FILE__ ) + '/gem' )
ENV['GEM_HOME'] =3D './gem'
require 'rubygems'
require 'html/table'
include HTML

Table.html_case =3D "lower"
Table::Row.end_tags =3D false
Table::Row::Data.end_tags =3D false
table =3D Table.new
tr1 =3D Table::Row.new
tr2 =3D Table::Row.new
tr3 =3D Table::Row.new
tr1.content =3D "foo", "bar", "baz"
tr2.content =3D 1, 2, 3
tr3.content =3D %w/hello world/
table.push( tr1, tr2, tr3 )
table[0][1].align =3D "left"
puts table.html

C:\myapp>ruby foo.rb
<table>
<tr>
<td>foo
<td align=3D'left'>bar
<td>baz
<tr>
<td>1
<td>2
<td>3
<tr>
<td>hello
<td>world
</table>

C:\myapp>
 
E

Eric Peterson

I must have something set up wrong on my box. Using your code exactly I
still get.


C:\InWork\myApp>ruby foo.rb
C:/Ruby/lib/ruby/site_ruby/1.8/rubygems/custom_require.rb:31:in
`gem_original_require': no such file to load -- html/table (LoadError)
from
C:/Ruby/lib/ruby/site_ruby/1.8/rubygems/custom_require.rb:31:in
`require'
from foo.rb:4


somewhat frustrating. This should be easier.


ruby 1.8.6 (2008-08-11 patchlevel 287) [i386-mswin32]
gem 1.3.5

And I've been told that one of the prod boxes I'll be going to uses
v.1.8.5. I hope it has rubygems installed, but I don't know.


Eric
 
G

Gordon Thiesfeld

I must have something set up wrong on my box. =A0Using your code exactly = I
still get.


C:\InWork\myApp>ruby foo.rb
C:/Ruby/lib/ruby/site_ruby/1.8/rubygems/custom_require.rb:31:in
`gem_original_require': no such file to load -- html/table (LoadError)
=A0 =A0 =A0 =A0from
C:/Ruby/lib/ruby/site_ruby/1.8/rubygems/custom_require.rb:31:in
`require'
=A0 =A0 =A0 =A0from foo.rb:4


somewhat frustrating. =A0This should be easier.


ruby 1.8.6 (2008-08-11 patchlevel 287) [i386-mswin32]

The one-click installer for that version sets the rubyopt environment
variable, so rubygems is getting loaded earlier than we realize.

C:\myapp>pik sw 186 mswin

=3D=3D Switching to ruby 1.8.6 (2008-08-11 patchlevel 287) [i386-mswin32] =
=3D=3D

C:\myapp>ruby foo.rb
<table>
<tr>
<td>foo
<td align=3D'left'>bar
<td>baz
<tr>
<td>1
<td>2
<td>3
<tr>
<td>hello
<td>world
</table>

C:\myapp>set RUBYOPT=3D-rubygems

C:\myapp>ruby foo.rb
c:/ruby/186-p287-mswin32/lib/ruby/site_ruby/1.8/rubygems/custom_require.rb:=
31:in
`gem_original_require': no such file to load -- html/table (LoadError)
from c:/ruby/186-p287-mswin32/lib/ruby/site_ruby/1.8/rubygems/custo=
m_require.rb:31:in
`require'
from foo.rb:5

C:\myapp>set RUBYOPT=3D

C:\myapp>ruby foo.rb
<table>
<tr>
<td>foo
<td align=3D'left'>bar
<td>baz
<tr>
<td>1
<td>2
<td>3
<tr>
<td>hello
<td>world
</table>


Hope that does it.
 
E

Eric Peterson

Well, that is interesting.

I will have to make sure that this environment variable is not set
before starting my app. Maybe put a kornshell wrapper around it.

Thanks much for your help.

Eric
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,774
Messages
2,569,599
Members
45,166
Latest member
DollyBff32
Top