Class: VagrantPlugins::Dotvm::Config::AbstractConfig
- Inherits:
-
Object
- Object
- VagrantPlugins::Dotvm::Config::AbstractConfig
- Defined in:
- lib/vagrant-dotvm/config/abstractconfig.rb
Direct Known Subclasses
AuthorizedKey, BuildImage, Host, Instance, Machine, Network, Option, Project, Provision, Route, Run, SharedFolder
Instance Method Summary collapse
-
#convert_array(data, type) ⇒ Array
Converts array of hashes into array of specialized objects.
- #ensure_type(value, type, name = '') ⇒ Object
-
#populate(data) ⇒ Object
Populates current object with provided data.
Instance Method Details
#convert_array(data, type) ⇒ Array
Converts array of hashes into array of specialized objects.
31 32 33 34 35 36 37 38 39 40 41 |
# File 'lib/vagrant-dotvm/config/abstractconfig.rb', line 31 def convert_array(data, type) result = [] data.to_a.each do |item| object = Object.const_get(type).new object.populate item result << object end result end |
#ensure_type(value, type, name = '') ⇒ Object
21 22 23 24 |
# File 'lib/vagrant-dotvm/config/abstractconfig.rb', line 21 def ensure_type(value, type, name = '') return true if value.is_a?(type) || value.is_a?(NilClass) fail InvalidConfigError.new, "'#{name}' must be #{type.name}." end |
#populate(data) ⇒ Object
Populates current object with provided data.
8 9 10 11 12 13 14 15 16 17 18 19 |
# File 'lib/vagrant-dotvm/config/abstractconfig.rb', line 8 def populate(data) data.each do |key, value| unless respond_to? "#{key}=" fail( InvalidConfigError.new, "Invalid configuration option: #{key}." ) end send("#{key}=", value) end end |