class Ore::DocumentFile

Parses the contents of a ‘.document`.

Attributes

extra_file_globs[R]

The glob-patterns to find all extra-files.

file_globs[R]

The glob-patterns to find all code-files.

path[R]

The path to the ‘.document` file.

Public Class Methods

find(project) click to toggle source

Finds the document file in a project.

@param [Project] project

The project to search within.

@return [DocumentFile, nil]

The found document file.
# File lib/ore/document_file.rb, line 44
def self.find(project)
  self.new(project.path(@@file)) if project.file?(@@file)
end
new(path) click to toggle source

Creates a new {DocumentFile}.

@param [String] path

The path of the `.document` file.
# File lib/ore/document_file.rb, line 24
def initialize(path)
  @path = File.expand_path(path)

  @file_globs = Set[]
  @extra_file_globs = Set[]

  parse!
end

Public Instance Methods

each_extra_file(&block) click to toggle source

All extra-files described in the ‘.document` file.

@yield [path]

The given block will be passed every path that matches the
extra-file globs in the `.document` file.

@yieldparam [String] path

A match that matches the `.document` extra-file patterns.

@return [Enumerator]

If no block was given, an enumerator object will be returned.
# File lib/ore/document_file.rb, line 82
def each_extra_file(&block)
  return enum_for(:each_extra_file) unless block

  @extra_file_globs.each do |pattern|
    Dir.glob(pattern,&block)
  end
end
each_file(&block) click to toggle source

All files described in the ‘.document` file.

@yield [path]

The given block will be passed every path that matches the file
globs in the `.document` file.

@yieldparam [String] path

A match that matches the `.document` file patterns.

@return [Enumerator]

If no block was given, an enumerator object will be returned.
# File lib/ore/document_file.rb, line 61
def each_file(&block)
  return enum_for(:each_file) unless block

  @file_globs.each do |pattern|
    Dir.glob(pattern,&block)
  end
end

Protected Instance Methods

parse!() click to toggle source

Parses the contents of a ‘.document` file.

# File lib/ore/document_file.rb, line 95
def parse!
  separator = false

  File.open(@path) do |file|
    file.each_line do |line|
      line = line.chomp.strip

      next if line.empty?

      unless separator
        if line == '-'
          separator = true
        else
          @file_globs << line
        end
      else
        @extra_file_globs << line
      end
    end
  end
end