Class: Search::PresenterFactory
- Inherits:
-
Object
- Object
- Search::PresenterFactory
- Defined in:
- app/presenters/search/presenter_factory.rb
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
10 11 12 13 14 |
# File 'app/presenters/search/presenter_factory.rb', line 10 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.
3 4 5 |
# File 'app/presenters/search/presenter_factory.rb', line 3 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.
5 6 7 |
# File 'app/presenters/search/presenter_factory.rb', line 5 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
18 19 20 21 |
# File 'app/presenters/search/presenter_factory.rb', line 18 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
25 26 27 |
# File 'app/presenters/search/presenter_factory.rb', line 25 def text(view_context=nil) initialize_text_presenter(view_context) || html(view_context) end |