123456789_123456789_123456789_123456789_123456789_

Module: ActionView::AbstractRenderer::ObjectRendering

Do not use. This module is for internal use only.
Relationships & Source Files
Defined in: actionview/lib/action_view/renderer/abstract_renderer.rb

Constant Summary

Instance Method Summary

Instance Method Details

#initialize(lookup_context, options)

[ GitHub ]

  
# File 'actionview/lib/action_view/renderer/abstract_renderer.rb', line 37

def initialize(lookup_context, options)
  super
  @context_prefix = lookup_context.prefixes.first
end

#local_variable(path) (private)

[ GitHub ]

  
# File 'actionview/lib/action_view/renderer/abstract_renderer.rb', line 43

def local_variable(path)
  if as = @options[:as]
    raise_invalid_option_as(as) unless /\A[a-z_]\w*\z/.match?(as.to_s)
    as.to_sym
  else
    base = path.end_with?("/") ? "" : File.basename(path)
    raise_invalid_identifier(path) unless base =~ /\A_?(.*?)(?:\.\w+)*\z/
    $1.to_sym
  end
end

#merge_prefix_into_object_path(prefix, object_path) (private)

[ GitHub ]

  
# File 'actionview/lib/action_view/renderer/abstract_renderer.rb', line 92

def merge_prefix_into_object_path(prefix, object_path)
  if prefix.include?(?/) && object_path.include?(?/)
    prefixes = []
    prefix_array = File.dirname(prefix).split("/")
    object_path_array = object_path.split("/")[0..-3] # skip model dir & partial

    prefix_array.each_with_index do |dir, index|
      break if dir == object_path_array[index]
      prefixes << dir
    end

    (prefixes << object_path).join("/")
  else
    object_path
  end
end

#partial_path(object, view) (private)

Obtains the path to where the object’s partial is located. If the object responds to to_partial_path, then to_partial_path will be called and will provide the path. If the object does not respond to to_partial_path, then an ArgumentError is raised.

If prefix_partial_path_with_controller_namespace is true, then this method will prefix the partial paths with a namespace.

[ GitHub ]

  
# File 'actionview/lib/action_view/renderer/abstract_renderer.rb', line 76

def partial_path(object, view)
  object = object.to_model if object.respond_to?(:to_model)

  path = if object.respond_to?(:to_partial_path)
    object.to_partial_path
  else
    raise ArgumentError.new("'#{object.inspect}' is not an ActiveModel-compatible object. It must implement :to_partial_path.")
  end

  if view.prefix_partial_path_with_controller_namespace
    PREFIXED_PARTIAL_NAMES[@context_prefix][path] ||= merge_prefix_into_object_path(@context_prefix, path.dup)
  else
    path
  end
end

#raise_invalid_identifier(path) (private)

Raises:

  • (ArgumentError)
[ GitHub ]

  
# File 'actionview/lib/action_view/renderer/abstract_renderer.rb', line 61

def raise_invalid_identifier(path)
  raise ArgumentError, IDENTIFIER_ERROR_MESSAGE % path
end

#raise_invalid_option_as(as) (private)

Raises:

  • (ArgumentError)
[ GitHub ]

  
# File 'actionview/lib/action_view/renderer/abstract_renderer.rb', line 65

def raise_invalid_option_as(as)
  raise ArgumentError, OPTION_AS_ERROR_MESSAGE % as
end