The document discusses techniques for dealing with "fat models" in Ruby on Rails applications. It argues that concerns are better than services for encapsulating business logic that belongs in models. Concerns allow models to have default behaviors while still supporting edge cases. The document also notes that the single responsibility principle is misleading, as real-world objects often have multiple related responsibilities. Well-designed models with concerns promote code reuse and testability over separated services.
14. # move
(1) User.create_from_facebook
# to
(2) UserService.create_from_facebook
# or
(3) FacebookService.create_user
Organise services by process
rather than object they operate on
Otherwise at some moment UserService would not be enough
42. Use Concerns
class Comment < AR::Base
include CommentNotification
include FeedActivityGeneration
include Archivable
end
Rails default: app/models/concerns/*
Attention!
50. class User < AR::Base
include FacebookProfile
end
# Hybrid Concern that provides
# instance and class methods
module FacebookProfile
has_one :facebook_profile # simplified
def connected_to_facebook?
def self.register_from_facebook(attributes)
Ex.1 User + Facebook
has_one :facebook_profile => Model
#register_user_from_facebook => Service