class Substance::Presenter
Attributes
view[R]
Public Class Methods
decorated?(object)
click to toggle source
Returns true if object has been wrapped in a Presenter
# File lib/substance/presenter.rb, line 11 def decorated?(object) object.is_a?(Presenter) end
new(object, view)
click to toggle source
Calls superclass method
# File lib/substance/presenter.rb, line 29 def initialize(object, view) super(object) @view = view end
present(object, view)
click to toggle source
Wrap object in presenter with access to a view context
# File lib/substance/presenter.rb, line 16 def present(object, view) return object if decorated?(object) new(object, view) end
present_collection(collection, view)
click to toggle source
Wrap each object in presenter with access to a view context
# File lib/substance/presenter.rb, line 22 def present_collection(collection, view) collection.map do |item| present(item, view) end end
Public Instance Methods
object()
click to toggle source
# File lib/substance/presenter.rb, line 34 def object undecorated(__getobj__) end
Private Instance Methods
decorated?(object)
click to toggle source
# File lib/substance/presenter.rb, line 40 def decorated?(object) self.class.decorated?(object) end
present_collection(collection, presenter)
click to toggle source
# File lib/substance/presenter.rb, line 44 def present_collection(collection, presenter) presenter.present_collection(collection, view) end
undecorated(potentially_decorated_object)
click to toggle source
# File lib/substance/presenter.rb, line 48 def undecorated(potentially_decorated_object) if decorated?(potentially_decorated_object) potentially_decorated_object.object else potentially_decorated_object end end