Ruby Rake从gem中加载任务 [英] Ruby Rake load tasks from a gem

查看:132
本文介绍了Ruby Rake从gem中加载任务的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我一直在尝试将位于github上的gem添加到我当前的应用程序中。 gem有一个rake文件,我希望能够从我的应用程序访问。但我不断收到加载错误。

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'

宝石文件看起来像那样

# -*- 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

我希望能够将./tasks/deploy.rake加载到我的应用程序中这个宝石,我该如何继续呢?

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

谢谢

推荐答案

好的,如果有人有兴趣,我找到了解决这个问题的方法:

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"

这就是我在Rakefile中需要说的全部内容!

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

这篇关于Ruby Rake从gem中加载任务的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆