Class: Convection::Model::Attributes

Inherits:
Object
  • Object
show all
Defined in:
lib/convection/model/attributes.rb

Overview

Manage parameters and attributes across stacks

Defined Under Namespace

Classes: Stack

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initializeAttributes

Returns a new instance of Attributes.



41
42
43
44
45
# File 'lib/convection/model/attributes.rb', line 41

def initialize
  @stacks = Hash.new do |hash, key|
    hash[key] = Stack.new
  end
end

Instance Attribute Details

#stacksObject (readonly)

Returns the value of attribute stacks.



39
40
41
# File 'lib/convection/model/attributes.rb', line 39

def stacks
  @stacks
end

Instance Method Details

#fetch(stack, key, default = nil) ⇒ Object

Raises:

  • (KeyError)


51
52
53
54
55
56
# File 'lib/convection/model/attributes.rb', line 51

def fetch(stack, key, default = nil)
  return get(stack, key, default) unless default.nil?
  raise KeyError, "key '#{key}' not found for stack '#{stack}'" unless include?(stack, key)

  @stacks[stack.to_s].fetch(key.to_s)
end

#get(stack, key, default = nil) ⇒ Object



58
59
60
# File 'lib/convection/model/attributes.rb', line 58

def get(stack, key, default = nil)
  include?(stack, key) ? @stacks[stack.to_s][key.to_s] : default
end

#include?(stack, key) ⇒ Boolean

Returns:

  • (Boolean)


47
48
49
# File 'lib/convection/model/attributes.rb', line 47

def include?(stack, key)
  @stacks.include?(stack) && @stacks[stack].include?(key)
end

#load_outputs(stack) ⇒ Object



66
67
68
# File 'lib/convection/model/attributes.rb', line 66

def load_outputs(stack)
  @stacks[stack.name.to_s].outputs = stack.outputs
end

#load_resources(stack) ⇒ Object



70
71
72
# File 'lib/convection/model/attributes.rb', line 70

def load_resources(stack)
  @stacks[stack.name.to_s].resources = stack.attribute_mapping_values
end

#set(stack, key, value) ⇒ Object



62
63
64
# File 'lib/convection/model/attributes.rb', line 62

def set(stack, key, value)
  @stacks[stack.to_s][key.to_s] = value
end