Class: GitPusshuTen::Commands::Push

Inherits:
Base
  • Object
show all
Defined in:
lib/gitpusshuten/commands/push.rb

Instance Attribute Summary collapse

Attributes inherited from Base

#cli, #command, #configuration, #environment, #hooks, #perform_hooks

Instance Method Summary collapse

Methods inherited from Base

#c, #command_object, description, #e, #error, example, #g, #git, #help, #local, long_description, #message, #perform!, #perform_hooks!, #post_perform!, #pre_perform!, #prompt_for_root_password!, #prompt_for_user_password!, #r, #requires_user_existence!, #silent, #standard, usage, #validate!, #warning, #y, #yes?

Constructor Details

#initialize(*objects) ⇒ Push

Returns a new instance of Push.



14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
# File 'lib/gitpusshuten/commands/push.rb', line 14

def initialize(*objects)
  super
  perform_hooks!

  @command = cli.arguments.shift
  @type    = cli.arguments.shift

  if %(production staging).include?(command) and not type
    c.environment = command
    @type = (command == 'production') ? 'master' : 'develop'
    @command = 'branch'
  end

  help unless type and e.name

  set_remote!
end

Instance Attribute Details

#typeObject

Returns the value of attribute type.



12
13
14
# File 'lib/gitpusshuten/commands/push.rb', line 12

def type
  @type
end

Instance Method Details

#perform_branch!Object

Pushes the specified branch to the remote environment.



34
35
36
37
# File 'lib/gitpusshuten/commands/push.rb', line 34

def perform_branch!
  message "Pushing branch #{y(type)} to the #{y(e.name)} environment."
  git.push(:branch, type).to(e.name)
end

#perform_ref!Object

Pushes the specified ref to the remote environment.



48
49
50
51
# File 'lib/gitpusshuten/commands/push.rb', line 48

def perform_ref!
  message "Pushing ref #{y(type)} to the #{y(e.name)} environment."
  git.push(:ref, type).to(e.name)
end

#perform_tag!Object

Pushes the specified tag to the remote environment.



41
42
43
44
# File 'lib/gitpusshuten/commands/push.rb', line 41

def perform_tag!
  message "Pushing tag #{y(type)} to the #{y(e.name)} environment."
  git.push(:tag, type).to(e.name)
end

#set_remote!Object

Adds the remote



55
56
57
58
# File 'lib/gitpusshuten/commands/push.rb', line 55

def set_remote!
  git.remove_remote(e.name) if git.has_remote?(e.name)
  git.add_remote(e.name, "ssh://#{c.user}@#{c.ip}:#{c.port}/#{e.app_dir}")
end