Class: Capistrano::Alice::Release

Inherits:
Object
  • Object
show all
Defined in:
lib/capistrano-alice/release_managment.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(config) ⇒ Release

Returns a new instance of Release.



12
13
14
15
# File 'lib/capistrano-alice/release_managment.rb', line 12

def initialize(config)
  @config      = config
  @environment = {}
end

Instance Attribute Details

#deploy_referenceObject

Returns the value of attribute deploy_reference.



6
7
8
# File 'lib/capistrano-alice/release_managment.rb', line 6

def deploy_reference
  @deploy_reference
end

#environmentObject

Returns the value of attribute environment.



5
6
7
# File 'lib/capistrano-alice/release_managment.rb', line 5

def environment
  @environment
end

#idObject

Returns the value of attribute id.



9
10
11
# File 'lib/capistrano-alice/release_managment.rb', line 9

def id
  @id
end

#numberObject

Returns the value of attribute number.



10
11
12
# File 'lib/capistrano-alice/release_managment.rb', line 10

def number
  @number
end

#path_rulesObject

Returns the value of attribute path_rules.



4
5
6
# File 'lib/capistrano-alice/release_managment.rb', line 4

def path_rules
  @path_rules
end

#processesObject

Returns the value of attribute processes.



3
4
5
# File 'lib/capistrano-alice/release_managment.rb', line 3

def processes
  @processes
end

#repository_referenceObject

Returns the value of attribute repository_reference.



7
8
9
# File 'lib/capistrano-alice/release_managment.rb', line 7

def repository_reference
  @repository_reference
end

#serversObject

Returns the value of attribute servers.



2
3
4
# File 'lib/capistrano-alice/release_managment.rb', line 2

def servers
  @servers
end

Instance Method Details

#activate!Object



46
47
48
49
50
51
52
53
54
# File 'lib/capistrano-alice/release_managment.rb', line 46

def activate!
  Net::HTTP.start(@config.alice_host, @config.alice_port) do |http|
    request = Net::HTTP::Post.new("/api_v1/releases/#{@id}/activate.json")
    request.body = Yajl::Encoder.encode({})
    request.content_type = "application/json"
    request['Accepts'] = "application/json"
    response = http.request(request)
  end
end

#create!Object



17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
# File 'lib/capistrano-alice/release_managment.rb', line 17

def create!
  body = {
    "application"          => @config.application,
    "machines"             => @servers,
    "processes"            => @processes,
    "path_rules"           => (@path_rules || {}).to_a,
    "environment"          => @environment,
    "deploy_reference"     => @deploy_reference,
    "repository_reference" => @repository_reference
  }

  Net::HTTP.start(@config.alice_host, @config.alice_port) do |http|
    request = Net::HTTP::Post.new("/api_v1/releases.json")
    request.body = Yajl::Encoder.encode(body)
    request.content_type = "application/json"
    request['Accepts'] = "application/json"
    response = http.request(request)
    if Net::HTTPSuccess === response
      response = Yajl::Parser.parse(response.body)
      @id          = response['release']['id']
      @number      = response['release']['number']
      @environment = response['release']['environment']
    else
      raise "Failed to create release!"
    end
  end

end

#destroy!Object



56
57
58
59
60
61
62
63
# File 'lib/capistrano-alice/release_managment.rb', line 56

def destroy!
  Net::HTTP.start(@config.alice_host, @config.alice_port) do |http|
    request = Net::HTTP::Delete.new("/api_v1/releases/#{@id}.json")
    request.content_type = "application/json"
    request['Accepts'] = "application/json"
    response = http.request(request)
  end
end