12

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(test@example.com)
  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

Max
  • 1,526
  • 2
  • 16
  • 19

1 Answers1

25

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!

Conor Livingston
  • 905
  • 1
  • 8
  • 17
Max
  • 1,526
  • 2
  • 16
  • 19
  • 2
    for me also work put `require '/rake_tasks'` in Rakefile of App (not gem) – Sergey Makridenkov Sep 24 '13 at 08:06
  • 1
    @SergXIIIth It depends on the structure of the gem. For instance, for `sitemap_generator` it's `require 'sitemap_generator/tasks'`, for `padrino` it's `require 'padrino-core/cli/rake'` etc. – jibiel Dec 15 '13 at 14:16