gem issue

Discussion in 'Ruby' started by Tim Pease, Feb 3, 2007.

  1. Tim Pease

    Tim Pease Guest

    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
    Tim Pease, Feb 3, 2007
    #1
    1. Advertising

  2. Tim Pease

    Trans Guest

    On Feb 3, 4:38 pm, "Tim Pease" <> 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.
    Trans, Feb 3, 2007
    #2
    1. Advertising

  3. Tim Pease

    Tim Pease Guest

    On 2/3/07, Trans <> wrote:
    >
    >
    > On Feb 3, 4:38 pm, "Tim Pease" <> 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
    Tim Pease, Feb 4, 2007
    #3
    1. Advertising

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

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. gga
    Replies:
    0
    Views:
    130
  2. han
    Replies:
    1
    Views:
    121
    Lyle Johnson
    Oct 24, 2005
  3. Ara.T.Howard
    Replies:
    0
    Views:
    165
    Ara.T.Howard
    Oct 27, 2005
  4. Clifford Heath
    Replies:
    7
    Views:
    303
    Shanti Braford
    Jun 9, 2006
  5. Austin 7873
    Replies:
    5
    Views:
    182
    Eric Hodel
    Jan 27, 2007
Loading...

Share This Page