Class: VagrantPlugins::AVF::Model::MachineRequirements
- Inherits:
-
Object
- Object
- VagrantPlugins::AVF::Model::MachineRequirements
- Defined in:
- lib/vagrant_provider_avf/model/machine_requirements.rb
Constant Summary collapse
- DEFAULT_CPUS =
1- DEFAULT_MEMORY_MB =
1024- DEFAULT_DISK_GB =
16- FIELDS =
[:cpus, :memory_mb, :disk_gb, :headless].freeze
Instance Attribute Summary collapse
-
#cpus ⇒ Object
readonly
Returns the value of attribute cpus.
-
#disk_gb ⇒ Object
readonly
Returns the value of attribute disk_gb.
-
#headless ⇒ Object
readonly
Returns the value of attribute headless.
-
#memory_mb ⇒ Object
readonly
Returns the value of attribute memory_mb.
Class Method Summary collapse
Instance Method Summary collapse
- #changed_fields(other) ⇒ Object
- #errors ⇒ Object
-
#initialize(cpus:, memory_mb:, disk_gb:, headless:) ⇒ MachineRequirements
constructor
A new instance of MachineRequirements.
- #to_h ⇒ Object
Constructor Details
#initialize(cpus:, memory_mb:, disk_gb:, headless:) ⇒ MachineRequirements
Returns a new instance of MachineRequirements.
28 29 30 31 32 33 |
# File 'lib/vagrant_provider_avf/model/machine_requirements.rb', line 28 def initialize(cpus:, memory_mb:, disk_gb:, headless:) @cpus = normalize_integer(cpus, DEFAULT_CPUS) @memory_mb = normalize_integer(memory_mb, DEFAULT_MEMORY_MB) @disk_gb = normalize_integer(disk_gb, DEFAULT_DISK_GB) @headless = headless.nil? ? true : headless end |
Instance Attribute Details
#cpus ⇒ Object (readonly)
Returns the value of attribute cpus.
26 27 28 |
# File 'lib/vagrant_provider_avf/model/machine_requirements.rb', line 26 def cpus @cpus end |
#disk_gb ⇒ Object (readonly)
Returns the value of attribute disk_gb.
26 27 28 |
# File 'lib/vagrant_provider_avf/model/machine_requirements.rb', line 26 def disk_gb @disk_gb end |
#headless ⇒ Object (readonly)
Returns the value of attribute headless.
26 27 28 |
# File 'lib/vagrant_provider_avf/model/machine_requirements.rb', line 26 def headless @headless end |
#memory_mb ⇒ Object (readonly)
Returns the value of attribute memory_mb.
26 27 28 |
# File 'lib/vagrant_provider_avf/model/machine_requirements.rb', line 26 def memory_mb @memory_mb end |
Class Method Details
.fetch(attributes, key) ⇒ Object
19 20 21 22 23 24 |
# File 'lib/vagrant_provider_avf/model/machine_requirements.rb', line 19 def self.fetch(attributes, key) return attributes[key] if attributes.key?(key) return attributes[key.to_sym] if attributes.key?(key.to_sym) nil end |
.from_h(attributes) ⇒ Object
10 11 12 13 14 15 16 17 |
# File 'lib/vagrant_provider_avf/model/machine_requirements.rb', line 10 def self.from_h(attributes) new( cpus: fetch(attributes, "cpus"), memory_mb: fetch(attributes, "memory_mb"), disk_gb: fetch(attributes, "disk_gb"), headless: fetch(attributes, "headless") ) end |
Instance Method Details
#changed_fields(other) ⇒ Object
44 45 46 |
# File 'lib/vagrant_provider_avf/model/machine_requirements.rb', line 44 def changed_fields(other) FIELDS.select { |field| public_send(field) != other.public_send(field) } end |
#errors ⇒ Object
35 36 37 38 39 40 41 42 |
# File 'lib/vagrant_provider_avf/model/machine_requirements.rb', line 35 def errors [].tap do |result| validate_positive_integer(:cpus, @cpus, result) validate_positive_integer(:memory_mb, @memory_mb, result) validate_positive_integer(:disk_gb, @disk_gb, result) validate_boolean(:headless, @headless, result) end end |
#to_h ⇒ Object
48 49 50 51 52 53 54 55 |
# File 'lib/vagrant_provider_avf/model/machine_requirements.rb', line 48 def to_h { "cpus" => @cpus, "memory_mb" => @memory_mb, "disk_gb" => @disk_gb, "headless" => @headless } end |