Class: Asage::Attribute

Inherits:
Object
  • Object
show all
Defined in:
lib/asage/attribute.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(attribute_file) ⇒ Attribute

Returns a new instance of Attribute.



9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
# 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

Instance Attribute Details

#app_nameObject

Returns the value of attribute app_name.



5
6
7
# File 'lib/asage/attribute.rb', line 5

def app_name
  @app_name
end

#attribute_fileObject

Returns the value of attribute attribute_file.



5
6
7
# File 'lib/asage/attribute.rb', line 5

def attribute_file
  @attribute_file
end

#instance_typeObject

Returns the value of attribute instance_type.



5
6
7
# File 'lib/asage/attribute.rb', line 5

def instance_type
  @instance_type
end

#key_nameObject

Returns the value of attribute key_name.



5
6
7
# File 'lib/asage/attribute.rb', line 5

def key_name
  @key_name
end

#load_balancer_namesObject

Returns the value of attribute load_balancer_names.



5
6
7
# File 'lib/asage/attribute.rb', line 5

def load_balancer_names
  @load_balancer_names
end

#max_sizeObject

Returns the value of attribute max_size.



5
6
7
# File 'lib/asage/attribute.rb', line 5

def max_size
  @max_size
end

#min_sizeObject

Returns the value of attribute min_size.



5
6
7
# File 'lib/asage/attribute.rb', line 5

def min_size
  @min_size
end

#role_nameObject

Returns the value of attribute role_name.



5
6
7
# File 'lib/asage/attribute.rb', line 5

def role_name
  @role_name
end

#security_group_idsObject

Returns the value of attribute security_group_ids.



5
6
7
# File 'lib/asage/attribute.rb', line 5

def security_group_ids
  @security_group_ids
end

#subnet_idsObject

Returns the value of attribute subnet_ids.



5
6
7
# File 'lib/asage/attribute.rb', line 5

def subnet_ids
  @subnet_ids
end

#user_dataObject

Returns the value of attribute user_data.



5
6
7
# File 'lib/asage/attribute.rb', line 5

def user_data
  @user_data
end

Instance Method Details

#ami_name_generatorObject



45
46
47
# File 'lib/asage/attribute.rb', line 45

def ami_name_generator
  "#{self.app_name}_for_asg_#{Time.now.to_i}"
end

#asg_name_generatorObject



33
34
35
# File 'lib/asage/attribute.rb', line 33

def asg_name_generator
  "#{self.app_name}_asg"
end

#blank?(attr) ⇒ Boolean

Returns:

  • (Boolean)


70
71
72
# File 'lib/asage/attribute.rb', line 70

def blank?(attr)
  self.send(attr).nil? || self.send(attr).empty?
end

#exists?Boolean

Returns:

  • (Boolean)


29
30
31
# File 'lib/asage/attribute.rb', line 29

def exists?
  File.exist?(self.attribute_file.to_s)
end

#lc_name_generatorObject



41
42
43
# File 'lib/asage/attribute.rb', line 41

def lc_name_generator
  "#{lc_prefix_generator}#{Time.now.to_i}"
end

#lc_prefix_generatorObject



37
38
39
# File 'lib/asage/attribute.rb', line 37

def lc_prefix_generator
  "#{self.app_name}_lc_"
end

#present?(attr) ⇒ Boolean

Returns:

  • (Boolean)


66
67
68
# File 'lib/asage/attribute.rb', line 66

def present?(attr)
  !blank?(attr)
end

#to_hObject



49
50
51
52
53
# 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_yamlObject



55
56
57
58
59
60
61
62
63
64
# 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