Class: Substance::Presenter
- Inherits:
-
SimpleDelegator
- Object
- SimpleDelegator
- Substance::Presenter
- Defined in:
- lib/substance_presenter.rb
Instance Attribute Summary collapse
-
#view ⇒ Object
readonly
Returns the value of attribute view.
Class Method Summary collapse
-
.decorated?(object) ⇒ Boolean
Returns true if object has been wrapped in a Presenter.
-
.present(object, view) ⇒ Object
Wrap object in presenter with access to a view context.
-
.present_collection(collection, view) ⇒ Object
Wrap each object in presenter with access to a view context.
Instance Method Summary collapse
-
#initialize(object, view) ⇒ Presenter
constructor
A new instance of Presenter.
- #object ⇒ Object
Constructor Details
#initialize(object, view) ⇒ Presenter
Returns a new instance of Presenter.
29 30 31 32 |
# File 'lib/substance_presenter.rb', line 29 def initialize(object, view) super(object) @view = view end |
Instance Attribute Details
#view ⇒ Object (readonly)
Returns the value of attribute view.
7 8 9 |
# File 'lib/substance_presenter.rb', line 7 def view @view end |
Class Method Details
.decorated?(object) ⇒ Boolean
Returns true if object has been wrapped in a Presenter
11 12 13 |
# File 'lib/substance_presenter.rb', line 11 def decorated?(object) object.is_a?(Presenter) end |
.present(object, view) ⇒ Object
Wrap object in presenter with access to a view context
16 17 18 19 |
# File 'lib/substance_presenter.rb', line 16 def present(object, view) return object if decorated?(object) new(object, view) end |
.present_collection(collection, view) ⇒ Object
Wrap each object in presenter with access to a view context
22 23 24 25 26 |
# File 'lib/substance_presenter.rb', line 22 def present_collection(collection, view) collection.map do |item| present(item, view) end end |
Instance Method Details
#object ⇒ Object
34 35 36 |
# File 'lib/substance_presenter.rb', line 34 def object undecorated(__getobj__) end |