Class: QuickSearch::BasePresenter

Inherits:
Object
  • Object
show all
Defined in:
app/presenters/quick_search/base_presenter.rb

Overview

Base presenter for quick search results and pinned records.

Wraps a domain object together with the view context so subclasses can
build display attributes and call URL/helpers without holding a reference
to the controller.

See Also:

Direct Known Subclasses

PinPresenter

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(object, template) ⇒ QuickSearch::BasePresenter

Parameters:

  • object (Object)

    the record being presented

  • template (Object)

    the view context used for helpers and URL generation



14
15
16
17
# File 'app/presenters/quick_search/base_presenter.rb', line 14

def initialize(object, template)
  @object = object
  @template = template
end

Dynamic Method Handling

This class handles dynamic methods through the method_missing method

#method_missingObject (private)

Delegates any unknown method to the view context.

Forwards the method name, arguments, and block (anonymous rest params).

Returns:

  • (Object)

    the template's return value



43
44
45
# File 'app/presenters/quick_search/base_presenter.rb', line 43

def method_missing(*, &)
  @template.send(*, &)
end

Class Method Details

.presents(name) ⇒ Symbol

Defines an instance reader named +name+ that returns the wrapped object.

Parameters:

  • name (Symbol)

    the reader name to define (e.g. +:result+)

Returns:

  • (Symbol)

    the name of the defined method



25
26
27
28
29
# File 'app/presenters/quick_search/base_presenter.rb', line 25

def self.presents(name)
  define_method(name) do
    @object
  end
end