Class: CapistranoCloudfoundry::Application

Inherits:
Object
  • Object
show all
Defined in:
lib/capistrano-cloudfoundry/application.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(name, url, target) ⇒ Application

Returns a new instance of Application.



5
6
7
8
9
# File 'lib/capistrano-cloudfoundry/application.rb', line 5

def initialize(name, url, target)
  @name = name
  @url = url.match(%r/http[s]?:\/\/([^\/]+)/) ? url.match(%r/http[s]?:\/\/([^\/]+)/)[1] : url
  @target = target
end

Instance Attribute Details

#nameObject (readonly)

Returns the value of attribute name.



4
5
6
# File 'lib/capistrano-cloudfoundry/application.rb', line 4

def name
  @name
end

#targetObject (readonly)

Returns the value of attribute target.



4
5
6
# File 'lib/capistrano-cloudfoundry/application.rb', line 4

def target
  @target
end

#urlObject (readonly)

Returns the value of attribute url.



4
5
6
# File 'lib/capistrano-cloudfoundry/application.rb', line 4

def url
  @url
end

Instance Method Details

#pushObject



10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
# File 'lib/capistrano-cloudfoundry/application.rb', line 10

def push
  #deploy the app
  apps = `vmc apps`
  case
    when apps.match(%r/#{@name}-blue *\|[^\|]*\|[^\|]*\| .*#{@url}/)
      @old_deploy = "blue"
      @deploy = "green"
    when apps.match(%r/#{@name}-green *\|[^\|]*\|[^\|]*\| .*#{@url}/)
      @old_deploy = "green"
      @deploy = "blue"
    else
      @deploy = "blue"
  end
  if apps.include?(" #{@name}-#{@deploy} ") then
    puts `vmc update #{@name}-#{@deploy}`
  else
    puts `vmc push #{@name}-#{@deploy} -n`
  end
  apps = `vmc apps`
  if apps.match(%r/#{@name}-#{@deploy}[ ]*\|[^\|]*\| RUNNING/) then
    @old_deploy ? `vmc unmap #{@name}-#{@old_deploy} #{@url}` : nil
    `vmc map #{@name}-#{@deploy} #{@url}`
  end
end