Sha256: eb262eb9b99eab1a37717faf188d940e637633bb818e02909672ea891f697ec2
Contents?: true
Size: 1.12 KB
Versions: 1
Compression:
Stored size: 1.12 KB
Contents
module Bourgeois class Presenter < ::SimpleDelegator def initialize(object, view = nil) @view = view super(@object = object) end # Return a String representation of the presenter + the original object def inspect "#<#{self.class} object=#{@object.inspect}>" end # We need to explicitely define this method because it's not # catched by the delegator def kind_of?(mod) @object.kind_of?(mod) end # ActionView::Helpers::FormBuilder needs this def self.model_name klass.model_name end # ActionView::Helpers::FormBuilder needs this too def self.human_attribute_name(*args) klass.human_attribute_name(*args) end private # Return the view from where the presenter was created def view @view end # Return the original delegated object def object @object end # Return the original object class based on the presenter class name # We would be able to use `@object.class` but we need this in class methods def self.klass @klass ||= self.name.split(/Presenter$/).first.constantize end end end
Version data entries
1 entries across 1 versions & 1 rubygems
Version | Path |
---|---|
bourgeois-0.1.2 | lib/bourgeois/presenter.rb |