use decent_exposure with decorators
Ruby
Latest commit 4698d64 Aug 24, 2016 @pewniak747 pewniak747 committed on GitHub Merge pull request #7 from fs/decent-exposure-3-0
Make compatible with decent-exposure 3.0

README.md

decent_decoration

Build Status Code Climate Coverage Status Gem Version

decent_decoration allows you to use excellent decent_exposure 3.0 gem with decorators.

Installation

Add this line to your application's Gemfile:

gem 'decent_decoration', '~> 0.1.0'

And then execute:

$ bundle

Usage

# app/controllers/conferences_controller.rb
# with decent_exposure
class ConferencesController < ApplicationController
  expose(:conference) { ConferenceDecorator.new(build_conference) }

  private

  def build_conference
    # create new conference or fetch existing one
  end
end

# with decent_decoration
class ConferencesController < ApplicationController
  expose_decorated(:conference)
end

decent_decoration makes decorated objects accessible in views. They remain undecorated in your controllers.

Define a decorator explicitly:

# app/controllers/conferences_controller.rb
class ConferencesController < ApplicationController
  expose_decorated(:conference, decorator: SponsoredConferenceDecorator)
end

decent_decoration detect automatically if you want to decorate a collection. To circumvent this pass collection: true/false

# app/controllers/conferences_controller.rb
class ConferencesController < ApplicationController
  expose_decorated(:conferences, collection: false)
end

decent_decoration supports most of the awesome decent_exposure api. Read more about it!

# app/controllers/attendees_controller.rb
class AttendeesController < ApplicationController
  expose_decorated(:conference)
  expose_decorated(:attendees, scope: :conference)
end

You can use any decorator mechanism as long as ConferenceDecorator responds to #decorate or #new. Try draper.

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

Copyright © 2012–2014 netguru. See LICENSE for further details.