class Wallaby::View::CustomLookupContext

Custom lookup context to cache lookup results.

Public Class Methods

convert(lookup_context, details: nil, prefixes: nil) click to toggle source

Convert an ActionView::LookupContext instance into {CustomLookupContext} @param lookup_context [ActionView::LookupContext] @param details [Hash] @param prefixes [Array<String>] @return [CustomLookupContext]

# 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

Public Instance Methods

find(path, prefixes, partial, *args) click to toggle source

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

{#cached_lookup} is used to cache the lookup result throughout a request. @param path [String, Symbol] @param prefixes [Array<String>] @param partial [true, false] @param args [Array] the rest of the arguments @return [ActionView::Template]

# 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
Also aliased as: original_find, find_template
find_template(path, prefixes, partial, *args)

@!method find_template(path, prefixes, partial, *args) This is an alias method of {#find} (see find)

Alias for: find
original_find(path, prefixes, partial, *args)

@!method original_find(path, prefixes, partial, *args) Original find method. @param path [String, Symbol] @param prefixes [Array<String>] @param partial [true, false] @param args [Array] the rest of the arguments @return [ActionView::Template]

Alias for: find

Protected Instance Methods

cached_lookup() click to toggle source

@!attribute [r] cached_lookup This is a lookup cache for method {#find} @return [Hash] prefix options

# File lib/wallaby/view/custom_lookup_context.rb, line 54
def cached_lookup
  @cached_lookup ||= {}
end