Class: VagrantPlugins::Skytap::Properties

Inherits:
Object
  • Object
show all
Defined in:
lib/vagrant-skytap/properties.rb

Direct Known Subclasses

EnvironmentProperties, VmProperties

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(data_dir) ⇒ Properties

Returns a new instance of Properties.


28
29
30
31
# File 'lib/vagrant-skytap/properties.rb', line 28

def initialize(data_dir)
  @properties = self.class.read(data_dir)
  @data_dir = data_dir
end

Instance Attribute Details

#data_dirObject (readonly)

Returns the value of attribute data_dir


7
8
9
# File 'lib/vagrant-skytap/properties.rb', line 7

def data_dir
  @data_dir
end

#propertiesObject (readonly)

Returns the value of attribute properties


6
7
8
# File 'lib/vagrant-skytap/properties.rb', line 6

def properties
  @properties
end

Class Method Details

.filenameObject

Raises:

  • (NotImplementedError)

9
10
11
# File 'lib/vagrant-skytap/properties.rb', line 9

def self.filename
  raise NotImplementedError.new('Must override')
end

.read(data_dir) ⇒ Object


13
14
15
16
17
18
# File 'lib/vagrant-skytap/properties.rb', line 13

def self.read(data_dir)
  file = data_dir.join(filename)
  if file.exist?
    YAML.load_file(file)
  end
end

.write(data_dir, properties = {}) ⇒ Object


20
21
22
23
24
25
26
# File 'lib/vagrant-skytap/properties.rb', line 20

def self.write(data_dir, properties={})
  existing_props = read(data_dir) || {}
  props = existing_props.merge(properties)

  IO.write(data_dir.join(filename),
           YAML.dump(props))
end

Instance Method Details

#readObject


33
34
35
# File 'lib/vagrant-skytap/properties.rb', line 33

def read
  self.class.read(@data_dir)
end

#write(properties = {}) ⇒ Object


37
38
39
# File 'lib/vagrant-skytap/properties.rb', line 37

def write(properties={})
  self.class.write(@data_dir, properties)
end