Class: Search::PresenterFactory
- Inherits:
-
Object
- Object
- Search::PresenterFactory
- Defined in:
- app/presenters/search/presenter_factory.rb
Overview
Presenter: presenter factory.
Instance Attribute Summary collapse
-
#namespace ⇒ Object
readonly
Returns the value of attribute namespace.
-
#presentable ⇒ Object
readonly
Returns the value of attribute presentable.
-
#presentable_type ⇒ Object
readonly
Returns the value of attribute presentable_type.
Instance Method Summary collapse
-
#html(view_context = nil) ⇒ Object
Returns a presenter class for html (view context is required) When no presenter exists, the presentable is returned.
-
#initialize(presentable, _presentable_type = nil) ⇒ PresenterFactory
constructor
Feed in the object to present, e.g.
-
#text(view_context = nil) ⇒ Object
Returns a presenter class for text format, note that a view context is not required.
Constructor Details
#initialize(presentable, _presentable_type = nil) ⇒ PresenterFactory
Feed in the object to present, e.g. an instance ViewCustomer, ViewOrder, etc.
Use presentable type to specify the base type, e.g. Customer, Order. in case it
cannot be inferred from the presentable class name
9 10 11 12 13 |
# File 'app/presenters/search/presenter_factory.rb', line 9 def initialize(presentable, _presentable_type = nil) @namespace = "Search::" @presentable = presentable @presentable_type = presentable.class.name.scan(/View(\w+)/).join end |
Instance Attribute Details
#namespace ⇒ Object (readonly)
Returns the value of attribute namespace.
4 5 6 |
# File 'app/presenters/search/presenter_factory.rb', line 4 def namespace @namespace end |
#presentable ⇒ Object (readonly)
Returns the value of attribute presentable.
4 5 6 |
# File 'app/presenters/search/presenter_factory.rb', line 4 def presentable @presentable end |
#presentable_type ⇒ Object (readonly)
Returns the value of attribute presentable_type.
4 5 6 |
# File 'app/presenters/search/presenter_factory.rb', line 4 def presentable_type @presentable_type end |
Instance Method Details
#html(view_context = nil) ⇒ Object
Returns a presenter class for html (view context is required)
When no presenter exists, the presentable is returned
17 18 19 20 |
# File 'app/presenters/search/presenter_factory.rb', line 17 def html(view_context = nil) initialize_html_presenter_klass(view_context) || initialize_fallback_presenter end |
#text(view_context = nil) ⇒ Object
Returns a presenter class for text format, note that a view context
is not required. At present there is a fallback to an html presenter
24 25 26 |
# File 'app/presenters/search/presenter_factory.rb', line 24 def text(view_context = nil) initialize_text_presenter(view_context) || html(view_context) end |