简体   繁体   English

Sinatra的Rails样式Rake任务(Ruby)

[英]Rails-style Rake Tasks for Sinatra (Ruby)

I can't seem to find a gem or example of anyone using Rails-style rake tasks within a Sinatra app. 我似乎找不到在Sinatra应用程序中使用Rails样式的rake任务的任何人的瑰宝或示例。 I would like to clean out my migrations folder and am looking to do something like explained here: When (if) to consolidate ActiveRecord migrations? 我想清理我的迁移文件夹,并希望按照以下说明进行操作: 什么时候合并ActiveRecord迁移?

Why Sinatra Doesn't Do What You Want "Out of the Box" 为什么Sinatra不能“开箱即用”地做您想做的事

Sinatra isn't a multi-layer framework in the same way as Ruby on Rails. Sinatra不是与Ruby on Rails相同的多层框架。 Specifically, while you can certainly add a database layer to a Sinatra application, it doesn't support ActiveRecord or Rails migrations "out of the box." 具体来说,尽管您当然可以将数据库层添加到Sinatra应用程序中,但它不支持“开箱即用”的ActiveRecord或Rails迁移。

If you're looking for standard Rails rake tasks and migration support, why not just use Rails? 如果您正在寻找标准的Rails rake任务和迁移支持,为什么不只使用Rails? Sinatra is terrific, but it is not a drop-in replacement for Rails. Sinatra很棒,但是它并不是Rails的替代品。

So You Want Database-Centric Rake Tasks... 所以您想要以数据库为中心的耙任务...

If your database connectivity comes from a gem, see if the gem's project has a Rakefile you can re-purpose for your application. 如果您的数据库连接来自gem,请查看gem的项目中是否有Rakefile,您可以将其重新用于您的应用程序。 For example, the sinatra-activerecord gem provides instructions for adding related Rake tasks to your Rakefile. 例如, sinatra-activerecord gem提供了有关将相关Rake任务添加到Rakefile中的说明。

If you rolled your own database connectivity, then you're probably going to have to roll your own Rake tasks as well. 如果您滚动了自己的数据库连接性,那么您可能还必须滚动自己的Rake任务。 The documentation for Rake is extensive, and the features should allow you to automate the tasks you need. Rake文档内容丰富,其功能应允许您自动执行所需的任务。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 Ruby on Rails:调试rake任务 - Ruby on Rails: debugging rake tasks 如何在Ruby中实现自己的Rails样式validates()方法? - How would I implement my own Rails-style validates() method in Ruby? Grails中是否提供Rails样式的链式查询? - Are Rails-style chained queries available in Grails? rake db rake 任务不工作 Ruby 2.4.0 & Rails 5.0.1 - rake db rake tasks not working Ruby 2.4.0 & Rails 5.0.1 使用名称空间的active_admin页面的Rails样式帮助器 - Rails-style helper for active_admin pages using namespace 终端会话连接终止后,Ruby on Rails中的Rake任务将停止 - Rake Tasks in Ruby on Rails are stopped once terminal session connection dies Ruby on Rails-在为Cron Job设置的Rake任务中使用时区 - Ruby on Rails - Using Timezones in Rake Tasks set for Cron Job 如何使用Ruby on Rails访问多个rake任务中的变量 - How to access variables across multiple rake tasks with Ruby on Rails Ruby on Rails 6 - 防止 rake 任务加载到 Heroku 的凭据 - Ruby on Rails 6 - Credentials preventing rake tasks from loading on Heroku Ruby on Rails 中后台作业、rake 任务和 cronjobs 之间的区别? - Difference between background jobs, rake tasks and cronjobs in Ruby on Rails?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM