Class: ViewModels::ContextExtractor

Inherits:
Object
  • Object
show all
Defined in:
lib/view_models/context_extractor.rb

Overview

Extracts controllers for a living from unsuspecting views.

Instance Attribute Summary (collapse)

Instance Method Summary (collapse)

Constructor Details

- (ContextExtractor) initialize(context)

Initialize the Context extractor

Parameters:

  • context (ActionController, ActionMailer, ActionView)

    Some render context



16
17
18
# File 'lib/view_models/context_extractor.rb', line 16

def initialize context
  @context = context
end

Instance Attribute Details

- (Object) context (readonly)

The context



11
12
13
# File 'lib/view_models/context_extractor.rb', line 11

def context
  @context
end

Instance Method Details

- (ActionController) extract

Extracts a controller from the context.

Returns:

  • (ActionController)

    an instance of action controller



23
24
25
26
# File 'lib/view_models/context_extractor.rb', line 23

def extract
  context = self.context
  context.respond_to?(:controller) ? context.send(:controller) : context
end