Class: Ore::DocumentFile
- Inherits:
-
Object
- Object
- Ore::DocumentFile
- Defined in:
- lib/ore/document_file.rb
Overview
Parses the contents of a .document
.
Constant Summary collapse
- @@file =
'.document'
Instance Attribute Summary collapse
-
#extra_file_globs ⇒ Object
readonly
The glob-patterns to find all extra-files.
-
#file_globs ⇒ Object
readonly
The glob-patterns to find all code-files.
-
#path ⇒ Object
readonly
The path to the
.document
file.
Class Method Summary collapse
-
.find(project) ⇒ DocumentFile?
Finds the document file in a project.
Instance Method Summary collapse
-
#each_extra_file {|path| ... } ⇒ Enumerator
All extra-files described in the
.document
file. -
#each_file {|path| ... } ⇒ Enumerator
All files described in the
.document
file. -
#initialize(path) ⇒ DocumentFile
constructor
Creates a new DocumentFile.
-
#parse! ⇒ Object
protected
Parses the contents of a
.document
file.
Constructor Details
#initialize(path) ⇒ DocumentFile
Creates a new Ore::DocumentFile.
24 25 26 27 28 29 30 31 |
# File 'lib/ore/document_file.rb', line 24 def initialize(path) @path = File.(path) @file_globs = Set[] @extra_file_globs = Set[] parse! end |
Instance Attribute Details
#extra_file_globs ⇒ Object (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_globs ⇒ Object (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 |
#path ⇒ Object (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.
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.
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.
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 |