My Secret Life as a Spaghetti Coder
home | about | contact | privacy statement
Gem, Y U No install from git?

Yesterday I wondered if there was a good reason we couldn't gem install <url to git repository> and thought I'd have a look at adding it to rubygems for fun's sake.

Is there a good reason we can't just do `gem install <url to git repository>` ?

Then I saw how many files there were and decided gem install from git with a shell script would be easily achieved in just a few minutes.

#!/bin/bash
gemifgTMPDIR=$TMPDIR"_gemifg"
git clone $1 $gemifgTMPDIR
gemifgOWD=$PWD
cd $gemifgTMPDIR
gem build *.gemspec
gem install *.gem
if [ ! -z "$gemifgTMPDIR" ]
  then
    rm -rf $gemifgTMPDIR
fi
cd $gemifgOWD

Let me know what you think, or if there are some repositories where it doesn't work for you. I only tested it on utility-belt.

Hey! Why don't you make your life easier and subscribe to the full post or short blurb RSS feed? I'm so confident you'll love my smelly pasta plate wisdom that I'm offering a no-strings-attached, lifetime money back guarantee!


Comments
Leave a comment

Nice idea to get a "snapshot" build gem. But is it convention for a gem to have a .gemspec in the root directory? E.g. I have my gemspec usually inside the Rakefile. You could check for it and use Rake as well (if you want your script to be general).

Posted by Peter Kofler on Jul 16, 2011 at 04:10 PM UTC - 6 hrs

Hey Peter,

That's a good idea. In fact I had originally written it to do `rake build` but then I noticed there was no rakefile in utility-belt.

I've looked up some gem projects this morning - haml, rails, chronic and all have a build task that references a gemspec they also have.

Do you know of an example of one that doesn't include a gemspec that I could use to test on?

Also, do you name the rake task for building the gem 'build' or do you know of any other common task names that people use for the same purpose?

Thanks for the feedback!

Posted by Sammy Larbi on Jul 18, 2011 at 08:12 AM UTC - 6 hrs

I usually put everything inside a Rakefile, see
https://code.google.com/p/javaclass-rb/source/brow...

I copied all the targets together from different OS projects, but can't remember where I took the basic layout from. It's hosted using HG, so I'm not sure it of any use for you. (Although the clone command is similar.)

On the other hand, would you say that including a .gemspec is common usage? So I should follow the lead ;-)

Or with some "magic" you could extract the gemspec definition (that has to live somewhere) from the Rakefile and work using it standalone.

Posted by Peter Kofler on Jul 18, 2011 at 09:16 AM UTC - 6 hrs

Judging from the results of looking up those 4 gems, I'd guess it is common to include a .gemspec, but of course I'd hate to extrapolate that out into a rule without doing further analysis. =)

Posted by Sammy Larbi on Jul 18, 2011 at 02:09 PM UTC - 6 hrs

Looks like you are right, see http://yehudakatz.com/2010/04/02/using-gemspecs-as...

Posted by Peter Kofler on Jul 22, 2011 at 04:24 PM UTC - 6 hrs

Awesome, thanks for sharing that. I was still mulling over how to generalize it, but after reading Yehuda's take, I think I won't expend the effort. =)

How did you come across it?

Posted by Sammy Larbi on Jul 22, 2011 at 07:33 PM UTC - 6 hrs

I already had decided to extract the .gemspec out of the Rakefile and was googling for the best way to do that. I didn't find anything. My Rakefile needs information from the gemspec for some tasks so I ended up with

gemspec = eval(IO.readlines('javaclass.gemspec').join)

which I do not like. "load" would be nicer but does not give me back the instance created in the .gemspec.

On the other hand, some tools, like Jeweler can't have a .gemspec, see http://jeffkreeftmeijer.com/2010/dont-put-your-gem...

Posted by Peter Kofler on Jul 23, 2011 at 01:06 PM UTC - 6 hrs

Cool, thanks. I've enjoyed reading those posts. I like to see the tradeoffs in different ways of doing things, and I hadn't really considered the alternatives in this case.

Posted by Sammy Larbi on Jul 23, 2011 at 01:18 PM UTC - 6 hrs

Leave a comment

Leave this field empty
Your Name
Email (not displayed, more info?)
Website

Comment:

Subcribe to this comment thread
Remember my details
Google
Web CodeOdor.com

Me
Picture of me

Topics
.NET (19)
AI/Machine Learning (14)
Answers To 100 Interview Questions (10)
Bioinformatics (2)
Business (1)
C and Cplusplus (6)
cfrails (22)
ColdFusion (78)
Customer Relations (15)
Databases (3)
DRY (18)
DSLs (11)
Future Tech (5)
Games (5)
Groovy/Grails (8)
Hardware (1)
IDEs (9)
Java (38)
JavaScript (4)
Linux (2)
Lisp (1)
Mac OS (4)
Management (15)
MediaServerX (1)
Miscellany (76)
OOAD (37)
Productivity (11)
Programming (168)
Programming Quotables (9)
Rails (31)
Ruby (67)
Save Your Job (58)
scriptaGulous (4)
Software Development Process (23)
TDD (41)
TDDing xorblog (6)
Tools (5)
Web Development (8)
Windows (1)
With (1)
YAGNI (10)

Resources
Agile Manifesto & Principles
Principles Of OOD
ColdFusion
CFUnit
Ruby
Ruby on Rails
JUnit



RSS 2.0: Full Post | Short Blurb
Subscribe by email:

Delivered by FeedBurner