Class: Search::PresenterFactory

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

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



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

#namespaceObject (readonly)

Returns the value of attribute namespace.



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

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.



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