Class: Reflection::Command::Stash

Inherits:
Base
  • Object
show all
Defined in:
lib/reflection/command/stash.rb

Instance Attribute Summary

Attributes inherited from Base

#config

Instance Method Summary collapse

Methods inherited from Base

#initialize, run!, #validate, #verify_that_target_is_not_a_repository

Constructor Details

This class inherits a constructor from Reflection::Command::Base

Instance Method Details

#prepare_stash_repository(stash_directory) ⇒ Object



27
28
29
30
31
32
33
34
35
# File 'lib/reflection/command/stash.rb', line 27

def prepare_stash_repository(stash_directory)
  Reflection.log.debug "Preparing stash repository.."

  if stash_directory.exists?
    stash_directory.validate_repository
  else
    stash_directory.clone_repository
  end
end

#run!Object



13
14
15
16
17
18
19
20
21
22
23
24
25
# File 'lib/reflection/command/stash.rb', line 13

def run!
  Reflection.log.info "Stashing '#{config.directory}'.."

  stash_directory = Directory::Stash.new(Reflection::Repository.new(config.repository), 'stash')
  target_directory = Directory::Base.new(config.directory)

  verify_that_target_is_not_a_repository(target_directory)
  
  prepare_stash_repository(stash_directory)
  stash_directory_into_repository(stash_directory, target_directory)

  Reflection.log.info "Stash Command done."
end

#stash_directory_into_repository(stash_directory, target_directory) ⇒ Object



37
38
39
40
41
42
43
# File 'lib/reflection/command/stash.rb', line 37

def stash_directory_into_repository(stash_directory, target_directory)
  copy_stash_repository_git_index_to_target(stash_directory.git_index, target_directory.path)
  Reflection::Rails.stash(config, target_directory) if config.rails_root
  commit_and_push_files(target_directory.path, target_directory.name)
  move_stash_repository_git_index_back(target_directory.git_index, stash_directory.path)
  Reflection::Rails.clean_target(target_directory) if config.rails_root
end

#validate!Object



5
6
7
8
9
10
11
# File 'lib/reflection/command/stash.rb', line 5

def validate!
  validate.existence_of config.directory
  if config.rails_root
    validate.existence_of config.rails_root
    Reflection::Rails.validate_environment(config)
  end
end