Module: Xen::Parentable

Included in:
Backup, Config, Instance
Defined in:
lib/ruby-xen.rb

Overview

DRY up some classes (children of Slice) with some module funkiness.

Instance Method Summary collapse

Instance Method Details

#sliceObject

Returns the parent Slice object (d) for a sub-object. We ensure d.instance.object_id == self.object_id

Example

i = Xen::Instance.all[2]
s = i.slice
i.object_id == s.instance.object_id # true


65
66
67
68
69
70
# File 'lib/ruby-xen.rb', line 65

def slice
  d = Xen::Slice.new(name)
  # Insert the current object into the newly created Slice's attributes
  d.instance_variable_set("@#{self.class.to_s.sub('Xen::','').downcase}", self)
  d
end