Class: Distil::FileSet

Inherits:
Object
  • Object
show all
Includes:
ErrorReporter, Enumerable
Defined in:
lib/distil/configurable/file-set.rb

Class Method Summary collapse

Instance Method Summary collapse

Methods included from ErrorReporter

#error, error, #ignore_warnings, #ignore_warnings=, #report, warning, #warning

Constructor Details

#initialize(value = [], owner = nil) ⇒ FileSet

Returns a new instance of FileSet.



7
8
9
10
# File 'lib/distil/configurable/file-set.rb', line 7

def initialize(value=[], owner=nil)
  @owner= owner
  @source_set= value
end

Class Method Details

.from_options(set, owner) ⇒ Object



33
34
35
# File 'lib/distil/configurable/file-set.rb', line 33

def self.from_options(set, owner)
  self.new(set, owner)
end

Instance Method Details

#eachObject



80
81
82
# File 'lib/distil/configurable/file-set.rb', line 80

def each
  files.each { |f| yield f }
end

#filesObject



12
13
14
15
16
17
18
19
20
21
22
# File 'lib/distil/configurable/file-set.rb', line 12

def files
  return @files if @files
  @files=[]
  case
    when (@source_set.is_a?(String))
      include_file(@source_set)
    when (@source_set.is_a?(Array))
      @source_set.each { |f| include_file(f) }
  end
  @files
end

#files=(set) ⇒ Object



24
25
26
27
# File 'lib/distil/configurable/file-set.rb', line 24

def files=(set)
  @files= nil
  @source_set= set
end

#include?(file) ⇒ Boolean

Returns:

  • (Boolean)


29
30
31
# File 'lib/distil/configurable/file-set.rb', line 29

def include?(file)
  files.include?(file)
end

#include_file(file) ⇒ Object



37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
# File 'lib/distil/configurable/file-set.rb', line 37

def include_file(file)
  files if !@files
  
  if file.is_a?(SourceFile)
    @files << file if !@files.include?(file)
    return
  end
  
  if @owner
    full_path= File.expand_path(File.join([@owner.source_folder, file].compact))
  else
    full_path= File.expand_path(file)
  end

  if File.directory?(full_path)
    Dir.foreach(full_path) { |f|
        next if f[/^\./]
        include_file(File.join(file, f))
    }
    return
  end

  files= Dir.glob(full_path)
  if (files.length>0)
    files.each { |f|
      source_file= SourceFile.from_path(f)
      next if (@files.include?(source_file))
      @files << source_file
    }
    return
  end

  # file not found by globbing (would also find explicit reference)
  source_file= @owner.find_file(file) if @owner
  if !source_file
    puts "full_path=#{full_path}\nsource_folder=#{@owner.source_folder}"
    error("Unable to locate file: #{file}")
    return
  end
  return if (@files.include?(source_file))
  @files << source_file
end