class Mamiya::Steps::Switch

Public Instance Methods

given_script()

This class see target_dir's script

Alias for: script
release() click to toggle source
# File lib/mamiya/steps/switch.rb, line 44
def release
  # TODO: link with relative if available?
  # TODO: Restore this if FAILED

  Mamiya.chdir(target) do
    logger.info "Releasing..."

    script.release(labels)[@exception]
  end
end
run!() click to toggle source
# File lib/mamiya/steps/switch.rb, line 7
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
script() click to toggle source

XXX: modulize?

# File lib/mamiya/steps/switch.rb, line 61
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
Also aliased as: given_script
switch() click to toggle source
# File lib/mamiya/steps/switch.rb, line 34
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)
  File.rename(next_path, script.current_path)
end

Private Instance Methods

current_targets_release?() click to toggle source
# File lib/mamiya/steps/switch.rb, line 72
def current_targets_release?
  script.current_path.exist? && script.current_path.realpath == target.realpath
end
do_release?() click to toggle source
# File lib/mamiya/steps/switch.rb, line 76
def do_release?
  force_release? ? true : !no_release?
end
force_release?() click to toggle source
# File lib/mamiya/steps/switch.rb, line 80
def force_release?
  !!options[:do_release]
end
labels() click to toggle source
# File lib/mamiya/steps/switch.rb, line 96
def labels
  # XXX: TODO: is it sure that passing labels via options of step?
  options[:labels]
end
no_release?() click to toggle source
# File lib/mamiya/steps/switch.rb, line 84
def no_release?
  !!options[:no_release]
end
target() click to toggle source
# File lib/mamiya/steps/switch.rb, line 88
def target
  @target ||= Pathname.new(options[:target]).realpath
end
target_meta() click to toggle source
# File lib/mamiya/steps/switch.rb, line 92
def target_meta
  @target_meta ||= JSON.parse target.join('.mamiya.meta.json').read
end