Class: Chapp::NodeApp

Inherits:
App
  • Object
show all
Defined in:
lib/chapp/app/node_app.rb

Instance Attribute Summary

Attributes inherited from App

#attributes, #id

Instance Method Summary collapse

Methods inherited from App

#config, #connected_apps

Constructor Details

#initialize(app_config, db, attributes, node_name, fqdn) ⇒ NodeApp

Returns a new instance of NodeApp.



6
7
8
9
10
11
12
13
14
15
16
17
# File 'lib/chapp/app/node_app.rb', line 6

def initialize app_config, db, attributes, node_name, fqdn
  @id = app_config.id
  @id_hash = app_config.id_hash
  @db = db
  @config = app_config
  @fqdn = fqdn
  @node_name = node_name
  @attributes = attributes

  @instances = nil
  @connected_apps = nil
end

Instance Method Details

#instancesObject



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
# File 'lib/chapp/app/node_app.rb', line 19

def instances
  unless @instances
    app = @db.app @id_hash
    app_instances = app.instances
    @instances = []

    # If we can't find our own instance add it to the list
    found_node = false
    app_instances.each do |instance|
      if instance.node_name == @node_name
        found_node = true
        @instances << Chapp::AppInstance.new(id, @node_name, @fqdn)
        break
      else
        @instances << instance
      end
    end

    unless found_node
      @instances << Chapp::AppInstance.new(id, @node_name, @fqdn)
    end
  end

  @instances
end