0.0
No commit activity in last 3 years
No release in over 3 years
Decorator to help with the boilerplate of using Rails helpers. It gently wraps your classes to keep your views fresh.
2005
2006
2007
2008
2009
2010
2011
2012
2013
2014
2015
2016
2017
2018
2019
2020
2021
2022
2023
2024
 Dependencies
 Project Readme

PlasticWrap

A decorator.

Installation

Add this line to your application's Gemfile:

gem 'plastic_wrap'

And then execute:

$ bundle

Or install it yourself as:

$ gem install plastic_wrap

Usage

PlasticWrap is easy to use. There are 2 variants of wrapping.

The easiest and most maleable is Light. This uses SimpleDelegator under the covers to do all the heavy lifting.

class Leftovers
  def best_before
    @best_before ||= Time.now
  end
end

class ReadableBestBefore < PlasticWrap::Light
  def best_before
    super.strftime('%m-%y')
  end
end


ReadableBestBefore.wrap(Leftovers.new).best_before #=> 1-2001

The other variant is Heavy. This uses Delegator under the covers for its lifting. You may want to use this is you don't want to deal with tracing through method_missing calls.

class Leftovers
  def best_before
    @best_before ||= Time.now
  end
end

class ReadableBestBefore < PlasticWrap.create_wrap(Leftovers)
  def best_before
    super.strftime('%m-%y')
  end
end


ReadableBestBefore.wrap(Leftovers.new).best_before #=> 1-2001

No matter which variant you decide to use; the wrap method accepts Enumerables and will return an array of nicely wrapped models. You also get the benefit of all the built-in Rails helpers in your decorators.

Contributing

  1. Fork it
  2. Create your feature branch (git checkout -b my-new-feature)
  3. Commit your changes (git commit -am 'Add some feature')
  4. Push to the branch (git push origin my-new-feature)
  5. Create new Pull Request

Bitdeli Badge