非Web Ruby项目的框架 [英] Framework for non-web Ruby project

查看:48
本文介绍了非Web Ruby项目的框架的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在为非网络项目寻找一个简单的Ruby框架.我对Rails非常熟悉,所以当我写纯Ruby时我会想念:

  • 不同的环境(开发,测试,生产)
  • 控制台 c
  • Rake或Rails提供的许多其他实用程序

我知道我可以要求ActiveSupport和朋友,但这不是我所需要的.主要是我想念的开发框架.

我研究过的一件事是将我的项目做为一个宝石(即使我最后不需要宝石).例如,使用jeweler提供版本控制.我敢肯定还有更好的方法,但是我找不到.你会用什么?

解决方案

好的,这有点像一个三部分的问题.越狱或trystti ...实际上不起作用.然后是越狱.

要了解有关Rails的一件事,就是不是神奇的.它是由有过失(例如过大的自我)但又真该死的聪明的凡人编写的代码.因此,经过一点点研究他们的工作,我们就可以理解它.

1.Rails环境很可爱

Rails环境管理背后的代码实际上非常简单.您有一个默认环境,它被development /server.rb#L53-55"rel =" nofollow> railties/lib/rails/commands/server.rb 中的这一行.您可以在应用程序中做很多相同的事情.运行一些定义 YourAwesomeThing.environment = ENV ["AWESOME_ENV"] ||的初始化代码.开发" .然后,在需要的地方需要 config/environments/#{YourAwesomeThing.environment} .rb .然后,需要在这些文件中进行配置,以根据环境修改库的工作方式.

我找不到在 3-1-stable (已经消失了的步兵)中执行此操作的行,因此 exit .很棒.我认为Rails开发人员不太喜欢控制台.

无论如何,这只是一个 irb 会话,之前已加载Rails环境!我再说一遍:Rails 不是神奇的.如果您键入 irb ,然后在该irb会话中键入 require'config/environment',您将获得(至少据我所知...)相同的内容到Rails控制台!

这是由于Rails初始化部分中发生的魔术所致,而魔术几乎是魔术,但并非如此.我已经在 解决方案

Alright, that is somewhat of a three-part question. A threstion, or triesti... actually that doesn't work. Threstion it is then.

One thing to understand about Rails is that it isn't magical. It's code, written by mortal humans who have faults (such as oversized-egos) but who are also incredibly damn smart. Therefore, we can understand it after perhaps a little bit of studying their work.

1. Rails environments are lovely

The code behind the Rails environment management is actually quite simple. You have a default environment which is set to development by this line in railties/lib/rails/commands/server.rb. You could do much the same thing in your application. Run a bit of initialization code that defines YourAwesomeThing.environment = ENV["AWESOME_ENV"] || "development". Then it's a matter of requiring config/environments/#{YourAwesomeThing.environment}.rb where you need it. Then it's a matter of having configuration in those files that modify how your library works depending on the environment.

I couldn't find the line that does that in 3-1-stable (it's gone walkies), so here's one that I think does it in the 3-0-stable branch..

As for the lovely methods such as Rails.env.production?, they are provided by the ActiveSupport::StringInquirer class.

2. Rails console is the Second Coming

I think rails console is amazing. I don't want to create a new file just to manually test some code like I would have done back in the Black Days of PHP. I can jump into the console and try it out there and then type exit when I'm done. Amazing. I think Rails developers don't appreciate the console nearly enough.

Anyway, this is just an irb session that has the Rails environment loaded before it! I'll restate it again: Rails is not magical. If you typed irb and then inside that irb session typed require 'config/environment' you would get (at least as far as I am aware...) an identical thing to the Rails console!

This is due to the magic that goes on in the initialization part of Rails which is almost magic, but not and I've explained it in the Initialization Guide Which Will Be Finished And Updated For Rails 3.1 Real Soon I Promise Cross My Heart And Hope to Die If Only I Had The Time!

You could probably learn a lot by reading that text seemingly of a similar length to a book written by George R. R. Martin or Robert Jordan. I definitely learned a lot writing it!

3. The Others

This is where I falter. What other utilities do you need from Rake / Rails? It's all there, you just need to pick out the parts you need which is actually quite simple... but I can't tell you how to do that unless you go ahead and paint those targets.


Anyway, this is the kind of question that is exciting for me to answer. Thanks for giving me that bit of entertainment :)

Edit

I just noticed the BONUS fourth question at the end of your question. What would be the point of versioning your project? Why not use a version control system such as Git to do this and just git tag versions as you see fit? I think that would make the most sense.

这篇关于非Web Ruby项目的框架的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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