class Asage::Attribute

Attributes

app_name[RW]
attribute_file[RW]
instance_type[RW]
key_name[RW]
load_balancer_names[RW]
max_size[RW]
min_size[RW]
role_name[RW]
security_group_ids[RW]
subnet_ids[RW]
user_data[RW]

Public Class Methods

new(attribute_file) click to toggle source
# File lib/asage/attribute.rb, line 9
def initialize(attribute_file)
  self.attribute_file = attribute_file

  if self.exists?
    attributes = YAML.load_file(attribute_file)
    self.app_name = attributes.keys.first

    attribute = attributes[self.app_name]
    self.instance_type       = attribute["instance_type"]
    self.key_name            = attribute["key_name"]
    self.security_group_ids  = attribute["security_group_ids"]
    self.user_data           = attribute["user_data"]
    self.role_name           = attribute["role_name"]
    self.min_size            = attribute["min_size"]
    self.max_size            = attribute["max_size"]
    self.load_balancer_names = attribute["load_balancer_names"]
    self.subnet_ids          = attribute["subnet_ids"]
  end
end

Public Instance Methods

ami_name_generator() click to toggle source
# File lib/asage/attribute.rb, line 45
def ami_name_generator
  "#{self.app_name}_for_asg_#{Time.now.to_i}"
end
asg_name_generator() click to toggle source
# File lib/asage/attribute.rb, line 33
def asg_name_generator
  "#{self.app_name}_asg"
end
blank?(attr) click to toggle source
# File lib/asage/attribute.rb, line 70
def blank?(attr)
  self.send(attr).nil? || self.send(attr).empty?
end
exists?() click to toggle source
# File lib/asage/attribute.rb, line 29
def exists?
  File.exist?(self.attribute_file.to_s)
end
lc_name_generator() click to toggle source
# File lib/asage/attribute.rb, line 41
def lc_name_generator
  "#{lc_prefix_generator}#{Time.now.to_i}"
end
lc_prefix_generator() click to toggle source
# File lib/asage/attribute.rb, line 37
def lc_prefix_generator
  "#{self.app_name}_lc_"
end
present?(attr) click to toggle source
# File lib/asage/attribute.rb, line 66
def present?(attr)
  !blank?(attr)
end
to_h() click to toggle source
# File lib/asage/attribute.rb, line 49
def to_h
  self.instance_variables.each_with_object({}) do |attr, hash|
    hash[attr.to_s.delete("@")] = self.instance_variable_get(attr)
  end
end
to_yaml() click to toggle source
# File lib/asage/attribute.rb, line 55
def to_yaml
  h = self.to_h
  h.delete("attribute_file")
  h.delete("app_name")
  attributes_hash = {self.app_name => h}

  File.open(self.attribute_file, 'w') do |f|
    YAML.dump(attributes_hash, f)
  end
end