Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Framework for non-web Ruby project

I'm looking for a simple Ruby framework for a non-web project. I'm very familiar with Rails, so when I write pure Ruby I miss:

  • The different environments (development, test, production)
  • The console rails c
  • And many other utilities provided by rake or rails

I know I can require ActiveSupport and friends, but it's not what I need. It's mostly the development framework that I miss.

One thing I investigated is to do my project as a gem (even if I don't need a gem at the end). Using jeweler for instance provides versioning. I'm sure there are better ways but I can't find any. What would you use ?

like image 631
Blacksad Avatar asked Aug 18 '11 21:08

Blacksad


People also ask

Which framework is available for Ruby language?

Sinatra. Sinatra is the second most used Ruby Framework (after Ruby on Rails) and was developed in 2007. It is a light micro-framework used by developers to build modern web applications. The users of Sinatra can finish writing the complete code in a single source code file and release the web application to the public ...

What is the most common Ruby framework?

Back-end web framework Ruby on Rails was developed in 2004 and is one of the most popular Ruby web frameworks. On GitHub, this framework has received over 49,000 ratings. Over 1,060,553 active websites rely on the Ruby framework's solid MVC (Model–view–controller) architecture.

Is Ruby a web framework?

Ruby on Rails (simplify as Rails) is a server-side web application framework written in Ruby under the MIT License. Rails is a model–view–controller (MVC) framework, providing default structures for a database, a web service, and web pages.

Is Ruby only used for web development?

Ruby is a popular, flexible programming language that is in high demand in the marketplace. It can be used for web development, scripting, data processing, DevOps, static site generation, and more.

What are frameworks in Ruby on Rails?

Ruby on Rails is known as an MVC (model-view-controller) full-stack framework. The code is separated into three interconnected layers: Model contains the logic of an application, all the essential data, and high-level classes. View is the UI representation of the data present in Modal.


2 Answers

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.

like image 198
Ryan Bigg Avatar answered Sep 20 '22 15:09

Ryan Bigg


First of all, Rails goal as a web framework is to let you mostly forget about the low-level details of a web based application (interacting with a web server, a database, etc.) and provide you with high-level abstractions which allow you to concentrate yourself on the actual job: Getting your application done.

There is such a huge diversity of non-web applications, that it is simply impossible to have a framework that "makes them all".

It is useful to understand what a framework is, and why and when you should use it.

Let's say you would have to build a dog house. You would buy some wood, nails and a hammer to build it the way you want from scratch, or you could go to Walmart and buy a DIY doghouse kit. You will get a manual with detailed instructions on how to build your dog's "dream doghouse", and you will get it faster done than when making it from scratch, but you will be limited to the wood that comes with it and may be forced to use their nails or screws, and in some cases you would also need to buy a special screw driver.

The DIY kit is your framework. Some smart guys already provided you with the basic tools of making your doghouse, you only had to figure out (or not, if you had a manual) how to do it given their "framework".

Now, let's say you would build a skyscraper. The materials, tools and conventions (the framework) used would probably not be the same as they would when building a doghouse, and it would be over-kill to use a "skyscraper framework" to build a doghouse.

You wouldn't write Twitter client with the same set of tools and conventions as you would when writing a banking application with a billion concurrent users.

Rails is just one framework which provides you with a set of many, many good (and useful) conventions to write a web application, but that doesn't necessarily mean that it's the ultimate way to go. You can choose another framework, and maybe you will like the conventions for writing your application even more than the ones provided by Rails; or you could write all from scratch which would not limit you to what is provided by a specific framework and maybe make it even better.

To answer your question: Think of what you want to write and don't let yourself be narrowed down by the set of tools and conventions provided by a framework, as they will surely be if you choose this path.

Buy yourself some books about Design Patterns and read some great software, and then you may understand why the authors did not choose an application framework. Indeed, they've developed their own conventions and defined the behavior of what it should do; and once again, the "Rails way" isn't the only way, which doesn't make it the bad way. :)

I would appreciate constructive criticism as I really tried to provide a good answer.

like image 24
Kenny Meyer Avatar answered Sep 19 '22 15:09

Kenny Meyer