Class: Roger::Release::Cleaner
- Inherits:
-
Object
- Object
- Roger::Release::Cleaner
- Defined in:
- lib/roger/release/cleaner.rb
Overview
The cleaner safely cleans up paths
Instance Method Summary collapse
-
#call(release, _options = {}) ⇒ Object
We switch to the build path and append the globbed files for safety, so even if you manage to sneak in a pattern like “/*/” it won’t do you any good as it will be reappended to the path.
- #clean_path(release, file) ⇒ Object
-
#initialize(pattern) ⇒ Cleaner
constructor
A new instance of Cleaner.
Constructor Details
#initialize(pattern) ⇒ Cleaner
Returns a new instance of Cleaner.
4 5 6 |
# File 'lib/roger/release/cleaner.rb', line 4 def initialize(pattern) @pattern = [pattern].flatten end |
Instance Method Details
#call(release, _options = {}) ⇒ Object
We switch to the build path and append the globbed files for safety, so even if you manage to sneak in a pattern like “/*/” it won’t do you any good as it will be reappended to the path
11 12 13 14 15 16 17 18 19 |
# File 'lib/roger/release/cleaner.rb', line 11 def call(release, = {}) Dir.chdir(release.build_path.to_s) do @pattern.each do |pattern| Dir.glob(pattern).each do |file| clean_path(release, file) end end end end |
#clean_path(release, file) ⇒ Object
21 22 23 24 25 26 27 28 29 30 31 |
# File 'lib/roger/release/cleaner.rb', line 21 def clean_path(release, file) path = File.join(release.build_path.to_s, file) if inside_build_path?(release.build_path, path) release.log(self, "Cleaning up \"#{path}\" in build") rm_rf(path) true else release.log(self, "FAILED cleaning up \"#{path}\" in build") false end end |