Class: Terraspace::Cloud::Upload::Tidy
- Inherits:
-
Base
- Object
- Terraspace::CLI::Base
- Base
- Base
- Terraspace::Cloud::Upload::Tidy
- Defined in:
- lib/terraspace/cloud/upload/tidy.rb
Instance Method Summary collapse
-
#always_removals ⇒ Object
These directories will be removed regardless of dir level.
- #cleanup ⇒ Object
- #get_removals(file) ⇒ Object
- #removals ⇒ Object
- #rm_rf(path) ⇒ Object
-
#tskeep ⇒ Object
We clean out ignored files pretty aggressively.
Methods inherited from Base
#artifacts_path, #initialize, #zip_path
Methods inherited from Base
#cancelled?, #changes?, #clean_cache2_stage, #cloud_upload, #initialize, #record?, #sh, #stage_attrs, #success_status
Methods included from Util::Pretty
Methods included from Util::Sure
Methods included from Util::Logging
Methods included from Context
Methods included from Api::Validate
Methods included from Api::Concern
#api, #cloud_stack_name, #expander, #region
Methods included from Api::Concern::Errors
Methods inherited from Terraspace::CLI::Base
Constructor Details
This class inherits a constructor from Terraspace::Cloud::Upload::Base
Instance Method Details
#always_removals ⇒ Object
These directories will be removed regardless of dir level
50 51 52 |
# File 'lib/terraspace/cloud/upload/tidy.rb', line 50 def always_removals %w[.git spec tmp] end |
#cleanup ⇒ Object
3 4 5 6 7 8 9 |
# File 'lib/terraspace/cloud/upload/tidy.rb', line 3 def cleanup removals.each do |removal| removal = removal.sub(%r{^/},'') # remove leading slash path = "#{artifacts_path}/#{removal}" rm_rf(path) end end |
#get_removals(file) ⇒ Object
22 23 24 25 26 27 28 |
# File 'lib/terraspace/cloud/upload/tidy.rb', line 22 def get_removals(file) path = file return [] unless File.exist?(path) removal = File.read(path).split("\n") removal.map {|i| i.strip}.reject {|i| i =~ /^#/ || i.empty?} end |
#removals ⇒ Object
11 12 13 14 15 16 17 18 19 20 |
# File 'lib/terraspace/cloud/upload/tidy.rb', line 11 def removals removals = always_removals removals += get_removals("#{artifacts_path}/.gitignore") removals = removals.reject do |p| tskeep.find do |keep| p.include?(keep) end end removals.uniq end |
#rm_rf(path) ⇒ Object
42 43 44 45 46 47 |
# File 'lib/terraspace/cloud/upload/tidy.rb', line 42 def rm_rf(path) exists = File.exist?("#{path}/.gitkeep") || File.exist?("#{path}/.keep") return if exists FileUtils.rm_rf(path) end |
#tskeep ⇒ Object
We clean out ignored files pretty aggressively. So provide a way for users to keep files from being cleaned out.
32 33 34 35 36 37 38 39 40 |
# File 'lib/terraspace/cloud/upload/tidy.rb', line 32 def tskeep always_keep = %w[] path = "#{artifacts_path}/.tskeep" return always_keep unless File.exist?(path) keep = IO.readlines(path) keep = keep.map {|i| i.strip}.reject { |i| i =~ /^#/ || i.empty? } (always_keep + keep).uniq end |