Class: Search::PresenterFactory

Inherits:
Object
  • Object
show all
Defined in:
app/presenters/search/presenter_factory.rb

Overview

Presenter: presenter factory.

Instance Attribute Summary collapse

Instance Method Summary collapse

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

#namespaceObject (readonly)

Returns the value of attribute namespace.



4
5
6
# File 'app/presenters/search/presenter_factory.rb', line 4

def namespace
  @namespace
end

#presentableObject (readonly)

Returns the value of attribute presentable.



4
5
6
# File 'app/presenters/search/presenter_factory.rb', line 4

def presentable
  @presentable
end

#presentable_typeObject (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