giant robots smashing into other giant robots

Written by thoughtbot

jferris

Ruby Science: Inheritance, Composition, STI, and Polymorphic Associations

Todays’ release of Ruby Science includes two new chapters. If you’re already reading Ruby Science, make sure to log into GitHub and download the latest version.

In this week’s updates, we cover composition and inheritance. You’ll learn about the uses and drawbacks of Single Table Inheritance (STI), as well as how to convert an STI hierarchy to use composition through polymorphic associations.

The book is a work in progress, and currently contains around 104 pages of content. A $49 purchase gets you access to the current release of the book, all future updates, and the companion example application. In addition, purchasers have the ability to send thoughtbot their toughest Ruby, Rails, and refactoring questions.

Get your copy of Ruby Science today.

jayroh

Handle incoming email with Griddler

Griddler

For all the likes, shares, tweets, pokes, follows, and friends, there’s a fundamental core to the internet that, no matter how hard some might hope, will never go away—email. Rails has built-in support for outgoing mail with ActionMailer, but nothing on the omakase menu handles incoming mail. To help with that, we extracted Griddler from Trajectory and are now happy to release it—hot off the… ahem… presses.

Griddler is a Rails engine that provides an endpoint for the SendGrid Parse API. It hands off a preprocessed email object to a class implemented by you. We’re happy to look at pull requests that interface with other email services.

Setup

To get Griddler integrated with your app, add Griddler to your Gemfile, and bundle away:

gem 'griddler'

Griddler automatically adds an endpoint to your routes table resembling the following:

post '/email_processor' => 'griddler/emails#create'

But you may copy, paste, and modify that anywhere else in your routes for the purposes of your application.

Once Sendgrid posts to your endpoint Griddler will take care of packaging up the important bits of that data and providing a nice Griddler::Email object for you. The contract we expect you to go in on with Griddler at this point is that you will implement a class called EmailProcessor, containing a class method called process, which we will be passing that packaged up instance of Griddler::Email into.

For example, in lib/email_processor.rb:

class EmailProcessor
  def self.process(email)
    # all of your application-specific code here - creating models,
    # processing reports, etc
  end
end

The email object contains the following attributes:

  • to
  • from
  • subject
  • body
  • raw_body

Of those, to, from, and subject fall on the obvious side as to their purpose.

Let your users interact with your app via email

What isn’t entirely obvious (but very cool) is that Griddler helps you handle the email body by cleaning up replies and providing the important parts of an email before -- Reply ABOVE THIS LINE -- in the body attribute. Note that the reply delimeter is adjustable in the configuration. We keep raw_body around, as contains everything before Griddler scrubs it into body so that you may use the contents for other purposes.

There is much more information in the Griddler README explaining the details, configuration, testing, and other bits.

If you like it, let us know what you think! As always, you can find the code on GitHub. We look forward to hearing all of the ways you use Griddler!

jferris

Ruby Science: Avoid Divergent Change and Use Convention Over Configuration

We have two new chapters to announce this week in Ruby Science. If you’re already reading Ruby Science, make sure to log into GitHub and download the latest version.

With this week’s updates, you’ll learn how to keep your classes from becoming junk drawers by learning to avoid Divergent Change. You’ll also see an example of using Convention Over Configuration to remove tedious boilerplate and avoid Duplicated Code.

The book is a work in progress, and currently contains around 82 pages of content. Purchasing the book also gets you access to the companion example application, as well as the ability to send thoughtbot your toughest Ruby, Rails, and refactoring questions.

If you haven’t already purchased it, you can still get access for the early purchase price of $39.

This Friday, the price will increase to $49.

Get your copy of Ruby Science today.

jferris

Ruby Science: Improving Callbacks and Validations

We have three new chapters to announce this week in Ruby Science. If you’re already reading Ruby Science, make sure to log into GitHub and download the latest version.

Here’s what’s new:

Code smells

  • Callback

Solutions

  • Extract Validator
  • Replace Callback with Method

The book is a work in progress, and currently contains around 76 pages of content. Purchasing the book also gets you access to the companion example application, as well as the ability to send thoughtbot your toughest Ruby, Rails, and refactoring questions.

If you haven’t already purchased it, you can still get access for the early purchase price of $39. In less than two weeks, the price will increase to $49.

Download a free sample of Ruby Science today.

Episode #28: Farther, further, faster

In this podcast episode, Ben Orenstein is joined by David Heinemeier Hansson, the creator of Ruby on Rails and a partner at 37signals. David and Ben discuss David’s normal day, his working relationship with Jason Fried, how their blog, Signal vs. Noise, is important to the company, how he got into programming, where he draws his inspiration from, some good books he’s read and how he learns today, how he overcomes fear and why he takes risks, how he got into racing, why he enjoys it, what he learns from it, and how feedback loops and goal posts help you learn, inspire you, and help you know how good you are. They then go on to explore what David would, or wouldn’t, change about Rails, and how he sees Rails evolving into the future. David also talks a little bit about the new product 37signals has in development, and 37signals’ overall product strategy, coding at 37signals and his approach to providing guidance to the team, what role he plays on Rails core, what he cares about, and what he pays attention to, and much, much more.