Class: Chapp::Wiring

Inherits:
Object
  • Object
show all
Defined in:
lib/chapp/wiring.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(app_config, db, node) ⇒ Wiring

Returns a new instance of Wiring.



10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
# File 'lib/chapp/wiring.rb', line 10

def initialize app_config, db, node
  @used_apps = Hash.new

  @db = db
  @node = node
  @app = Chapp::NodeApp.new app_config, db, node.default["chapp"]["app_attributes"],
    Chef::Config[:node_name], node["fqdn"]

  app_config.used_apps.each do |app_id|
    used_app = @db.app app_id
    type = used_app.config.type

    unless @used_apps.has_key? type
      @used_apps[type] = Array.new
    end

    @used_apps[type] << used_app
  end
end

Instance Attribute Details

#nodeObject (readonly)

Returns the value of attribute node.



8
9
10
# File 'lib/chapp/wiring.rb', line 8

def node
  @node
end

Instance Method Details

#app(type = nil) ⇒ Object



30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
# File 'lib/chapp/wiring.rb', line 30

def app type=nil
  if type.nil?
    @app
  else
    unless @used_apps.has_key? type
      raise "App does not use app of type [#{type}]"
    end

    if @used_apps[type].size > 1
      raise "App uses many apps of [#{type}]"
    end

    @used_apps[type].first
  end
end

#apps(type) ⇒ Object



46
47
48
49
50
51
52
# File 'lib/chapp/wiring.rb', line 46

def apps type
  unless @used_apps.has_key? type
    raise "App does not use app of type [#{type}]"
  end

  @used_apps[type]
end