0

I'm starting my way into Ruby development and have some questions that I hope you can give your best opinion to better design some command line applications I'm developing.

What are the best patterns when creating data layers in Ruby? I've seen a lot of articles talking about ORMs (ActiveRecords and others) and also saw articles where classes are created with self methods that make SQL queries, meaning that the model is aware of its own persistence implementation details.

Due to my C# experience I work a lot with repository patterns and I'm really not used to put all my DataLayer logic directly inside the model classes so I tend to look at those kind of approaches as "not" best practices.

As an example, if you have a class Manager with some methods where all the business logic resides and you need to get a class Foo from a SQL database, would you create a class to act as a SQL repository with all the data access implementation there, e.g. SqlRepo.find_foo("1"), or would you just create self methods on the Foo class, each with the persistence detail needed such as Foo.find("1")? Any other better ideas?

Another question that comes to mind is the Ruby on Rails. As far as I know its just a MVC framework for Ruby web development. Some articles talk about ActiveRecords ORM and other subjects in a way that it seems that those gems are almost exclusive for Rails development. Is that only because Rails is very popular, almost more than Ruby itself, and because of that most blogs are from Rails guys so they talk in their comfort zone?

0

... As far as I know its just a MVC framework for Ruby web development. Some articles talk about ActiveRecords ORM and other subjects in a way that it seems that those gems are almost exclusive for Rails development. Is that only because Rails is very popular, almost more than Ruby itself, and because of that most blogs are from Rails guys so they talk in their comfort zone?

The short answer is all Gem's are basically exclusive for RUBY. Not ruby on rails.

The medium length answer is Gems are proprietary to ruby based frameworks. Notice I am saying ruby based frame works, there's got to be 10 or 12 that I know of which are ruby frameworks (Search for ruby frameworks in google) or close enough that they understand & use gems.

Recall, the theory of a Gem was pretty novel in web programming back during the days of the static webpages of the 90s. Since the success of Ruby on Rails post 90's, many of the frameworks have copied the idea of encapsulating a package that automatically install and work for dependencies off publicly available internet libraries for that purpose. Which is why people talk like they do about "gems".

ActiveRecord gem is not actually the entire story either, the gem is just a handler for the pattern known as ActiveRecord. Wiki description...Link. A pretty good description of what the gem & pattern are to ruby on rails here ... Link.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.