Class: Wallaby::View::CustomLookupContext

Inherits:
ActionView::LookupContext
  • Object
show all
Defined in:
lib/wallaby/view/custom_lookup_context.rb

Overview

Custom lookup context to cache lookup results.

Class Method Summary collapse

Instance Method Summary collapse

Class Method Details

.convert(lookup_context, details: nil, prefixes: nil) ⇒ CustomLookupContext

Convert an ActionView::LookupContext instance into Wallaby::View::CustomLookupContext

Parameters:

  • lookup_context (ActionView::LookupContext)
  • details (Hash) (defaults to: nil)
  • prefixes (Array<String>) (defaults to: nil)

Returns:



12
13
14
15
16
17
18
19
20
# File 'lib/wallaby/view/custom_lookup_context.rb', line 12

def self.convert(lookup_context, details: nil, prefixes: nil)
  return lookup_context if lookup_context.is_a? self

  new(
    lookup_context.view_paths,
    details || lookup_context.instance_variable_get('@details'),
    prefixes || lookup_context.prefixes
  )
end

Instance Method Details

#find(path, prefixes, partial, *args) ⇒ ActionView::Template Also known as: find_template

This is to resolve the performance bottleneck for template/partial lookup.

#cached_lookup is used to cache the lookup result throughout a request.

Parameters:

  • path (String, Symbol)
  • prefixes (Array<String>)
  • partial (true, false)
  • args (Array)

    the rest of the arguments

Returns:

  • (ActionView::Template)


39
40
41
42
# File 'lib/wallaby/view/custom_lookup_context.rb', line 39

def find(path, prefixes, partial, *args)
  key = [path, prefixes, partial].join(EQUAL)
  cached_lookup[key] ||= original_find(path, prefixes, partial, *args)
end

#original_find(path, prefixes, partial, *args) ⇒ ActionView::Template

Original find method.

Parameters:

  • path (String, Symbol)
  • prefixes (Array<String>)
  • partial (true, false)
  • args (Array)

    the rest of the arguments

Returns:

  • (ActionView::Template)


29
# File 'lib/wallaby/view/custom_lookup_context.rb', line 29

alias original_find find