Interior Decorator

Code Climate

Ultra-lightweight decorator for Rails models. Only 42 actionable lines of code!

Installation

Include it in your Gemfile.

gem 'interior_decorator'

Usage

Create Your Decorator

Add your decorator in app/decorators:

class UserDecorator < InteriorDecorator

  def full_name
    "#{first_name} #{last_name}"
  end

  def updated_at
    model.updated_at.strftime("%A, %B %e, %Y")
  end

end

Method calls are sent to the model via method_missing, so you can call model methods directly as in the full_name method defined above.

If there's going to be a method name collision then call model methods with model..

You can access helper methods with helper., or h. for short.

Decorate Your Objects

In Controllers

Just call decorate:

UserDecorator.decorate(user)

In Views

Just call decorate:

<%= decorate(user) %>

Or d for short.

On Collections

Just call decorate. You'll get an array of decorated objects.

UserDecorator.decorate(users)
<%= decorate(users) %>

Vim Projections

For use with Rails.vim. Place in config/projections.json.

{
  "app/decorators/*_decorator.rb": {
    "command": "decorator",
    "alternate": "spec/decorators/%s_decorator_spec.rb",
    "template": "class %SDecorator < InteriorDecorator\nend"
  }
}

Contribute

Pull requests are welcome, but let's keep this thing simple.