Module: Oprah::ControllerHelpers

Extended by:
ActiveSupport::Concern
Defined in:
lib/oprah/controller_helpers.rb

Overview

Helpers that will be mixed into ‘ActionController::Base` and `ActionMailer::Base` by the Railtie.

Since:

  • 0.0.1

Defined Under Namespace

Classes: ViewContextProxy

Instance Method Summary collapse

Instance Method Details

#oprah_view_contextActionView::Base

The view context automatically passed to objects presented from this controller.

You can override this method pass a custom view context to all presented objects from the controller scope.

Returns:

  • (ActionView::Base)

See Also:

Since:

  • 0.0.1



71
72
73
# File 'lib/oprah/controller_helpers.rb', line 71

def oprah_view_context
  @oprah_view_context || view_context
end

#oprah_view_context=(view_context) ⇒ ActionView::Base

Assigns the view context returned from #oprah_view_context.

You can override this method pass a custom view context to all presented objects from the controller scope.

Parameters:

  • view_context (ActionView::Base)

    The view context to assign

Returns:

  • (ActionView::Base)

See Also:

Since:

  • 0.1.3



84
85
86
# File 'lib/oprah/controller_helpers.rb', line 84

def oprah_view_context=(view_context)
  @oprah_view_context = view_context
end

#present(*args, **kwargs, &block) ⇒ Object

Presents a single object.

Will pass the view context returned from #oprah_view_context to the presenter by default. This can be overridden.

See Also:

Since:

  • 0.0.1



41
42
43
44
45
46
47
# File 'lib/oprah/controller_helpers.rb', line 41

def present(*args, **kwargs, &block)
  kwargs = {
    view_context: oprah_view_context_proxy
  }.merge(kwargs)

  Presenter.present(*args, **kwargs, &block)
end

#present_many(*args, **kwargs, &block) ⇒ Object

Presents a collection of objects.

Will pass the view context returned from #oprah_view_context to the presenter by default. This can be overridden.

See Also:

Since:

  • 0.0.1



55
56
57
58
59
60
61
# File 'lib/oprah/controller_helpers.rb', line 55

def present_many(*args, **kwargs, &block)
  kwargs = {
    view_context: oprah_view_context_proxy
  }.merge(kwargs)

  Presenter.present_many(*args, **kwargs, &block)
end

#view_contextActionView::Base

Returns an instance of a view class and sets the current view context returned by #oprah_view_context.

If you override this method in your controller ensure you keep Oprah’s view context updated using #oprah_view_context=.

Returns:

  • (ActionView::Base)

See Also:

Since:

  • 0.1.3



98
99
100
# File 'lib/oprah/controller_helpers.rb', line 98

def view_context
  self.oprah_view_context = super
end