acts_as_list refactoring part 3

I refactor acts_as_list Ruby gem again: watch as I choose better names, strip unnecessary variables, work with some ActiveRecord internals and make code intent clearer. In this refactoring adventure I'm going to focus on just one 11-line method, and surprisingly, there's a lot of things that can be improved in just one method. You don't need to read part 2 and part 1 to understand this article. acts_as_list is a Rails gem. It allows you to treat Rails model

Continue Reading

acts_as_list refactoring part 2

In this post I'm continuing refactoring of acts_as_list gem I started in part 1. As you might remember, I've split .acts_as_list method into several modules, each module dedicated to an option passed to the method. E.g. ColumnMethodDefiner module defines methods related to the column option (the option defines column name for storing record's list position). This post is dedicated to refactoring of the ColumnMethodDefiner module. Improving ColumnMethodDefiner module So, I've extracted code related to column option of .acts_as_list to

Continue Reading

Be lazy and don’t keep context in your head

Sometimes, code we read makes us to remember context. Consider the following code (it sends an invite email to a user): Lines 2-8 (see above ↑) deal with the case of existing user, and the rest deal with the case of new user. When reading lines 3-5 you have to remember that you're dealing with an existing user, same with lines 12-22, only there you deal with a new user. After all, both existing user and new user cases

Continue Reading
Web Analytics