Class: Definition

Inherits:
Object
  • Object
show all
Defined in:
lib/sproutr/definition.rb

Constant Summary collapse

FILE_PREFIX =
"~/Sprout_configs/machine_definitions/"

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize {|_self| ... } ⇒ Definition

Returns a new instance of Definition.

Yields:

  • (_self)

Yield Parameters:

  • _self (Definition)

    the object that the method was called on



8
9
10
# File 'lib/sproutr/definition.rb', line 8

def initialize
  yield self if block_given?
end

Instance Attribute Details

#amiObject

Returns the value of attribute ami.



6
7
8
# File 'lib/sproutr/definition.rb', line 6

def ami
  @ami
end

#availability_zoneObject

Returns the value of attribute availability_zone.



6
7
8
# File 'lib/sproutr/definition.rb', line 6

def availability_zone
  @availability_zone
end

#chef_cookbooksObject

Returns the value of attribute chef_cookbooks.



6
7
8
# File 'lib/sproutr/definition.rb', line 6

def chef_cookbooks
  @chef_cookbooks
end

#chef_installObject

Returns the value of attribute chef_install.



6
7
8
# File 'lib/sproutr/definition.rb', line 6

def chef_install
  @chef_install
end

#chef_recipesObject

Returns the value of attribute chef_recipes.



6
7
8
# File 'lib/sproutr/definition.rb', line 6

def chef_recipes
  @chef_recipes
end

#gemsObject

Returns the value of attribute gems.



6
7
8
# File 'lib/sproutr/definition.rb', line 6

def gems
  @gems
end

#key_nameObject

Returns the value of attribute key_name.



6
7
8
# File 'lib/sproutr/definition.rb', line 6

def key_name
  @key_name
end

#nameObject

Returns the value of attribute name.



6
7
8
# File 'lib/sproutr/definition.rb', line 6

def name
  @name
end

#packagesObject

Returns the value of attribute packages.



6
7
8
# File 'lib/sproutr/definition.rb', line 6

def packages
  @packages
end

#sizeObject

Returns the value of attribute size.



6
7
8
# File 'lib/sproutr/definition.rb', line 6

def size
  @size
end

#tagsObject

Returns the value of attribute tags.



6
7
8
# File 'lib/sproutr/definition.rb', line 6

def tags
  @tags
end

#user_dataObject

Returns the value of attribute user_data.



6
7
8
# File 'lib/sproutr/definition.rb', line 6

def user_data
  @user_data
end

#volume_sizeObject

Returns the value of attribute volume_size.



6
7
8
# File 'lib/sproutr/definition.rb', line 6

def volume_size
  @volume_size
end

#volumesObject

Returns the value of attribute volumes.



6
7
8
# File 'lib/sproutr/definition.rb', line 6

def volumes
  @volumes
end

Instance Method Details

#load_from_file(filename) ⇒ Object



12
13
14
15
16
17
# File 'lib/sproutr/definition.rb', line 12

def load_from_file(filename)
  definition_file = File.open(FILE_PREFIX + filename, 'r')
  JSON.parse(definition_file.read).each do |element, value|
    instance_variable_set(element, value)
  end
end

#save_to_file(filename) ⇒ Object



19
20
21
22
23
24
25
# File 'lib/sproutr/definition.rb', line 19

def save_to_file(filename)
  hash_of_definition = Hash.new
  instance_variables.each do |var|
    hash_of_definition[var.to_s.gsub("@","")] = instance_variable_get(var)
  end
  File.open(FILE_PREFIX + filename, 'w') {|f| f.write(hash_of_definition.to_json) }
end