Class: CfDeployer::Component

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

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(application_name, environment_name, component_name, context) ⇒ Component

Returns a new instance of Component.



7
8
9
10
11
12
13
14
15
16
# File 'lib/cf_deployer/component.rb', line 7

def initialize(application_name, environment_name, component_name, context)
  @application_name = application_name
  @environment_name = environment_name
  @name = component_name
  @context = context
  @dependencies = []
  @children = []
  Log.debug "initializing #{name}.."
  Log.debug @context
end

Instance Attribute Details

#childrenObject (readonly)

Returns the value of attribute children.



5
6
7
# File 'lib/cf_deployer/component.rb', line 5

def children
  @children
end

#dependenciesObject (readonly)

Returns the value of attribute dependencies.



5
6
7
# File 'lib/cf_deployer/component.rb', line 5

def dependencies
  @dependencies
end

#nameObject (readonly)

Returns the value of attribute name.



5
6
7
# File 'lib/cf_deployer/component.rb', line 5

def name
  @name
end

Instance Method Details

#<=>(other) ⇒ Object



68
69
70
71
72
73
74
75
76
77
78
79
# File 'lib/cf_deployer/component.rb', line 68

def <=>(other)
  i_am_depednent = depends_on? other
  it_is_dependent = other.depends_on? self

  if i_am_depednent
    1
  elsif it_is_dependent
    -1
  else
    0
  end
end

#depends_on?(component, source = self) ⇒ Boolean

Returns:

  • (Boolean)

Raises:



85
86
87
88
# File 'lib/cf_deployer/component.rb', line 85

def depends_on?(component, source=self)
  raise ApplicationError.new("Cyclic dependency") if @dependencies.include?(source)
  @dependencies.include?(component) || @dependencies.any? { |d| d.depends_on?(component, source) }
end

#deployObject



26
27
28
29
30
31
32
33
# File 'lib/cf_deployer/component.rb', line 26

def deploy
  Log.debug "deploying #{name}..."
  @dependencies.each do |parent|
    parent.deploy unless(parent.exists?)
  end
  resolve_settings
  strategy.deploy
end

#destroyObject

Raises:



54
55
56
57
# File 'lib/cf_deployer/component.rb', line 54

def destroy
  raise ApplicationError.new("Unable to destroy #{name}, it is depended on by other components") if any_children_exist?
  strategy.destroy
end

#diffObject



41
42
43
44
45
46
47
48
49
50
51
52
# File 'lib/cf_deployer/component.rb', line 41

def diff
  resolve_settings
  current_json = strategy.active_template
  if current_json
    puts "#{name} json template diff:"
    new_json = ConfigLoader.erb_to_json(name, @context)
    Diffy::Diff.default_format = :color
    puts Diffy::Diff.new( current_json, new_json )
  else
    puts "No current json for component #{name}"
  end
end

#exists?Boolean

Returns:

  • (Boolean)


18
19
20
# File 'lib/cf_deployer/component.rb', line 18

def exists?
   strategy.exists?
end

#inspectObject



81
82
83
# File 'lib/cf_deployer/component.rb', line 81

def inspect
  "component: #{name}"
end

#jsonObject



35
36
37
38
39
# File 'lib/cf_deployer/component.rb', line 35

def json
  resolve_settings
  puts "#{name} json template:"
  puts ConfigLoader.erb_to_json(name, @context)
end

#kill_inactiveObject



22
23
24
# File 'lib/cf_deployer/component.rb', line 22

def kill_inactive
  strategy.kill_inactive
end

#output_value(key) ⇒ Object



64
65
66
# File 'lib/cf_deployer/component.rb', line 64

def output_value(key)
  strategy.output_value(key)
end

#run_hook(hook_name) ⇒ Object



94
95
96
97
# File 'lib/cf_deployer/component.rb', line 94

def run_hook hook_name
  resolve_settings
  strategy.run_hook hook_name
end

#status(get_resource_statuses) ⇒ Object



90
91
92
# File 'lib/cf_deployer/component.rb', line 90

def status get_resource_statuses
  strategy.status get_resource_statuses
end

#switchObject



59
60
61
# File 'lib/cf_deployer/component.rb', line 59

def switch
  exists? ? strategy.switch : (raise ApplicationError.new("No stack exists for component: #{name}"))
end