Including gems with standalone app

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. :slight_smile:

Thanks
Eric

···

--
Posted via http://www.ruby-forum.com/.

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'] = './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

···

On Wed, Aug 5, 2009 at 5:12 PM, Eric Peterson<ericdp@mac.com> wrote:

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. :slight_smile:

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

···

--
Posted via http://www.ruby-forum.com/.

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'

···

--
Posted via http://www.ruby-forum.com/.

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'] = './gem'
require 'rubygems'
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:\myapp>ruby foo.rb
<table>
   <tr>
      <td>foo
      <td align='left'>bar
      <td>baz
   <tr>
      <td>1
      <td>2
      <td>3
   <tr>
      <td>hello
      <td>world
</table>

C:\myapp>

···

On Thu, Aug 6, 2009 at 11:23 AM, Eric Peterson<ericdp@mac.com> wrote:

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

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.

···

On Aug 6, 12:43 pm, Eric Peterson <eri...@mac.com> wrote:

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'
--
Posted viahttp://www.ruby-forum.com/.

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

···

--
Posted via http://www.ruby-forum.com/.

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

···

--
Posted via http://www.ruby-forum.com/.

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

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

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

C:\myapp>set RUBYOPT=-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/custom_require.rb:31:in
`require'
        from foo.rb:5

C:\myapp>set RUBYOPT=

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

Hope that does it.

···

On Thu, Aug 6, 2009 at 3:58 PM, Eric Peterson<ericdp@mac.com> wrote:

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]

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

···

--
Posted via http://www.ruby-forum.com/.