Class: Dokkit::Environment::Helper::FileSelection

Inherits:
Object
  • Object
show all
Defined in:
lib/dokkit/environment/helpers/fileselection.rb

Overview

FileSelection encapsulates the behaviour of Rake::FileList class. Objects of class FileSelection are capable to return the list of file in a directory. Objects are initialized with a base directory. File list can be refined with FileSelection#include and FileSelection#exclude instance methods.

Direct Known Subclasses

ExtMap

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(base_dir = '.') {|_self| ... } ⇒ FileSelection

Initialize a FileSelection object.

base_dir

the base dir for all inclusion/exclusion operations.

Yields:

  • (_self)

Yield Parameters:



28
29
30
31
32
33
# File 'lib/dokkit/environment/helpers/fileselection.rb', line 28

def initialize(base_dir = '.')
  @base_dir = base_dir
  @includes = []
  @excludes = []
  yield self if block_given?
end

Instance Attribute Details

#base_dirObject (readonly) Also known as: dir

Returns the value of attribute base_dir.



23
24
25
# File 'lib/dokkit/environment/helpers/fileselection.rb', line 23

def base_dir
  @base_dir
end

#excludesObject (readonly)

Returns the value of attribute excludes.



23
24
25
# File 'lib/dokkit/environment/helpers/fileselection.rb', line 23

def excludes
  @excludes
end

#includesObject (readonly)

Returns the value of attribute includes.



23
24
25
# File 'lib/dokkit/environment/helpers/fileselection.rb', line 23

def includes
  @includes
end

Instance Method Details

#exclude(*patterns) ⇒ Object

Exclude files from the list.

patterns

array of glob patterns



45
46
47
48
49
# File 'lib/dokkit/environment/helpers/fileselection.rb', line 45

def exclude(*patterns)
  @excludes.clear
  patterns.each { |pattern| @excludes << pattern }
  self
end

#filesObject

Return an array containing the file list.



52
53
54
55
56
57
58
59
# File 'lib/dokkit/environment/helpers/fileselection.rb', line 52

def files
  if File.exists?(@base_dir)  
    FileList.new(@base_dir) do |fl|
      fl.exclude *@excludes.collect { |exclude| File.join(@base_dir, exclude) } unless @excludes.empty?
      fl.include *@includes.collect { |include| File.join(@base_dir, include) } unless @includes.empty?
    end.uniq.select { |fn| not File.directory?(fn) }
  end
end

#include(*patterns) ⇒ Object

Include files to the list.

patterns

array of glob patterns



37
38
39
40
41
# File 'lib/dokkit/environment/helpers/fileselection.rb', line 37

def include(*patterns)
  @includes.clear
  patterns.each { |pattern| @includes << pattern }
  self
end