Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Ruby Rake load tasks from a gem

i have been trying to include a gem located on github to my current app. The gem has a rake file that i want to able to access from my app. But i keep getting load errors.

load 'tasks/deploy.rake'

The gem file looks something like that

# -*- encoding: utf-8 -*-
require 'rake'

Gem::Specification.new do |gem|
  gem.authors       = %w(Hello World)
  gem.email         = %w([email protected])
  gem.description   = 'test'
  gem.summary       = 'test'
  gem.homepage      = 'https://github.com/..'
  gem.files         = FileList[ 'lib/**/*.rb', 'tasks/deploy.rake', 'README.md' ].to_a
  gem.name          = 'test'
  gem.require_paths = %w(lib)
  gem.version       = '0.0.1'
end

I want to be able to load ./tasks/deploy.rake to my app that includes this gem, how do i go on about it?

thanks

like image 969
Max Avatar asked Mar 16 '13 06:03

Max


People also ask

What is Rakefile in Ruby?

Rake is a tool you can use with Ruby projects. It allows you to use ruby code to define "tasks" that can be run in the command line. Rake can be downloaded and included in ruby projects as a ruby gem. Once installed, you define tasks in a file named "Rakefile" that you add to your project.

How Rakefile works?

By default, the Rake utility checks the current working directory for a file with the name Rakefile (with no extension). This enables you to add a file of Rake tasks to the source code of any application without conflicting with the names of existing files.

What is Rakefile?

A Rakefile contains executable Ruby code. Anything legal in a ruby script is allowed in a Rakefile. Now that we understand there is no special syntax in a Rakefile, there are some conventions that are used in a Rakefile that are a little unusual in a typical Ruby program.


1 Answers

Okay, I found a solution for this problem if anyone is interested:

# Rails.root/Rakefile

spec = Gem::Specification.find_by_name 'test'
load "#{spec.gem_dir}/tasks/deploy.rake"

That's all I needed to say in my Rakefile!

like image 166
Max Avatar answered Sep 22 '22 00:09

Max