Class: ActionView::LookupContext
| Relationships & Source Files | |
| Namespace Children | |
|
Modules:
| |
|
Classes:
| |
| Super Chains via Extension / Inclusion / Inheritance | |
|
Instance Chain:
|
|
| Inherits: | Object |
| Defined in: | actionview/lib/action_view/lookup_context.rb |
Overview
LookupContext is the object responsible for holding all information
required for looking up templates, i.e. view paths and details.
LookupContext is also responsible for generating a key, given to
view paths, used in the resolver cache lookup. Since this key is generated
only once during the request, it speeds up all cache accesses.
Class Method Summary
Instance Attribute Summary
- #default_procs readonly
-
#formats=(values)
writeonly
Override formats= to expand ["/"] values and automatically add
:htmlas fallback to:js. -
#locale
rw
Override locale to return a symbol instead of array.
-
#locale=(value)
rw
Overload locale= to also set the
I18n.locale. - #prefixes rw
- #registered_details readonly
ViewPaths - Included
DetailsCache - Included
Instance Method Summary
ViewPaths - Included
| #any_templates?, | |
| #append_view_path | Append a path to the list of view paths for the current |
| #details_for_lookup, | |
| #lookup_context |
|
| #prepend_view_path | Prepend a path to the list of view paths for the current |
| #template_exists?, | |
| #_prefixes | The prefixes used in render "foo" shortcuts. |
DetailsCache - Included
| #disable_cache | Temporary skip passing the details_key forward. |
| #_set_detail, | |
| #details_key | Calculate the details key. |
Constructor Details
.new(view_paths, details = {}, prefixes = []) ⇒ LookupContext
# File 'actionview/lib/action_view/lookup_context.rb', line 247
def initialize(view_paths, details = {}, prefixes = []) @details_key = nil @digest_cache = nil @cache = true @prefixes = prefixes @details = initialize_details({}, details) @view_paths = build_view_paths(view_paths) end
Class Method Details
.register_detail(name, &block)
[ GitHub ]# File 'actionview/lib/action_view/lookup_context.rb', line 22
def self.register_detail(name, &block) block = ActiveSupport::Ractors.shareable_proc(&block) @default_procs = @default_procs.merge(name => block).freeze @registered_details = @default_procs.keys.freeze Accessors.define_method(:"default_#{name}", &block) Accessors.module_eval <<-METHOD, __FILE__, __LINE__ + 1 def #{name} @details[:#{name}] || [] end def #{name}=(value) value = value.present? ? Array(value) : default_#{name} _set_detail(:#{name}, value) if value != @details[:#{name}] end METHOD end
.reset_view_context_class
[ GitHub ]# File 'actionview/lib/action_view/lookup_context.rb', line 98
def self.reset_view_context_class @view_context_mutex.synchronize { @view_context_class = nil } end
.view_context_class
[ GitHub ]# File 'actionview/lib/action_view/lookup_context.rb', line 102
def self.view_context_class return @view_context_class if @view_context_class base = ActionView::Base # prevent recursive locking @view_context_mutex.synchronize do @view_context_class = base.with_empty_template_cache end end
Instance Attribute Details
#default_procs (readonly)
[ GitHub ]# File 'actionview/lib/action_view/lookup_context.rb', line 18
singleton_class.attr_reader :default_procs, :registered_details
#formats=(values) (writeonly)
Override formats= to expand ["/"] values and automatically
add :html as fallback to :js.
# File 'actionview/lib/action_view/lookup_context.rb', line 278
def formats=(values) if values values = values.dup values.concat(default_formats) if values.delete "*/*" values.uniq! Template.validate_formats(values) if (values.length == 1) && (values[0] == :js) values << :html @html_fallback_for_js = true end end super(values) end
#locale (rw)
Override locale to return a symbol instead of array.
# File 'actionview/lib/action_view/lookup_context.rb', line 295
def locale @details[:locale].first end
#locale=(value) (rw)
Overload locale= to also set the I18n.locale. If the current I18n.config object responds
to original_config, it means that it has a copy of the original ::I18n configuration and it's
acting as proxy, which we need to skip.
#prefixes (rw)
[ GitHub ]# File 'actionview/lib/action_view/lookup_context.rb', line 16
attr_accessor :prefixes
#registered_details (readonly)
[ GitHub ]# File 'actionview/lib/action_view/lookup_context.rb', line 18
singleton_class.attr_reader :default_procs, :registered_details
Instance Method Details
#digest_cache
[ GitHub ]# File 'actionview/lib/action_view/lookup_context.rb', line 257
def digest_cache @digest_cache ||= DetailsKey.digest_cache(@details) end
#initialize_details(target, details) (private)
[ GitHub ]# File 'actionview/lib/action_view/lookup_context.rb', line 268
def initialize_details(target, details) LookupContext.registered_details.each do |k| target[k] = details[k] || LookupContext.default_procs[k].call end target end
#with_prepended_formats(formats)
[ GitHub ]# File 'actionview/lib/action_view/lookup_context.rb', line 261
def with_prepended_formats(formats) details = @details.dup details[:formats] = formats self.class.new(@view_paths, details, @prefixes) end