Framework for Non-Web Ruby Project

Framework for non-web Ruby project

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.

Is Ruby on Rails suitable for a non-web application?

Rails is specifically a web application framework, however there are GUI toolkits that can be used with Ruby, including Qt (although not the open source version).

Do you need a framework to write Ruby or Python code for the web?

The short answer is no, they are not necessary. In ruby you have .erb templates that can be used in a similar way as you use PHP pages. You can write a site in ruby or Python using several technologies (Rails-like frameworks, Templates or even talking directly with the HTTP library and building the page CGI-style).

Web frameworks like Python's Django or Ruby's Rails (there are many) just raise the level of abstraction from the PHP's or ASP's, and automate several process (like login, database interaction, REST API's) which is always a good thing.

Recommendations for sites / articles / books on developing web sites in Ruby without using a framework such as Rails / Merb

You should give Sinatra a try. It's a framework, but a minimalistic one, so you can easily see what is going on under the hood.

Other than that maybe the CGI Ruby library is a place to look into.

Building a Web Framework

For creating a web framework (if you don't want to handle all of the http stuff) i'd look into rack

for example:

class App
def call
[200, {"Content-type:" => "text/html"}, ["Hello"]]
end
end

# config.ru

run App.new

Is cucumber suitable for non-web project?

I've used Cucumber plenty for non-Rails applications. It's useful for testing full use cases, regardless of the interface. For example, testing multiple runs of a command-line application quickly.



Related Topics



Leave a reply



Submit