Class: Rivet::Config

Inherits:
OpenState show all
Defined in:
lib/rivet/config.rb

Instance Attribute Summary collapse

Attributes inherited from OpenState

#generated_attributes, #required_fields

Class Method Summary collapse

Instance Method Summary collapse

Methods inherited from OpenState

#install_get_or_set, #method_missing, #validate

Constructor Details

#initialize(name, load_path = '.', &block) ⇒ Config



14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
# File 'lib/rivet/config.rb', line 14

def initialize(name, load_path='.', &block)
  super()
  @name = name
  @path = load_path
  @bootstrap = OpenState.new
  @required_fields = {
    :min_size => nil,
    :max_size => nil,
    :availability_zones => nil,
    :default_cooldown => 300,
    :desired_capacity => 0,
    :health_check_grace_period => 0,
    :health_check_type => :ec2,
    :load_balancers => [],
    :tags => [],
    :termination_policies => ['Default']
  }
  instance_eval(&block) if block
end

Dynamic Method Handling

This class handles dynamic methods through the method_missing method in the class Rivet::OpenState

Instance Attribute Details

#bootstrapObject

Returns the value of attribute bootstrap.



6
7
8
# File 'lib/rivet/config.rb', line 6

def bootstrap
  @bootstrap
end

#nameObject (readonly)

Returns the value of attribute name.



5
6
7
# File 'lib/rivet/config.rb', line 5

def name
  @name
end

Class Method Details

.from_file(dsl_file, load_path = '.') ⇒ Object



8
9
10
11
12
# File 'lib/rivet/config.rb', line 8

def self.from_file(dsl_file, load_path='.')
  name = File.basename(dsl_file, '.rb')
  data = Proc.new { eval(File.read(dsl_file)) }
  new(name, load_path, &data)
end

Instance Method Details

#normalize_availability_zonesObject



42
43
44
# File 'lib/rivet/config.rb', line 42

def normalize_availability_zones
  availability_zones.map { |zone| region + zone }.sort
end

#normalize_load_balancersObject



50
51
52
# File 'lib/rivet/config.rb', line 50

def normalize_load_balancers
  load_balancers.sort
end

#normalize_security_groupsObject



46
47
48
# File 'lib/rivet/config.rb', line 46

def normalize_security_groups
  security_groups.sort
end

#normalize_subnetsObject



54
55
56
# File 'lib/rivet/config.rb', line 54

def normalize_subnets
  subnets.sort
end

#normalize_tagsObject



58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
# File 'lib/rivet/config.rb', line 58

def normalize_tags
  normalized_tags = []
  tags.each do |t|
    normalized_hash = {}

    if t.has_key? :propagate_at_launch
      normalized_hash[:propagate_at_launch] = t[:propagate_at_launch]
    else
      normalized_hash[:propagate_at_launch] = true
    end

    [:value, :key].each do |k|
      if t.has_key? k
        normalized_hash[k] = t[k]
      else
        normalized_hash[k] = nil
      end
    end
    normalized_tags << normalized_hash
  end
  normalized_tags
end

#path(*args) ⇒ Object



34
35
36
37
38
39
40
# File 'lib/rivet/config.rb', line 34

def path(*args)
  if args.size < 1
    @path
  else
    File.join(@path, *args)
  end
end