Class: Mamiya::Steps::Switch

Inherits:
Abstract show all
Defined in:
lib/mamiya/steps/switch.rb

Instance Attribute Summary

Attributes inherited from Abstract

#config, #logger, #options

Instance Method Summary collapse

Methods inherited from Abstract

#initialize

Constructor Details

This class inherits a constructor from Mamiya::Steps::Abstract

Instance Method Details

#given_scriptObject

This class see target_dir’s script



60
# File 'lib/mamiya/steps/switch.rb', line 60

alias given_script script

#releaseObject



43
44
45
46
47
48
49
50
51
52
53
54
55
# File 'lib/mamiya/steps/switch.rb', line 43

def release
  # TODO: link with relative if available?
  # TODO: Restore this if FAILED

  old_pwd = Dir.pwd
  Dir.chdir(target)

  logger.info "Releasing..."

  script.release(labels)[@exception]
ensure
  Dir.chdir old_pwd if old_pwd
end

#run!Object



6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
# File 'lib/mamiya/steps/switch.rb', line 6

def run!
  @exception = nil
  @switched = false

  if current_targets_release?
    logger.info "Already switched"
  else
    switch
  end

  if @switched ? do_release? : force_release?
    release
  else
    logger.warn "Skipping release"
  end

rescue Exception => e
  @exception = e
  raise e
ensure
  logger.warn "Exception occured, cleaning up..." if @exception

  script.after_switch(labels)[@exception] if @switched

  logger.info "DONE!" unless @exception
end

#scriptObject

XXX: modulize?



63
64
65
66
67
68
69
70
# File 'lib/mamiya/steps/switch.rb', line 63

def script
  @target_script ||= Mamiya::Script.new.load!(
    target.join('.mamiya.script', target_meta['script'])).tap do |script|
    script.set(:deploy_to, config.deploy_to_for(script.application))
    script.set(:release_path, target)
    script.set(:logger, logger)
  end
end

#switchObject



33
34
35
36
37
38
39
40
41
# File 'lib/mamiya/steps/switch.rb', line 33

def switch
  logger.info "Switching to #{target}"
  @switched = true
  script.before_switch(labels)[]

  next_path = script.release_path.parent.join(script.current_path.basename)
  next_path.make_symlink(target.realpath)
  FileUtils.mv(next_path, script.current_path)
end