Class: CfDeployer::Application

Inherits:
Object
  • Object
show all
Defined in:
lib/cf_deployer/application.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(context = {}) ⇒ Application

Returns a new instance of Application.



5
6
7
8
9
10
# File 'lib/cf_deployer/application.rb', line 5

def initialize(context = {})
 @context = context
 get_components
 add_component_dependencies
 @components.sort!
end

Instance Attribute Details

#componentsObject (readonly)

Returns the value of attribute components.



3
4
5
# File 'lib/cf_deployer/application.rb', line 3

def components
  @components
end

Instance Method Details

#add_component_dependenciesObject



20
21
22
23
24
25
26
27
28
29
30
31
32
# File 'lib/cf_deployer/application.rb', line 20

def add_component_dependencies
  @context[:components].keys.each do | key |
    component = @components.find { |c| c.name == key.to_s }
    dependencies = @context[:components][key][:'depends-on'] || []
    dependencies.each do | parent_name |
      parent = @components.find { |c| c.name == parent_name }
      if parent
        parent.children << component
        component.dependencies << parent
      end
    end
  end
end

#deployObject



34
35
36
37
38
# File 'lib/cf_deployer/application.rb', line 34

def deploy
  Log.debug @context
  components = get_targets().sort
  components.each &:deploy
end

#destroyObject



62
63
64
65
# File 'lib/cf_deployer/application.rb', line 62

def destroy
  components = get_targets.sort { |a, b| b <=> a }
  components.each &:destroy
end

#diffObject



45
46
47
48
# File 'lib/cf_deployer/application.rb', line 45

def diff
  components = get_targets().sort
  components.each &:diff
end

#get_componentsObject



12
13
14
15
16
17
18
# File 'lib/cf_deployer/application.rb', line 12

def get_components
  @components = []
  @context[:components].keys.each do | key |
    component = Component.new(@context[:application], @context[:environment], key.to_s, @context[:components][key])
    @components << component
  end
end

#jsonObject



40
41
42
43
# File 'lib/cf_deployer/application.rb', line 40

def json
  components = get_targets().sort
  components.each &:json
end

#kill_inactiveObject



67
68
69
70
# File 'lib/cf_deployer/application.rb', line 67

def kill_inactive
  component = get_targets.first
  component.kill_inactive
end

#run_hook(component_name, hook_name) ⇒ Object



58
59
60
# File 'lib/cf_deployer/application.rb', line 58

def run_hook component_name, hook_name
  @components.detect{ |component| component_name == component.name }.run_hook hook_name
end

#status(component_name, verbosity) ⇒ Object



50
51
52
53
54
55
56
# File 'lib/cf_deployer/application.rb', line 50

def status component_name, verbosity
  statuses = {}
  @components.select { |component|  component_name.nil? || component_name == component.name }.each do |component|
    statuses[component.name] = component.status(verbosity != 'stacks')
  end
  statuses
end

#switchObject



72
73
74
75
76
# File 'lib/cf_deployer/application.rb', line 72

def switch
  @context[:targets].each do | component_name |
    @components.find { |c| c.name == component_name }.switch
  end
end