简体   繁体   中英

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(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

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!

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM