app/controllers/api/base_controller/renderer.rb
#
# Given a resource, return its serialized flavor using Jbuilder
#
Given a resource, return its serialized flavor using Jbuilder
Given a resource return its serialized flavor using Jbuilder
def collection_to_jbuilder(type, reftype, resources, opts = {})
        link_builder = Api::LinksBuilder.new(params, @req.url, opts[:counts])
        Jbuilder.new do |json|
          json.ignore_nil!
          json.set! 'name', opts[:name] if opts[:name]
          if opts[:counts]
            opts[:counts].counts.each do |count, value|
              json.set! count, value
            end
          end
          json.set! 'pages', link_builder.pages if link_builder.links?
          unless @req.hide?("resources")
            json.resources resources.collect do |resource|
              if opts[:expand_resources]
                add_hash json, resource_to_jbuilder(type, reftype, resource, opts).attributes!
              else
                json.href normalize_href(compress_path(reftype), ApplicationRecord.compress_id(resource["id"]))
              end
            end
          end
          cspec = collection_config[type]
          aspecs = gen_action_spec_for_collections(type, cspec, opts[:is_subcollection], reftype) if cspec
          add_actions(json, aspecs, reftype)
          if link_builder.links?
            json.links do
              link_builder.links.each do |link_name, link_href|
                json.set! link_name, link_href
              end
            end
          end
        end
      end
def collection_to_jbuilder ( type , reftype , resources , opts = { } ) link_builder = Api :: LinksBuilder . new ( params , @req . url , opts [ :counts ] ) Jbuilder . new do | json | json . ignore_nil! json . set! 'name' , opts [ :name ] if opts [ :name ] if opts [ :counts ] opts [ :counts ] . counts . each do | count , value | json . set! count , value end end json . set! 'pages' , link_builder . pages if link_builder . links? unless @req . hide? ( "resources" ) json . resources resources . collect do | resource | if opts [ :expand_resources ] add_hash json , resource_to_jbuilder ( type , reftype , resource , opts ) . attributes! else json . href normalize_href ( compress_path ( reftype ) , ApplicationRecord . compress_id ( resource [ "id" ] ) ) end end end cspec = collection_config [ type ] aspecs = gen_action_spec_for_collections ( type , cspec , opts [ :is_subcollection ] , reftype ) if cspec add_actions ( json , aspecs , reftype ) if link_builder . links? json . links do link_builder . links . each do | link_name , link_href | json . set! link_name , link_href end end end end end
Given a resource, return its serialized flavor using Jbuilder
Given a resource return its serialized flavor using Jbuilder
type
<not_specific>
reftype
<not_specific>
resources
<not_specific>
opts
<not_specific>