Class: HR_Deploy::Deployer

Inherits:
Object
  • Object
show all
Defined in:
lib/hr_deploy/deployer.rb

Instance Method Summary collapse

Constructor Details

#initializeDeployer



22
23
24
25
26
27
28
29
# File 'lib/hr_deploy/deployer.rb', line 22

def initialize
  @target = nil
  @confirm = nil
  @dry_run = nil
  @start_time = nil
  @tasks_to_run = []
  @finished_tasks = []
end

Instance Method Details

#command_available?(cmd) ⇒ Boolean



122
123
124
125
126
127
128
129
130
131
# File 'lib/hr_deploy/deployer.rb', line 122

def command_available?(cmd)
  exts = ENV['PATHEXT'] ? ENV['PATHEXT'].split(';') : ['']
  ENV['PATH'].split(File::PATH_SEPARATOR).each do |path|
    exts.each do |ext|
      exe = File.join(path, "#{cmd}#{ext}")
      return true if File.executable? exe
    end
  end
  false
end

#deploy(target_name, confirm, dry_run, db_change) ⇒ Object



31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
# File 'lib/hr_deploy/deployer.rb', line 31

def deploy(target_name, confirm, dry_run, db_change)

  self.confirm = confirm
  self.dry_run = dry_run
  self.db_change = db_change

  unless HR_Deploy::ConfigHandler.config_exists?
    puts "No deployment config is present. Run 'hr_deploy generate' to generate a config example"
    exit 1
  end

  config_handler = HR_Deploy::ConfigHandler.new

  # This will set up targets or error in 'config_handler'
  config_handler.attempt_to_load_targets

  if config_handler.error
    puts config_handler.error
    exit 1

  else
    if target_name == nil

      # Deploy to default target
      default_targets = config_handler.targets.find_all { |target| target.default? }
      if default_targets.count == 0

        puts 'No default target specified. Edit config to specify one'
        exit 1
      elsif default_targets.count > 1

        puts 'Multiple default targets specified. Edit config to specify only one'
        exit 1
      else

        self.target = default_targets.first
        deploy_to_target
      end
    else

      target = config_handler.targets.find { |target| target.name == target_name }
      if target
        self.target = target
        deploy_to_target
      else
        puts "No such target: #{target_name}"
        exit 1
      end
    end
  end
end