class Object

Constants

Jbuilder

Public Instance Methods

_cache_key(key, options) click to toggle source
# File lib/jbuilder/jbuilder_template.rb, line 150
def _cache_key(key, options)
  name_options = options.slice(:skip_digest, :virtual_path)
  key = _fragment_name_with_digest(key, name_options)

  if @context.respond_to?(:fragment_cache_key)
    key = @context.fragment_cache_key(key)
  else
    key = url_for(key).split('://', 2).last if ::Hash === key
  end

  ::ActiveSupport::Cache.expand_cache_key(key, :jbuilder)
end
_fragment_name_with_digest(key, options) click to toggle source
# File lib/jbuilder/jbuilder_template.rb, line 163
def _fragment_name_with_digest(key, options)
  if @context.respond_to?(:cache_fragment_name)
    # Current compatibility, fragment_name_with_digest is private again and cache_fragment_name
    # should be used instead.
    @context.cache_fragment_name(key, options)
  elsif @context.respond_to?(:fragment_name_with_digest)
    # Backwards compatibility for period of time when fragment_name_with_digest was made public.
    @context.fragment_name_with_digest(key)
  else
    key
  end
end
_is_active_model?(object) click to toggle source
# File lib/jbuilder/jbuilder_template.rb, line 180
def _is_active_model?(object)
  object.class.respond_to?(:model_name) && object.respond_to?(:to_partial_path)
end
_partial_options?(options) click to toggle source
# File lib/jbuilder/jbuilder_template.rb, line 176
def _partial_options?(options)
  ::Hash === options && options.key?(:as) && options.key?(:partial)
end
_render_active_model_partial(object) click to toggle source
# File lib/jbuilder/jbuilder_template.rb, line 218
def _render_active_model_partial(object)
  @context.render object, json: self
end
_render_explicit_partial(name_or_options, locals = {}) click to toggle source
# File lib/jbuilder/jbuilder_template.rb, line 197
def _render_explicit_partial(name_or_options, locals = {})
  case name_or_options
  when ::Hash
    # partial! partial: 'name', foo: 'bar'
    options = name_or_options
  else
    # partial! 'name', locals: {foo: 'bar'}
    if locals.one? && (locals.keys.first == :locals)
      options = locals.merge(partial: name_or_options)
    else
      options = { partial: name_or_options, locals: locals }
    end
    # partial! 'name', foo: 'bar'
    as = locals.delete(:as)
    options[:as] = as if as.present?
    options[:collection] = locals[:collection] if locals.key?(:collection)
  end

  _render_partial_with_options options
end
_set_inline_partial(name, object, options) click to toggle source
# File lib/jbuilder/jbuilder_template.rb, line 184
def _set_inline_partial(name, object, options)
  value = if object.nil?
    []
  elsif _is_collection?(object)
    _scope{ _render_partial_with_options options.merge(collection: object) }
  else
    locals = ::Hash[options[:as], object]
    _scope{ _render_partial_with_options options.merge(locals: locals) }
  end

  set! name, value
end