使用 Sinatra 时如何从 gem 导入 rake 任务?

发布于 2024-10-27 10:14:59 字数 1235 浏览 0 评论 0原文

我正在尝试向 orientdb gem 添加一些基本的 rake 任务,这将允许我创建数据库、创建数据库迁移并迁移数据库 - 类似于 Rails 迁移。

当我在本地执行 rake 任务时,我得到了 db:settings、db:create 和 db:create_migration 来工作,但是当我将它们放入 gem 中后,我不知道如何在使用时从 Sinatra 应用程序访问它们“耙”。

我有一种感觉,我要么 a) 没有正确组织 gem 中的文件和/或 b) 没有从 Sinatra 应用程序正确调用内容。

我的分叉存储库的当前状态位于 https://github.com/ricaurte/orientdb-jruby

我将任务文件放入 lib/orientdb/tasks/database.rake => https://github.com/ricaurte/orientdb -jruby/blob/master/lib/orientdb/tasks/database.rake

Sinatra App Rakefile

APPLICATION_ROOT = File.expand_path('..', __FILE__)

require 'rake'
require 'orientdb'
#import "orientdb/tasks/database.rake"

task :environment do
  require File.expand_path(File.join(*%w[ config environment ]), File.dirname(__FILE__))
end

配置/环境

require "rubygems"
require "bundler"
Bundler.setup

require 'sinatra'
require "orientdb"

ruby​​: jruby 1.6.0 (ruby 1.9.2 patchlevel 136) (2011-03-24 5f5278c) (OpenJDK 64 位服务器虚拟机 1.6.0_20) [linux-amd64-java]

I'm trying to add some basic rake tasks to the orientdb gem that will allow me to create the database, create database migrations, and migrate the database - similar to rails migrations.

When I had the rake tasks locally, I got the db:settings, db:create, and db:create_migration to work, but after I put them in the gem I can't figure out how to access them from the Sinatra application when using "rake".

I have a feeling I am either a) not organizing the files in the gem properly and/or b) not calling things properly from the Sinatra app.

The current state of my forked repository is at https://github.com/ricaurte/orientdb-jruby

I put the file for the tasks in lib/orientdb/tasks/database.rake => https://github.com/ricaurte/orientdb-jruby/blob/master/lib/orientdb/tasks/database.rake

Sinatra App Rakefile

APPLICATION_ROOT = File.expand_path('..', __FILE__)

require 'rake'
require 'orientdb'
#import "orientdb/tasks/database.rake"

task :environment do
  require File.expand_path(File.join(*%w[ config environment ]), File.dirname(__FILE__))
end

config/environment

require "rubygems"
require "bundler"
Bundler.setup

require 'sinatra'
require "orientdb"

ruby: jruby 1.6.0 (ruby 1.9.2 patchlevel 136) (2011-03-24 5f5278c) (OpenJDK 64-Bit Server VM 1.6.0_20) [linux-amd64-java]

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

双手揣兜 2024-11-03 10:14:59

经过 10 多个小时的尝试,我终于弄清楚了如何做到这一点,并且在此过程中我必须修补 Rake。我提交了这个补丁:
https://github.com/jimweirich/rake/pull/28

我还写了一篇博客文章,其中包含修补后的代码:
http://www.justinidea.com/2011/03/ suggest-modification-to-rakes-discovery-of-tasks.html

[更新]

我还找到了另一种不需要rake补丁的方法,想想看......我所要做的就是创建一个任务.rb 并在 rakefile 中需要它,但为了使其工作,我必须使它看起来像这样:

require 'rake'
require 'bundler'
Bundler.setup
require 'orientdb'
require 'orientdb/tasks'

不过,我仍然认为 rake 补丁非常酷。 :)

[更新 2]

在拉取请求被 rake 团队接受之前,我创建了一个名为 alltasks 的 gem,它将加载 Gemfile 中的 gem 及其依赖项包含的所有 rake 任务。

https://github.com/ricaurte/alltasks

I figured out how to do it after 10+ hours of trying to figure it out and I had to patch Rake in the process. I submitted this patch:
https://github.com/jimweirich/rake/pull/28

I also wrote up a blog entry that contains the patched code:
http://www.justinidea.com/2011/03/proposed-modification-to-rakes-discovery-of-tasks.html

[UPDATE]

I also found another way that doesn't require a rake patch, go figure...all I had to do was create a tasks.rb and require it inside the rakefile, but to make this work I had to make it look like this:

require 'rake'
require 'bundler'
Bundler.setup
require 'orientdb'
require 'orientdb/tasks'

I still think the rake patch is pretty cool though. :)

[UPDATE 2]

In the mean time until the pull request gets accepted by the rake team, I created a gem called alltasks that will load all of the rake tasks that the gems in your Gemfile and their dependencies contain.

https://github.com/ricaurte/alltasks

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文