Class: ActionView::UnboundTemplate
Relationships & Source Files | |
Inherits: | Object |
Defined in: | actionview/lib/action_view/unbound_template.rb |
Class Method Summary
Instance Attribute Summary
Instance Method Summary
- #bind_locals(locals)
- #build_template(locals) private
- #normalize_locals(locals) private
- #built_templates Internal use only
Constructor Details
.new(source, identifier, details:, virtual_path:) ⇒ UnboundTemplate
# File 'actionview/lib/action_view/unbound_template.rb', line 10
def initialize(source, identifier, details:, virtual_path:) @source = source @identifier = identifier @details = details @virtual_path = virtual_path @templates = Concurrent::Map.new(initial_capacity: 2) @write_lock = Mutex.new end
Instance Attribute Details
#details (readonly)
[ GitHub ]# File 'actionview/lib/action_view/unbound_template.rb', line 7
attr_reader :virtual_path, :details
#format (readonly)
[ GitHub ]#handler (readonly)
[ GitHub ]#locale (readonly)
[ GitHub ]#variant (readonly)
[ GitHub ]#virtual_path (readonly)
[ GitHub ]# File 'actionview/lib/action_view/unbound_template.rb', line 7
attr_reader :virtual_path, :details
Instance Method Details
#bind_locals(locals)
[ GitHub ]# File 'actionview/lib/action_view/unbound_template.rb', line 20
def bind_locals(locals) unless template = @templates[locals] @write_lock.synchronize do normalized_locals = normalize_locals(locals) # We need ||=, both to dedup on the normalized locals and to check # while holding the lock. template = (@templates[normalized_locals] ||= build_template(normalized_locals)) if template.strict_locals? # Under strict locals, we only need one template. # This replaces the @templates Concurrent::Map with a hash which # returns this template for every key. @templates = Hash.new(template).freeze else # This may have already been assigned, but we've already de-dup'd so # reassignment is fine. @templates[locals.dup] = template end end end template end
#build_template(locals) (private)
[ GitHub ]#built_templates
This method is for internal use only.
[ GitHub ]
# File 'actionview/lib/action_view/unbound_template.rb', line 44
def built_templates # :nodoc: @templates.values end
#normalize_locals(locals) (private)
[ GitHub ]# File 'actionview/lib/action_view/unbound_template.rb', line 63
def normalize_locals(locals) locals.map(&:to_sym).sort!.freeze end