Class: Ore::DocumentFile

Inherits:
Object
  • Object
show all
Defined in:
lib/ore/document_file.rb

Overview

Parses the contents of a .document.

Constant Summary collapse

@@file =
'.document'

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(path) ⇒ DocumentFile

Creates a new Ore::DocumentFile.

Parameters:

  • path (String)

    The path of the .document file.



24
25
26
27
28
29
30
31
# 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

Instance Attribute Details

#extra_file_globsObject (readonly)

The glob-patterns to find all extra-files.



16
17
18
# File 'lib/ore/document_file.rb', line 16

def extra_file_globs
  @extra_file_globs
end

#file_globsObject (readonly)

The glob-patterns to find all code-files.



13
14
15
# File 'lib/ore/document_file.rb', line 13

def file_globs
  @file_globs
end

#pathObject (readonly)

The path to the .document file.



10
11
12
# File 'lib/ore/document_file.rb', line 10

def path
  @path
end

Class Method Details

.find(project) ⇒ DocumentFile?

Finds the document file in a project.

Parameters:

  • project (Project)

    The project to search within.

Returns:



44
45
46
# File 'lib/ore/document_file.rb', line 44

def self.find(project)
  self.new(project.path(@@file)) if project.file?(@@file)
end

Instance Method Details

#each_extra_file {|path| ... } ⇒ Enumerator

All extra-files described in the .document file.

Yields:

  • (path)

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

Yield Parameters:

  • path (String)

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

Returns:

  • (Enumerator)

    If no block was given, an enumerator object will be returned.



82
83
84
85
86
87
88
# 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 {|path| ... } ⇒ Enumerator

All files described in the .document file.

Yields:

  • (path)

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

Yield Parameters:

  • path (String)

    A match that matches the .document file patterns.

Returns:

  • (Enumerator)

    If no block was given, an enumerator object will be returned.



61
62
63
64
65
66
67
# 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

#parse!Object (protected)

Parses the contents of a .document file.



95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
# 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