Open sourcing Aristotle – a new way of looking at Business Logic in Ruby

At Apprentus we’re huge fans of Open Source. Our entire site is built with Ruby on Rails and the vast amount of readily available Rubygems, among other Open Source technologies (PostgreSQL, ElasticSearch, Redis, etc). It is a tremendous timesaver when you can plug in to a great ecosystem and don’t have to write every piece of code from scratch (e.g. Facebook authentication, Geolocation, HTML entity decoding, PDF generation, etc).

In the spirit of giving back to the community when possible we’ll be open sourcing some reusable parts of our site in the coming months.

The first of such parts is Aristotle – a ruby gem built to keep Business Logic code in sync with documentation for non-technical stakeholders. It’s loosely inspired by Cucumber and is actually pretty cool! : )

To explain, let’s start with an example.

We use different mail templates in the different stages of a student-teacher communication. All of these templates can be edited by the admins, but it’s not totally obvious which template is used when.

We used to have code like this in the Message model:

When a wrong template is used and my co-founder asks why, I have to look in the code to figure out what went wrong. It’s possible it wasn’t a technical bug at all, but just false assumptions made when designing the system.

Aristotle lets me separate the logic of choosing the template from the actual model code. I write out the logic rules in plain english in app/logic/message.logic:

And create a corresponding app/logic/message_logic.rb:

Now the code in my Message model just looks like this:

And if my co-founder ever asks which template is used and why, I can direct him to the admin pages where the logic is shown by calling

like this:

Message logic rules

As an added bonus I can directly see the code as well:

Aristotle Business Logic code rules

Choosing a template for a message is a simple example. The system really shines when you have even more rules, for example:

Lines #5 and #6 illustrate the logic errors that are easy to debug with Aristotle without even looking at the code.

So there you have it. Aristotle – a new way of looking at Business Logic in Ruby, built with the goal of minimising documentation and maintenance overhead for non-technical stakeholders.

Check it out and let us know your thoughts!

And if you or someone you know ever needs private lessons on any subject in the French-speaking part of Europe, check out Apprentus!

Tagged with: , ,
Posted in News
About
Apprentus is the best way to find high-quality face-to-face teachers in hundreds of different subjects. From math tutoring to yoga, our mission is to provide thousands of searchable and bookable classes.