sitepress-core/lib/sitepress/resource.rb
# Filters parent/child/sibling resources by a type. The default behavior is to only return
# resources of the same type. For example given the pages `/a.html`, `/a.gif`, `/a/b.html`,
# if you query the parent from page `/a/b.html` you'd only get `/a.html` by default. If you
# query the parents via `parents(type: :all)` you'd get get [`/a.html`, `/a.gif`]
#
# TODO: When `type: :all` is scoped, some queries will mistakenly return single resources.
# :all should return an array of arrays to accurately represention levels.
#
# TODO: Put a better extension/mime_type handler into resource tree, then instead of faltening
# below and select, we could call a single map and pull out a resources
Filters parent/child/sibling resources by a type. The default behavior is to only return
resources of the same type.

When `type: :all` is scoped, some queries will mistakenly return single resources.
:all should return an array of arrays to accurately represention levels.

Put a better extension/mime_type handler into resource tree, then instead of faltening
below and select, we could call a single map and pull out a resources
Filters parent / child / sibling resources by a type . The default behavior is to only return resources of the same type . When ` type : : all ` is scoped some queries will mistakenly return single resources . : all should return an array of arrays to accurately represention levels . Put a better extension / mime_type handler into resource tree then instead of faltening below and select we could call a single map and pull out a resources
def filter_resources(type: DEFAULT_FILTER_SCOPE, &block)
      return [] unless node
      nodes = block.call
      case type
      when :all
        nodes.map{ |node| node.formats }
      when :same
        nodes.map{ |n| n.formats.get(format) }.flatten
      when String, Symbol, NilClass
        nodes.map{ |n| n.formats.get(type) }.flatten
      when MIME::Type
        nodes.map{ |n| n.formats.mime_type(type) }.flatten
      else
        raise ArgumentError, "Invalid type argument #{type}. Must be either :same, :all, an extension string, or a Mime::Type"
      end
    end
def filter_resources ( type : DEFAULT_FILTER_SCOPE , & block ) return [ ] unless node nodes = block . call case type when :all nodes . map { | node | node . formats } when :same nodes . map { | n | n . formats . get ( format ) } . flatten when String , Symbol , NilClass nodes . map { | n | n . formats . get ( type ) } . flatten when MIME :: Type nodes . map { | n | n . formats . mime_type ( type ) } . flatten else raise ArgumentError , "Invalid type argument #{type}. Must be either :same, :all, an extension string, or a Mime::Type" end end
Filters parent/child/sibling resources by a type.
Filters parent / child / sibling resources by a type .
type
<not_specific>
block
<not_specific>