Why aren’t Rails applications divided and business logic moved to gems?

ASP.NET MVC and Java web applications have the usual practice of storing business logic in a separate / dll package and processing things such as databases and delivery mechanisms (web application, web service, native mobile or desktop, etc. .d ..) as parts that are connected .

Some of the benefits of this type of structuring I can say:

  • Reuse business logic with various delivery mechanisms or retention levels.
  • You can perform acceptance and unit tests of business logic without having to download a web framework or connect to a database; tests are very fast
  • Thinking about the application in terms of what it is, not how to deliver it

But this practice is not common in the Rails community; I don’t see any Rails application where business logic is stored in gems, and the main ORMs all bind conservation logic and business logic. Is there something in Ruby that makes structuring applications the way I mentioned, unnecessary?

+4
source share
3 answers

Define "necessary." This does not need to be done in .NET or Java, it is convenient.

Rails applications often publish only a web application and related services in a single application.

Testing is similar; there is no need to break the functionality of the application to test the code separately, and testing in Rails is no different: there are unit tests, specifications, etc. that can work at any level of the code, and various mechanisms for extracting arbitrary parts of the functionality.

Retention levels are usually processed by the AR level, although in practice it is rather unusual to actually switch retention levels (I did this exactly once every thirty years of development, but this, of course, is anecdotal). In addition, some of these switches in Ruby are transparent at the code level due to duck text input (for example, I switched one application from the local database to the service almost transparently, switching to ActiveResource instead of ActiveRecord, although I did not try to optimize something later , and the data model was pretty simple.)

All this suggests that the IMO the Rails community often overlooks the practice of "corporate" stores, because the Ruby language simplifies assembly without the need for redesign. The limitations of this only become clear after applications have reached a certain size.

Recent trends in the development of Ruby and Rails include the things that I have been doing in the enterprise for many years (and it’s much easier to implement in Ruby than, say, Java). However, using functionality in libraries alone is not particularly useful. Identification of the code that needs to be broken, but this happens in different environments when necessary.

+3
source

Rails is a configuration convention. And his opinion / recommendations that have been stated.

I don’t see a big advantage to destroy BLL in Gems. If I do not have code that is independent of my web application and can be reused. For example, I recently created a BBCode parser for a corporate forum, so I packaged it as a GEM that can connect to any rails application. There are thousands of GEMs on github that expand the rails functionally.

The whole idea of ​​creating a GEM for a rails application is to reuse the code. If you separate your code to try to further split the code, then you will not rely on rail agreements, and if other rail developers come into your project, they will have a learning curve.

You can use any number of test systems that do not load the web frame on rails. Testing in an entire huge topic I would consider RSpec and much more. And there are several ways to speed up testing (for example, using Guard and Spork)

It all depends on the application. The idea behind Rails is to quickly build your application. Java development in my experience has been very slow. The same goes for ASP. But this may just be a "bad experience." Many people swear by both.

0
source

This mainly concerns efforts and configuration. Let me break up the individual points:

Efforts: Setting up a new gem takes a little time (and each project has its own set of dependencies - testing, bullying, documentation, etc.)

Configuration:. Because most Rails applications use ActiveRecord; It's a little harder to split your model layer (although a lot of gems do this). Rails::Engine helps to greatly alleviate the pain around this.

Cost:. For most Rails projects, there is very little that you get by breaking your code into a separate stone / repo:

  • Most projects do not share the code with each other (and when they do, they set gems)

  • There is - or should be, if properly configured - there is no difference in how you test the code; either in the pearl or in your main project. (You can test models without clicking on your controllers, etc. - no problem)

  • The main advantage is providing explicit contracts between interfaces / layers - and this is less common in the Ruby community.

0
source

All Articles