Class: Batali::Source::Path
- Inherits:
-
Batali::Source
- Object
- Grimoire::Utility
- Utility
- Batali::Source
- Batali::Source::Path
- Includes:
- Bogo::Memoization
- Defined in:
- lib/batali/source/path.rb
Overview
Path based source
Direct Known Subclasses
Constant Summary collapse
- DEFAULT_IGNORE =
Returns default ignore globs.
['.git*']
- IGNORE_FILE =
Returns valid ignore file names.
['chefignore', '.chefignore']
Instance Attribute Summary
Attributes inherited from Batali::Source
Instance Method Summary collapse
-
#asset ⇒ String
Directory containing contents.
Methods inherited from Batali::Source
#==, build, #clean_asset, #diff, #initialize, #unit_dependencies, #unit_version
Constructor Details
This class inherits a constructor from Batali::Source
Instance Method Details
#asset ⇒ String
Returns directory containing contents.
21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 |
# File 'lib/batali/source/path.rb', line 21 def asset memoize(:asset) do dir = Dir.mktmpdir chefignore = IGNORE_FILE.map do |c_name| c_path = File.join(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}/", '') relative_path unless chefignore.detect{|ig| File.fnmatch(ig, relative_path)} end.compact files_to_copy.each do |relative_path| new_path = File.join(dir, relative_path) FileUtils.mkdir_p(File.dirname(new_path)) FileUtils.cp(File.join(path, relative_path), new_path) end dir end end |