Sha256: ca60ab0da53f2864a0cd256af6ce61068e112038aa2759ee26bd59c0fde4abf2
Contents?: true
Size: 594 Bytes
Versions: 3
Compression:
Stored size: 594 Bytes
Contents
module Bourgeois module ViewHelper # Wrap a resource or a collection into its related delegator # # @example # present User.new(name: 'Remi') do |user| # puts user.inspect # => #<UserPresenter object=#<User name="Remi>> # puts user.name # => Remi # end def present(object, klass = nil, &blk) return object.map { |o| present(o, klass, &blk) } if object.respond_to?(:to_a) klass ||= "#{object.class}Presenter".constantize presenter = klass.new(object, self) yield presenter if block_given? presenter end end end
Version data entries
3 entries across 3 versions & 1 rubygems
Version | Path |
---|---|
bourgeois-0.1.1 | lib/bourgeois/view_helper.rb |
bourgeois-0.1 | lib/bourgeois/view_helper.rb |
bourgeois-0.0.1 | lib/bourgeois/view_helper.rb |