Class: Search::PresenterFactory
- Inherits:
-
Object
- Object
- Search::PresenterFactory
- Defined in:
- app/presenters/search/presenter_factory.rb
Overview
Factory that resolves a view-model instance to the appropriate Search presenter.
Instance Attribute Summary collapse
-
#namespace ⇒ String
readonly
The namespace prefix used to resolve presenter classes.
-
#presentable ⇒ Object
readonly
The object being presented.
-
#presentable_type ⇒ String
readonly
The inferred base name of the presenter class.
Instance Method Summary collapse
-
#html(view_context = nil) ⇒ BasePresenter, Object
Returns the HTML presenter instance for the presentable object.
-
#initialize(presentable, _presentable_type = nil) ⇒ PresenterFactory
constructor
Creates a new factory for the given presentable object.
-
#text(view_context = nil) ⇒ BasePresenter, Object
Returns the text presenter instance for the presentable object.
Constructor Details
#initialize(presentable, _presentable_type = nil) ⇒ PresenterFactory
Creates a new factory for the given presentable object.
20 21 22 23 24 |
# File 'app/presenters/search/presenter_factory.rb', line 20 def initialize(presentable, _presentable_type = nil) @namespace = "Search::" @presentable = presentable @presentable_type = presentable.class.name.scan(/View(\w+)/).join end |
Instance Attribute Details
#namespace ⇒ String (readonly)
Returns the namespace prefix used to resolve presenter classes.
8 9 10 |
# File 'app/presenters/search/presenter_factory.rb', line 8 def namespace @namespace end |
#presentable ⇒ Object (readonly)
Returns the object being presented.
11 12 13 |
# File 'app/presenters/search/presenter_factory.rb', line 11 def presentable @presentable end |
#presentable_type ⇒ String (readonly)
Returns the inferred base name of the presenter class.
14 15 16 |
# File 'app/presenters/search/presenter_factory.rb', line 14 def presentable_type @presentable_type end |
Instance Method Details
#html(view_context = nil) ⇒ BasePresenter, Object
Returns the HTML presenter instance for the presentable object.
Falls back to the raw presentable when no presenter class exists.
32 33 34 35 |
# File 'app/presenters/search/presenter_factory.rb', line 32 def html(view_context = nil) initialize_html_presenter_klass(view_context) || initialize_fallback_presenter end |
#text(view_context = nil) ⇒ BasePresenter, Object
Returns the text presenter instance for the presentable object.
Falls back to the HTML presenter when no text presenter class exists.
43 44 45 |
# File 'app/presenters/search/presenter_factory.rb', line 43 def text(view_context = nil) initialize_text_presenter(view_context) || html(view_context) end |