Installing gems with rake

is that possible.
google says nothing about it.

ciao robertj

···

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

Robert Kuzelj wrote:

is that possible.
google says nothing about it.

ciao robertj

Robert- I'm handling it with a new task and a yml config.

sudo rake gems:install

######## gems.rake ########

namespace :gems do
  require 'rubygems'

  task :install do
    # defaults to --no-rdoc --no-ri, set docs=(anything) to build docs
    docs = (ENV['docs'].nil? ? '--no-rdoc --no-ri' : '')
    #grab the list of gems/version to check
    gems = YAML.load_file 'config/gems.yml'

    gems.each do |gem|
      # load the gem spec
      gem_spec = YAML.load(`gem spec #{gem[:name]}`)
      gem_loaded = false
      gem_loaded = require_gem gem[:name], gem[:version] rescue nil

      # if forced
      # or there is no gem_spec
      # or the spec version doesn't match the required version
      # or require_gem returns false
      # (return false also happens if the gem has already been
loaded)
      if ! ENV['force'].nil? or
         ! gem_spec or
         (gem_spec.version.version != gem[:version] and ! gem_loaded)

        ret = system "gem install #{gem[:name]} -v #{gem[:version]} -y
#{docs}"
        # something bad happened, pass on the message
        p $? unless ret
      else
        puts "#{gem[:name]} #{gem[:version]} already installed"
      end
    end
  end
end

######## gems.yml ########

    - :name: rails
      :version: "1.1.6"

    - :name: fastercsv
      :version: "0.2.1"

    - :name: memcache-client
      :version: "1.0.3"

    - :name: mongrel
      :version: "0.3.13.3"

    - :name: mongrel_cluster
      :version: "0.2.0"

    - :name: uuidtools
      :version: "1.0.0"

    - :name: ferret
      :version: "0.9.5"

···

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