Class: VirtualBox::NATEngine

Inherits:
AbstractModel show all
Defined in:
lib/virtualbox/nat_engine.rb

Overview

Represents a NAT engine for a given NetworkAdapter. This data is available through the ‘nat_driver` relationship on NetworkAdapter only if the adapter is a NAT adapter.

Class Method Summary collapse

Instance Method Summary collapse

Methods inherited from AbstractModel

#destroy, #errors, errors_for_relationship, #existing_record!, #inspect, #lazy_attribute?, #lazy_relationship?, #new_record!, #new_record?, #parent_machine, #populate_attributes, #populate_relationship, #populate_relationships, reload!, #reload!, reload?, reloaded!, #save!, #save_attribute, #save_changed_interface_attributes, #save_interface_attribute, #set_relationship, #validate, #write_attribute

Methods included from AbstractModel::Validatable

#__validates_extract_options, #add_error, #clear_errors, #errors, #errors_on, #full_error_messages, #valid?, #validate, #validates_format_of, #validates_inclusion_of, #validates_numericality_of, #validates_presence_of

Methods included from AbstractModel::Relatable

#destroy_relationship, #destroy_relationships, #has_relationship?, included, #lazy_relationship?, #loaded_relationship?, #populate_relationship, #populate_relationships, #read_relationship, #relationship_class, #relationship_data, #save_relationship, #save_relationships, #set_relationship

Methods included from AbstractModel::VersionMatcher

#assert_version_match, #split_version, #version_match?

Methods included from AbstractModel::Dirty

#changed?, #changes, #clear_dirty!, #ignore_dirty, #method_missing, #set_dirty!

Methods included from AbstractModel::InterfaceAttributes

#load_interface_attribute, #load_interface_attributes, #save_interface_attribute, #save_interface_attributes, #spec_to_proc

Methods included from AbstractModel::Attributable

#attributes, #has_attribute?, included, #lazy_attribute?, #loaded_attribute?, #populate_attributes, #read_attribute, #readonly_attribute?, #write_attribute

Methods included from Logger

included, #logger, #logger_output=

Constructor Details

#initialize(caller, inat) ⇒ NATEngine

Returns a new instance of NATEngine.



38
39
40
41
# File 'lib/virtualbox/nat_engine.rb', line 38

def initialize(caller, inat)
  super()
  initialize_attributes(caller, inat)
end

Dynamic Method Handling

This class handles dynamic methods through the method_missing method in the class VirtualBox::AbstractModel::Dirty

Class Method Details

.populate_relationship(caller, inat) ⇒ NATEngine

Populates the NAT engine for anything which is related to it.

**This method typically won’t be used except internally.**

Returns:



24
25
26
27
# File 'lib/virtualbox/nat_engine.rb', line 24

def populate_relationship(caller, inat)
  return nil if inat.nil?
  new(caller, inat)
end

.save_relationship(caller, item) ⇒ Object

Saves the relationship. This simply calls #save on every member of the relationship.

**This method typically won’t be used except internally.**



33
34
35
# File 'lib/virtualbox/nat_engine.rb', line 33

def save_relationship(caller, item)
  item.save
end

Instance Method Details

#initialize_attributes(parent, inat) ⇒ Object

Initializes the attributes of an existing NAT engine.



44
45
46
47
48
49
50
51
52
53
54
55
# File 'lib/virtualbox/nat_engine.rb', line 44

def initialize_attributes(parent, inat)
  write_attribute(:parent, parent)
  write_attribute(:interface, inat)

  # Load the interface attributes associated with this model
  load_interface_attributes(inat)
  populate_relationships(inat)

  # Clear dirty and set as existing
  clear_dirty!
  existing_record!
end

#modify_engineObject

Helper method to get the mutable ‘INATEngine` interface.



65
66
67
68
69
# File 'lib/virtualbox/nat_engine.rb', line 65

def modify_engine
  parent.modify_adapter do |adapter|
    yield adapter.nat_driver
  end
end

#saveObject



57
58
59
60
61
62
# File 'lib/virtualbox/nat_engine.rb', line 57

def save
  modify_engine do |nat|
    save_changed_interface_attributes(nat)
    save_relationships
  end
end