upholsterer¶ ↑
Based on SimplePresenter (github.com/fnando/simple_presenter)
<img src=“https://codeclimate.com/github/llxff/upholsterer/badges/gpa.svg” /> <img src=“https://hakiri.io/github/llxff/upholsterer/master.svg” alt=“security” /> <img src=“https://travis-ci.org/RuntimeLLC/upholsterer.svg” />
Installation¶ ↑
gem install upholsterer
Usage¶ ↑
class User < ActiveRecord::Base # implements the following attributes: name, email, password_hash, password_salt end class UserPresenter < Upholsterer::Base expose :name, :email end or class UserPresenter < Upholsterer::Base expose_all end user = UserPresenter.new(User.first) users = UserPresenter.map(User.all)
If you’re using Upholsterer within Rails, presenters also have access to:
-
route helpers: just use the
routes
orr
methods -
view helpers: just use the
helpers
orh
methods -
I18n methods: just use the
translate
,t
,localize
orl
methods
If you want to to use *_url
route methods, make sure you set the default_url_options
option. You can use the config.upholsterer.default_url_options
method, which defaults to config.action_mailer.default_url_options
. You can add something like the following to your config/environments/development.rb
, for instance:
config.upholsterer.default_url_options = {:host => "localhost:3000"}
For additional usage, check the specs.
Troubleshooting¶ ↑
If you’re having problems because already have a class/module called Presenter that is conflicting with this gem, you can require the namespace and inherit from Upholsterer::Base
.
require "upholsterer/namespace" class UserPresenter < Upholsterer::Base end
If you’re using Rails/Bundler or something like that, remember to override the :require
option.
# Gemfile source :rubygems gem "upholsterer", :require => "upholsterer/namespace"
License¶ ↑
(The MIT License)
Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the ‘Software’), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED ‘AS IS’, WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.