Class: SuperStack::Manager

Inherits:
Object
  • Object
show all
Defined in:
lib/super_stack/manager.rb

Constant Summary collapse

DEFAULT_INTERVAL =
10

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initializeManager

Returns a new instance of Manager.



24
25
26
# File 'lib/super_stack/manager.rb', line 24

def initialize
  @layers = {}
end

Instance Attribute Details

#layersObject (readonly)

Returns the value of attribute layers.



6
7
8
# File 'lib/super_stack/manager.rb', line 6

def layers
  @layers
end

#merge_policyObject

Returns the value of attribute merge_policy.



6
7
8
# File 'lib/super_stack/manager.rb', line 6

def merge_policy
  @merge_policy
end

Instance Method Details

#[](filter = nil) ⇒ Object



8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
# File 'lib/super_stack/manager.rb', line 8

def [](filter=nil)
  raise 'Manager not ready (no merge policy specified)' unless ready?
  layers = to_a
  return [] if layers.empty?
  return layers[0] if layers.count == 1
  first_layer = layers.shift
  res = layers.inject(first_layer) do |stack, layer|
    merge_policy.merge stack, layer
  end
  if filter.nil?
    res
  else
    res[filter]
  end
end

#add_layer(layer) ⇒ Object



32
33
34
35
36
37
# File 'lib/super_stack/manager.rb', line 32

def add_layer(layer)
  raise 'Layer should have a name' unless layer.respond_to? :name
  raise 'Layer already existing' if layers.keys.include? layer.name
  layer.priority = get_unused_priority if layer.priority.nil?
  layers[layer.name] = layer
end

#ready?Boolean

Returns:

  • (Boolean)


44
45
46
# File 'lib/super_stack/manager.rb', line 44

def ready?
  !@merge_policy.nil?
end

#to_aObject



28
29
30
# File 'lib/super_stack/manager.rb', line 28

def to_a
  layers.values.sort
end