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 =
[FileSystemResolver.new(""), FileSystemResolver.new("/")]

Instance Attribute Summary

Attributes included from ViewPaths

#view_paths

Class Method Summary collapse

Instance Method Summary collapse

Methods included from ViewPaths

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

Methods included from Details

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

Constructor Details

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

Returns a new instance of LookupContext.



61
62
63
64
65
66
67
68
69
# File 'lib/action_view/lookup_context.rb', line 61

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

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

Class Method Details

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



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

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