Class: SmartBox::Modes::CopyMode

Inherits:
Object
  • Object
show all
Defined in:
lib/smart_box/modes/copy_mode.rb

Overview

copy mode: copies the source project into an isolated workspace directory, then initializes a git repo inside the workspace for checkpoint support.

Constant Summary collapse

COPY_EXCLUDES =

Directories and files to exclude when copying the source project

%w[
  .git
  .smart_box
  node_modules
  vendor/bundle
  .bundle
  tmp
  log
].freeze
EXCLUDE_DIRS =
%w[
  .git
  .smart_box
  node_modules
  tmp
  log
].freeze

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(source_path:, workspace_path:) ⇒ CopyMode

Returns a new instance of CopyMode.



32
33
34
35
# File 'lib/smart_box/modes/copy_mode.rb', line 32

def initialize(source_path:, workspace_path:)
  @source_path    = File.expand_path(source_path)
  @workspace_path = File.expand_path(workspace_path)
end

Instance Attribute Details

#source_pathObject (readonly)

Returns the value of attribute source_path.



30
31
32
# File 'lib/smart_box/modes/copy_mode.rb', line 30

def source_path
  @source_path
end

#workspace_pathObject (readonly)

Returns the value of attribute workspace_path.



30
31
32
# File 'lib/smart_box/modes/copy_mode.rb', line 30

def workspace_path
  @workspace_path
end

Instance Method Details

#setupObject

— entry point —



39
40
41
42
43
44
# File 'lib/smart_box/modes/copy_mode.rb', line 39

def setup
  validate_source!
  create_workspace!
  copy_source!
  init_git!
end

#teardownObject



46
47
48
# File 'lib/smart_box/modes/copy_mode.rb', line 46

def teardown
  FileUtils.rm_rf(@workspace_path) if Dir.exist?(@workspace_path)
end