Class: Nucleus::ApplicationRepoSanitizer
- Inherits:
-
Object
- Object
- Nucleus::ApplicationRepoSanitizer
- Includes:
- Logging
- Defined in:
- lib/nucleus/core/common/files/application_repo_sanitizer.rb
Instance Method Summary collapse
-
#initialize(exclude_git = true) ⇒ ApplicationRepoSanitizer
constructor
Create a new instance of the object.
-
#sanitize(repository_dir) ⇒ Object
Sanitizing the repository_dir will check if the repository has more than one file / directory besides the git DB.
Methods included from Logging
configure_logger_for, #log, logger_for
Constructor Details
#initialize(exclude_git = true) ⇒ ApplicationRepoSanitizer
Create a new instance of the object.
7 8 9 |
# File 'lib/nucleus/core/common/files/application_repo_sanitizer.rb', line 7 def initialize(exclude_git = true) @exclude_git = exclude_git end |
Instance Method Details
#sanitize(repository_dir) ⇒ Object
Sanitizing the repository_dir will check if the repository has more than one file / directory besides the git DB. If there is only one directory, all files in this directory are going to be moved one level up. If there was:
.git
wordfinder
All contents of ‘wordfinder` will be moved one level up, resulting in:
config
lib
public
specs
views
README.md
server.js
...
30 31 32 33 34 35 36 37 38 39 40 41 42 |
# File 'lib/nucleus/core/common/files/application_repo_sanitizer.rb', line 30 def sanitize(repository_dir) # no sanitizing for files return unless File.directory?(repository_dir) repo_entries = sanitized_dir_entries(repository_dir) return unless repo_entries.length == 1 log.debug 'Uploaded application is wrapped in folder, fixing now by moving all contents one level up...' dir = File.join(repository_dir, repo_entries[0]) dir_entries = sanitized_dir_entries(dir).map { |name| File.join(dir, name) } FileUtils.mv(dir_entries, repository_dir) # Now delete the usually empty directory FileUtils.rm_r dir end |