Class: Reflection::Command::Apply

Inherits:
Reflection::Command::Base show all
Defined in:
lib/reflection/command/apply.rb

Method Summary

Methods inherited from Reflection::Command::Base

#initialize, run!, #validate, #verify_that_target_is_not_a_repository

Constructor Details

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

Method Details

- (Object) run!



15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
# File 'lib/reflection/command/apply.rb', line 15

def run!
  stash_directory = Directory::Stash.new(Reflection::Repository.new(config.repository), 'apply')
  target_directory = Directory::Base.new(config.directory)

  get_user_approval_for_cleaning_target(target_directory)
  get_user_approval_for_apply_database_dump if config.rails_root
  
  verify_that_target_is_not_a_repository(target_directory)

  Reflection.log.info "Applying '#{config.repository}' >> '#{config.directory}'.."

  target_directory.clean!

  if stash_directory.exists?
    stash_directory.validate_repository
    stash_directory.copy_git_index_to(target_directory.path)
    repo = Repository.new_from_path(target_directory.path)
    repo.reset!
    repo.pull
    stash_directory.get_git_index_from(target_directory.path)
  else
    stash_directory.clone_repository
    stash_directory.move_content_to(target_directory.path)
    stash_directory.get_git_index_from(target_directory.path)
  end

  Reflection::Rails.apply(config, target_directory)
  Reflection.log.info "Apply Command done."
end

- (Object) validate!



7
8
9
10
11
12
13
# File 'lib/reflection/command/apply.rb', line 7

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