module Fuse::Document::Asset::HasDependents

Constants

COMMENT_PATTERN
REQUIRE_PATTERN

Public Instance Methods

dependents() click to toggle source
# File lib/fuse/document/asset/has_dependents.rb, line 6
def dependents
  collection = Fuse::Document::AssetCollection.new
  local_root = File.dirname(full_path)
  if (comments = raw[COMMENT_PATTERN])
    comments.lines.each do |line|
      if (match = REQUIRE_PATTERN.match(line))
        case match[1]
          when 'require'
            [File.join(local_root, match[2])]
          when 'require_glob'
            Dir[File.join(local_root, match[2])]
          else
            []
        end.map do |p|
          Fuse::Document::Asset.for(p[@root.length..-1], @root)
        end.reject do |p|
          p.nil?
        end.each do |p|
          collection << p
        end
      end
    end
  end
  collection
end