class Batali::Source::Path
Path
based source
Constants
- DEFAULT_IGNORE
@return [Array<String>] default ignore globs
- IGNORE_FILE
@return [Array<String>] valid ignore file names
Public Class Methods
new(*_, &block)
click to toggle source
Calls superclass method
Batali::Source::new
# File lib/batali/source/path.rb, line 20 def initialize(*_, &block) super self.path = Utility.clean_path(path) end
Public Instance Methods
asset()
click to toggle source
@return [String] directory containing contents
# File lib/batali/source/path.rb, line 26 def asset memoize(:asset) do dir = Dir.mktmpdir chefignore = IGNORE_FILE.map do |c_name| c_path = Utility.join_path(path, c_name) c_path if File.exist?(c_path) end.compact.first chefignore = chefignore ? File.readlines(chefignore) : [] chefignore += DEFAULT_IGNORE chefignore.uniq! files_to_copy = Dir.glob(File.join(path, "{.[^.]*,**}", "**", "{*,*.*,.*}")) files_to_copy = files_to_copy.map do |file_path| next unless File.file?(file_path) relative_path = file_path.sub("#{path}#{File::SEPARATOR}", "") relative_path unless chefignore.detect { |ig| File.fnmatch(ig, relative_path) } end.compact files_to_copy.each do |relative_path| new_path = Utility.join_path(dir, relative_path) FileUtils.mkdir_p(File.dirname(new_path)) FileUtils.cp(Utility.join_path(path, relative_path), new_path) end dir end end