Class: Asage::Attribute
- Inherits:
-
Object
- Object
- Asage::Attribute
- Defined in:
- lib/asage/attribute.rb
Instance Attribute Summary collapse
-
#app_name ⇒ Object
Returns the value of attribute app_name.
-
#attribute_file ⇒ Object
Returns the value of attribute attribute_file.
-
#instance_type ⇒ Object
Returns the value of attribute instance_type.
-
#key_name ⇒ Object
Returns the value of attribute key_name.
-
#load_balancer_names ⇒ Object
Returns the value of attribute load_balancer_names.
-
#max_size ⇒ Object
Returns the value of attribute max_size.
-
#min_size ⇒ Object
Returns the value of attribute min_size.
-
#role_name ⇒ Object
Returns the value of attribute role_name.
-
#security_group_ids ⇒ Object
Returns the value of attribute security_group_ids.
-
#subnet_ids ⇒ Object
Returns the value of attribute subnet_ids.
-
#user_data ⇒ Object
Returns the value of attribute user_data.
Instance Method Summary collapse
- #ami_name_generator ⇒ Object
- #asg_name_generator ⇒ Object
- #blank?(attr) ⇒ Boolean
- #exists? ⇒ Boolean
-
#initialize(attribute_file) ⇒ Attribute
constructor
A new instance of Attribute.
- #lc_name_generator ⇒ Object
- #lc_prefix_generator ⇒ Object
- #present?(attr) ⇒ Boolean
- #to_h ⇒ Object
- #to_yaml ⇒ Object
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_name ⇒ Object
Returns the value of attribute app_name.
5 6 7 |
# File 'lib/asage/attribute.rb', line 5 def app_name @app_name end |
#attribute_file ⇒ Object
Returns the value of attribute attribute_file.
5 6 7 |
# File 'lib/asage/attribute.rb', line 5 def attribute_file @attribute_file end |
#instance_type ⇒ Object
Returns the value of attribute instance_type.
5 6 7 |
# File 'lib/asage/attribute.rb', line 5 def instance_type @instance_type end |
#key_name ⇒ Object
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_names ⇒ Object
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_size ⇒ Object
Returns the value of attribute max_size.
5 6 7 |
# File 'lib/asage/attribute.rb', line 5 def max_size @max_size end |
#min_size ⇒ Object
Returns the value of attribute min_size.
5 6 7 |
# File 'lib/asage/attribute.rb', line 5 def min_size @min_size end |
#role_name ⇒ Object
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_ids ⇒ Object
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_ids ⇒ Object
Returns the value of attribute subnet_ids.
5 6 7 |
# File 'lib/asage/attribute.rb', line 5 def subnet_ids @subnet_ids end |
#user_data ⇒ Object
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_generator ⇒ Object
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_generator ⇒ Object
33 34 35 |
# File 'lib/asage/attribute.rb', line 33 def asg_name_generator "#{self.app_name}_asg" end |
#blank?(attr) ⇒ 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
29 30 31 |
# File 'lib/asage/attribute.rb', line 29 def exists? File.exist?(self.attribute_file.to_s) end |
#lc_name_generator ⇒ Object
41 42 43 |
# File 'lib/asage/attribute.rb', line 41 def lc_name_generator "#{lc_prefix_generator}#{Time.now.to_i}" end |
#lc_prefix_generator ⇒ Object
37 38 39 |
# File 'lib/asage/attribute.rb', line 37 def lc_prefix_generator "#{self.app_name}_lc_" end |
#present?(attr) ⇒ Boolean
66 67 68 |
# File 'lib/asage/attribute.rb', line 66 def present?(attr) !blank?(attr) end |
#to_h ⇒ Object
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_yaml ⇒ Object
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 |