Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > Ruby > gem issue

Reply
Thread Tools

gem issue

 
 
Tim Pease
Guest
Posts: n/a
 
      02-03-2007
I'm working on Ruby program that will have a resource directory for
storing configuration, logging information, etc. I've used the
__END__ and DATA trick in my main ruby program to store some sane
defaults for the resources directory if this is the first time the
program has been run by a user.

#!/usr/bin/env ruby

require 'mylib'

unless File.exist?(ENV['HOME'] + '.myrc')
File.open(ENV['HOME'] + '.myrc/defaults', 'w') do |fd|
fd.write DATA.readlines
end
end

# use defaults here

__END__
hash_key_1 : 1
hash_key_2 : 2
etc : and some more


This works very well when my application is run directly. But when
installed via gems a new ruby script is created that loads my
executable script This causes the __END__ keyword in my ruby
script to stop working, and the DATA constant is not set.

Is there a way to tell the gem installer "Hey, quit being so smart and
just install my executable file without wrappering it with your own
ruby script".

Blessings,
TwP

 
Reply With Quote
 
 
 
 
Trans
Guest
Posts: n/a
 
      02-03-2007


On Feb 3, 4:38 pm, "Tim Pease" <(E-Mail Removed)> wrote:
> I'm working on Ruby program that will have a resource directory for
> storing configuration, logging information, etc. I've used the
> __END__ and DATA trick in my main ruby program to store some sane
> defaults for the resources directory if this is the first time the
> program has been run by a user.
>
> #!/usr/bin/env ruby
>
> require 'mylib'
>
> unless File.exist?(ENV['HOME'] + '.myrc')
> File.open(ENV['HOME'] + '.myrc/defaults', 'w') do |fd|
> fd.write DATA.readlines
> end
> end
>
> # use defaults here
>
> __END__
> hash_key_1 : 1
> hash_key_2 : 2
> etc : and some more
>
> This works very well when my application is run directly. But when
> installed via gems a new ruby script is created that loads my
> executable script This causes the __END__ keyword in my ruby
> script to stop working, and the DATA constant is not set.
>
> Is there a way to tell the gem installer "Hey, quit being so smart and
> just install my executable file without wrappering it with your own
> ruby script".


Something like:

File.read(__FILE__).split("__END__").last

But why not store it in a separate config file?

T.


 
Reply With Quote
 
 
 
 
Tim Pease
Guest
Posts: n/a
 
      02-04-2007
On 2/3/07, Trans <(E-Mail Removed)> wrote:
>
>
> On Feb 3, 4:38 pm, "Tim Pease" <(E-Mail Removed)> wrote:
> > I'm working on Ruby program that will have a resource directory for
> > storing configuration, logging information, etc. I've used the
> > __END__ and DATA trick in my main ruby program to store some sane
> > defaults for the resources directory if this is the first time the
> > program has been run by a user.
> >
> > #!/usr/bin/env ruby
> >
> > require 'mylib'
> >
> > unless File.exist?(ENV['HOME'] + '.myrc')
> > File.open(ENV['HOME'] + '.myrc/defaults', 'w') do |fd|
> > fd.write DATA.readlines
> > end
> > end
> >
> > # use defaults here
> >
> > __END__
> > hash_key_1 : 1
> > hash_key_2 : 2
> > etc : and some more
> >
> > This works very well when my application is run directly. But when
> > installed via gems a new ruby script is created that loads my
> > executable script This causes the __END__ keyword in my ruby
> > script to stop working, and the DATA constant is not set.
> >
> > Is there a way to tell the gem installer "Hey, quit being so smart and
> > just install my executable file without wrappering it with your own
> > ruby script".

>
> Something like:
>
> File.read(__FILE__).split("__END__").last
>
> But why not store it in a separate config file?
>


I'm trying to be clever in the way I bootstrap this config file into
existence. Using __END__ and DATA seemed very Rubyish and clever.
Alas that gems are smarter than I am.

I just dumped it into a here doc in the file. Just as effective.

There is a way to tell gem not to create a wrapper, but the user has
to do it when they install the gem ...

gem install --no-wrapper mygem

However, gem is not honoring the executable bit in the file permission
:/ So the symbolic link to my executable still does not work because
the executable is no longer executable <sigh>.

TwP

 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
RubyGems 0.9.1 calling a gem with gem '<gem>' Austin 7873 Ruby 5 01-27-2007 10:05 PM
gem.cmd install RMagick-win32-1.9.2-mswin32.gem: Buffer error Clifford Heath Ruby 7 06-09-2006 07:02 PM
[GEM PATCH] allow gem to install bin file to different location Ara.T.Howard Ruby 0 10-26-2005 11:52 PM
ERROR: While executing gem ... (Gem::GemNotFoundException) Could not find rubygems-upodate (> 0) in the repository han Ruby 1 10-24-2005 10:28 PM
[ANN] Getopt-Declare 1.12 (gem/zip) and GGEnv (gem/zip) gga Ruby 0 07-18-2005 03:21 PM



Advertisments