class Middleman::Cli::Deploy

This class provides a “deploy” command for the middleman CLI.

Public Class Methods

exit_on_failure?() click to toggle source

Tell Thor to exit with a nonzero exit code on failure

# File lib/middleman-deploy/commands.rb, line 19
def self.exit_on_failure?
  true
end

Public Instance Methods

deploy() click to toggle source
# File lib/middleman-deploy/commands.rb, line 28
def deploy
  build_before(options)
  process
end

Protected Instance Methods

build_before(options = {}) click to toggle source
# File lib/middleman-deploy/commands.rb, line 35
def build_before(options = {})
  build_enabled = options.fetch('build_before', self.deploy_options.build_before)

  if build_enabled
    # http://forum.middlemanapp.com/t/problem-with-the-build-task-in-an-extension
    run('middleman build') || exit(1)
  end
end
deploy_options() click to toggle source
# File lib/middleman-deploy/commands.rb, line 58
def deploy_options
  options = nil

  begin
    options = ::Middleman::Application.server.inst.options
  rescue NoMethodError
    print_usage_and_die 'You need to activate the deploy extension in config.rb.'
  end

  unless options.method
    print_usage_and_die 'The deploy extension requires you to set a method.'
  end

  case options.method
  when :rsync, :sftp
    unless options.host && options.path
      print_usage_and_die "The #{options.method} method requires host and path to be set."
    end
  when :ftp
    unless options.host && options.user && options.password && options.path
      print_usage_and_die 'The ftp deploy method requires host, path, user, and password to be set.'
    end
  end

  options
end
print_usage_and_die(message) click to toggle source
process() click to toggle source
# File lib/middleman-deploy/commands.rb, line 48
def process
  server_instance   = ::Middleman::Application.server.inst

  camelized_method  = self.deploy_options.method.to_s.split('_').map { |word| word.capitalize}.join
  method_class_name = "Middleman::Deploy::Methods::#{camelized_method}"
  method_instance   = method_class_name.constantize.new(server_instance, self.deploy_options)

  method_instance.process
end