Class: ActionView::LookupContext

Inherits:
Object
  • Object
show all
Includes:
Accessors, Details, ViewPaths
Defined in:
lib/action_view/lookup_context.rb

Overview

Action View Lookup Context

LookupContext is the object responsible to hold all information required to lookup templates, i.e. view paths and details. The LookupContext is also responsible to generate a key, given to view paths, used in the resolver cache lookup. Since this key is generated just once during the request, it speeds up all cache accesses.

Defined Under Namespace

Modules: Accessors, Details, ViewPaths Classes: DetailsKey

Constant Summary collapse

@@fallbacks =
FallbackFileSystemResolver.instances

Instance Attribute Summary collapse

Attributes included from ViewPaths

#view_paths

Attributes included from Details

#cache

Class Method Summary collapse

Instance Method Summary collapse

Methods included from ViewPaths

#exists?, #find, #find_all, #with_fallbacks

Methods included from Details

#details_key, #disable_cache, #formats=, #freeze_formats, #locale, #locale=, #skip_default_locale!, #update_details, #with_layout_format

Constructor Details

#initialize(view_paths, details = {}, prefixes = []) ⇒ LookupContext

Returns a new instance of LookupContext.



63
64
65
66
67
68
69
70
71
72
73
# File 'lib/action_view/lookup_context.rb', line 63

def initialize(view_paths, details = {}, prefixes = [])
  @details, @details_key = { :handlers => default_handlers }, nil
  @frozen_formats, @skip_default_locale = false, false
  @cache = true
  @prefixes = prefixes

  self.view_paths = view_paths
  self.registered_detail_setters.each do |key, setter|
    send(setter, details[key])
  end
end

Instance Attribute Details

#prefixesObject

:nodoc:



12
13
14
# File 'lib/action_view/lookup_context.rb', line 12

def prefixes
  @prefixes
end

Class Method Details

.register_detail(name, options = {}, &block) ⇒ Object



23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
# File 'lib/action_view/lookup_context.rb', line 23

def self.register_detail(name, options = {}, &block)
  self.registered_details << name
  self.registered_detail_setters << [name, "#{name}="]

  Accessors.send :define_method, :"_#{name}_defaults", &block
  Accessors.module_eval <<-METHOD, __FILE__, __LINE__ + 1
    def #{name}
      @details[:#{name}]
    end

    def #{name}=(value)
      value = Array.wrap(value.presence || _#{name}_defaults)
      _set_detail(:#{name}, value) if value != @details[:#{name}]
    end
  METHOD
end