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"]
Constants inherited from Utility
Instance Attribute Summary
Attributes inherited from Batali::Source
Instance Method Summary collapse
-
#asset ⇒ String
Directory containing contents.
-
#initialize(*_, &block) ⇒ Path
constructor
A new instance of Path.
Methods inherited from Batali::Source
#==, build, #clean_asset, #diff, #unit_dependencies, #unit_version
Methods inherited from Utility
Constructor Details
#initialize(*_, &block) ⇒ Path
Returns a new instance of Path.
20 21 22 23 |
# File 'lib/batali/source/path.rb', line 20 def initialize(*_, &block) super self.path = Utility.clean_path(path) end |
Instance Method Details
#asset ⇒ String
Returns directory containing contents.
26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 |
# 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 |