If you're working from Rake, which is already a gem, it will load
rubygems so no need for you to do the require.
Also, having gem 'abc', '>= 0' is the same as doing the require of
that gem directly (it will always load the latest version), having
'gem' in your code makes it already dependent on RubyGems, which
breaks the statements in your first link.
I normally don't define any gem method in my libraries since my
dependencies will be loaded with the require (in case I'm creating a
gem that depends on other, RubyGems will active these dependencies
before I do require)
···
On Jan 14, 6:46 am, Bernard Lambeau <blamb...@gmail.com> wrote:
Do you see "enhancement of" / "agreement about" such a pattern? Any reading
I should further read ??
* If I write a pure library, your answer makes sense as the dependencies
will be managed as you say.
* The same is true when the code is invoked by rake, ok.
* What if I have a bin/foo executable? Should I make something special there
if I have version requirements on external libs ??
Thanks again!
B
···
On Fri, Jan 14, 2011 at 2:22 PM, Luis Lavena <luislavena@gmail.com> wrote:
On Jan 14, 6:46 am, Bernard Lambeau <blamb...@gmail.com> wrote:
>
> Do you see "enhancement of" / "agreement about" such a pattern? Any
reading
> I should further read ??
>
Use plain require.
If you're working from Rake, which is already a gem, it will load
rubygems so no need for you to do the require.
Also, having gem 'abc', '>= 0' is the same as doing the require of
that gem directly (it will always load the latest version), having
'gem' in your code makes it already dependent on RubyGems, which
breaks the statements in your first link.
I normally don't define any gem method in my libraries since my
dependencies will be loaded with the require (in case I'm creating a
gem that depends on other, RubyGems will active these dependencies
before I do require)
I see (I was currently re-reading 54177’s gists · GitHub, which is
clear in fact -- my apologies).
I understand that users of my library will have a good _foo_ executable that
works fine
Now, as a developer I would like to be able to run (no rake, no rspec, and
so on):
ruby -rrubygems bin/foo
How are version requirements met in that scenario? I assume they are not and
that rubygems will load last versions of all gems?
Should I configure rvm's gemsets on my devel computer ? or do you use
Bundler to manage that case ??
Thanks again for clarification!
B
···
On Fri, Jan 14, 2011 at 3:10 PM, Luis Lavena <luislavena@gmail.com> wrote:
On Jan 14, 11:02 am, Bernard Lambeau <blamb...@gmail.com> wrote:
> * What if I have a bin/foo executable? Should I make something special
there
> if I have version requirements on external libs ??
>
Actually no.
RubyGems will wrap your bin/foo script with a loader that looks like
this:
require 'rubygems'
version = ">= 0"
if ARGV.first =~ /^_(.*)_$/ and Gem::Version.correct? $1 then
version = $1
ARGV.shift
end
gem 'mygem', version
load Gem.bin_path('mygem', 'foo', version)
So your foo script don't need to require rubygems.
And when developing, if you run through rspec, it will already load
rubygems for you.
If you want to test from the command line, then you can:
ruby -rrubygems -Ilib bin/foo
Or simple put RUBYOPT=-rrubygems
and have ruby -Ilib bin/foo
So, under your environment will have rubygems and nowhere in your
code.
Thanks a lot Luis, it makes things a lot clearer for me!!
For the sake of history, the initial code I was refering to in my first
message is now here:
B
···
On Fri, Jan 14, 2011 at 5:15 PM, Luis Lavena <luislavena@gmail.com> wrote:
On Jan 14, 11:26 am, Bernard Lambeau <blamb...@gmail.com> wrote:
> [Note: parts of this message were removed to make it a legal post.]
>
> I see (I was currently re-readinghttps://gist.github.com/54177, which is
> clear in fact -- my apologies).
>
> I understand that users of my library will have a good _foo_ executable
that
> works fine
>
> Now, as a developer I would like to be able to run (no rake, no rspec,
and
> so on):
>
> ruby -rrubygems bin/foo
>
> How are version requirements met in that scenario? I assume they are not
and
> that rubygems will load last versions of all gems?
They are not. Up to you deal with the dependencies.
>
> Should I configure rvm's gemsets on my devel computer ? or do you use
> Bundler to manage that case ??
>
Don't add bundler code to your library either, as bundler depends on
RubyGems, you can:
ruby -rrubygems -rbundler/setup bin/foo
Above line will work on 1.9, but not on Ruby 1.8.x