Objects on Rails

Author Avdi Grimm
Format online HTML
Price free

This is not a Rails tutorial. This is the complete text of Objects on Rails, a “developer’s notebook” documenting some guidelines, techniques, and ideas for applying classic object-oriented thought to Ruby on Rails applications. This book is aimed at the working Rails developer who is looking to grow and evolve Rails projects while keeping them flexible, maintainable, and robust. Using the development of a blog app as its example, the focus is on pragmatic solutions which tread a “middle way” between the expedience of the Rails “golden path”, and rigid OO purity.

Chapters include:

  • What this is not
  • About the approach
  • About the Code
  • A note on scale
  • Why OOP?
  • Yet another frickin’ blog app
  • Adding blog entries
  • Placeholder blog entries
  • Making new entries
  • Posts vs. Entries
  • The Post class
  • Why “publish”?
  • Adding entries to the blog
  • Submitting posts
  • Using ActiveModel
  • The Post creation action
  • Making the Blog object into a Singleton
  • Object Trees and Lone Wolves
  • Getting the tests running again
  • Stubbing out modules
  • Adding timestamps
  • Sensible defaults for injected dependencies
  • OMG Dependency Injection!
  • Injecting only the dependencies we need
  • Sorting and limiting posts
  • Adding validation
  • Introducing the Exhibit Pattern
  • Exhibit A
  • What about Presenters?
  • Exhibit Object Characteristics
  • Refactoring the exhibits
  • Refactoring #exhibit
  • Many models to many exhibits
  • Do we need helpers?
  • Making the data stick around
  • The trouble with ActiveRecord
  • Adding ActiveRecord
  • Why does Blog do the saving?
  • Updating the Blog tests
  • Separating out integration tests
  • Updating the Post tests
  • Mocking ActiveRecord
  • Stubbing out the Database with NullDB
  • Rake tasks for testing
  • Using ActiveRecord objects as data access objects
  • Concealing ActiveRecord behind a FigLeaf
  • Exiting Eden
  • Default content
  • Navel-gazing objects
  • Exhibits for REST
  • Adding tags
  • An Object Model for Tags
  • Conversions
  • Attaching the TagList to a Post
  • Making Post more tag-aware
  • Accepting and displaying tags
  • Filtering posts by tag
  • Extracting a Taggable role
  • Refactoring to a separate ActiveRecord model
  • Reconsidering Taggable
  • Respecting controller privacy
  • Jealously guarding collections
  • Objects as lending libraries
  • Toward self-rendering objects
  • Exhibiting from inside the controller
  • Exhibiting the blog object
  • The exhibit_query macro
  • Finishing the BlogExhibit
  • Rendering the list of posts
  • An exhibit for collections
  • Transitive exhibited-ness
  • Telling the post to render itself
  • Entry collection, render thyself
  • Rendering a TagList
  • Bringing it all back home

Read Mirror

Leave a Reply

Your email address will not be published. Required fields are marked *