class Wallaby::View::CustomLookupContext
Custom lookup context to cache lookup results.
Public Class Methods
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
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
@!method find_template
(path, prefixes, partial, *args) This is an alias method of {#find} (see find
)
@!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]
Protected Instance Methods
@!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