Class: Webbynode::Commands::Push

Inherits:
Webbynode::Command show all
Includes:
Updater
Defined in:
lib/webbynode/commands/push.rb

Constant Summary

Constants inherited from Webbynode::Command

Webbynode::Command::Aliases, Webbynode::Command::CommandError, Webbynode::Command::InvalidCommand, Webbynode::Command::InvalidOption, Webbynode::Command::Settings

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods included from Updater

#check_for_updates

Methods inherited from Webbynode::Command

add_alias, #api, class_for, command, command_class_name, description, for, #gemfile, #git, help, inherited, #io, #no?, #notify, option, #option, #options, options_help, #param, #param_values, parameter, #params, #params_hash, params_help, #pushand, #remote_executor, requires_initialization!, requires_options!, requires_pushed_application!, #run, #server, setting, #settings, summary, summary_help, usage, #validate_initialization, #validate_options, #yes?

Constructor Details

#initialize(*args) ⇒ Push

Returns a new instance of Push.



15
16
17
18
19
# File 'lib/webbynode/commands/push.rb', line 15

def initialize(*args)
  super
  @before_tasks = Webbynode::Commands::Tasks.new
  @after_tasks  = Webbynode::Commands::Tasks.new
end

Instance Attribute Details

#after_tasksObject

Returns the value of attribute after_tasks.



7
8
9
# File 'lib/webbynode/commands/push.rb', line 7

def after_tasks
  @after_tasks
end

#app_nameObject

Returns the value of attribute app_name.



7
8
9
# File 'lib/webbynode/commands/push.rb', line 7

def app_name
  @app_name
end

#before_tasksObject

Returns the value of attribute before_tasks.



7
8
9
# File 'lib/webbynode/commands/push.rb', line 7

def before_tasks
  @before_tasks
end

Instance Method Details

#executeObject



21
22
23
24
25
26
27
28
29
30
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
# File 'lib/webbynode/commands/push.rb', line 21

def execute
  unless option(:dirty)
    raise CommandError, 
      "Cannot push because you have pending changes. Do a git commit or add changes to .gitignore." unless git.clean?
  end
  
  @app_name = pushand.parse_remote_app_name
  
  # Ensures there are Task Files to read from
  before_tasks.ensure_tasks_folder
  
  # Reads out the "before push" tasks file to see if there are any tasks that must be performed
  # It will perform the "before push" tasks if there are any available
  before_tasks.read_tasks(Webbynode::Commands::Tasks::BeforePushTasksFile)
  perform_before_tasks if before_tasks.has_tasks?
  
  handle_semaphore
  
  # Logs a initialization message to the user
  io.log "Pushing #{app_name.color(:cyan)}", :start
  
  # Checks for server-side updates
  if check_for_updates
    io.log "Note: Rapp Engine updated".color(:yellow)
    io.log ""
  end
  
  # Pushes the application to Webbynode
  io.exec("git push webbynode +HEAD:master", false)
  
  # Reads out the "after push" tasks file to see if there are any tasks that must be performed
  # It will perform the "after push" tasks if there are any available
  after_tasks.read_tasks(Webbynode::Commands::Tasks::AfterPushTasksFile)
  perform_after_tasks if after_tasks.has_tasks?
  
  io.log "Finished pushing #{app_name.color(:cyan)}", :finish
end

#handle_semaphoreObject



59
60
61
62
# File 'lib/webbynode/commands/push.rb', line 59

def handle_semaphore
  return unless option(:'recreate-vhost')
  remote_executor.exec "mkdir -p /var/webbynode/semaphores && touch /var/webbynode/semaphores/recreate_#{app_name}"
end