Class: Nucleus::ApplicationRepoSanitizer

Inherits:
Object
  • Object
show all
Includes:
Logging
Defined in:
lib/nucleus/core/common/files/application_repo_sanitizer.rb

Instance Method Summary collapse

Methods included from Logging

configure_logger_for, #log, logger_for

Constructor Details

#initialize(exclude_git = true) ⇒ ApplicationRepoSanitizer

Create a new instance of the object.

Parameters:

  • exclude_git (Boolean) (defaults to: true)

    if true the ‘.git’ directory won’t be moved up, but will be ignored.



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
...

Parameters:

  • repository_dir (String)

    path to the git repository that is going to be sanitized



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