Class: ConfigBuilder::Model::Base
- Inherits:
-
Object
- Object
- ConfigBuilder::Model::Base
- Defined in:
- lib/config_builder/model/base.rb
Overview
A ConfigBuilder model implements a logic-less interface to a component of Vagrant.
A model should implement the following methods:
self.new_from_hash
This method takes an arbitrarily nested data structure of basic data types (Arrays, Hashes, Numerics, Strings, etc) and instantiates a new object with attributes set based on that data structure.
#to_proc
This method takes the object attributes and generates a lambda that will
create a Vagrant config with the state specified by the attributes. The
lambda should have an arity of one and should be passed a config
object.
The generated block will generate the Vagrant config that implements the
behavior specified by the object attributes.
If the Model delegates certain configuration to other models, the generated lambda should be able to evaluate lambdas from the delegated models.
Implementing classes do not need to inherit from ConfigBuilder::Model::Base, but it makes life easier.
Direct Known Subclasses
Network::ForwardedPort, Network::PrivateNetwork, Provider::Libvirt, Provider::VMware, Provider::Virtualbox, Provider::Vsphere, Provisioner::File, Provisioner::Puppet, Provisioner::PuppetServer, Provisioner::Shell, Root, SSH, SyncedFolder, VM, WinRM
Class Method Summary collapse
- .def_model_attribute(identifier) ⇒ Object
- .model_attributes ⇒ Object
-
.new_from_hash(attributes) ⇒ Object < ConfigBuilder::Model]
Deserialize a hash into a configbuilder model.
Instance Method Summary collapse
- #attrs=(config) ⇒ Object private
-
#call(config) ⇒ void
Generate a block based on the attribute configuration and call it with the given config.
-
#to_proc ⇒ Proc
abstract
Generate a block based on configuration specified by the attributes.
Class Method Details
.def_model_attribute(identifier) ⇒ Object
93 94 95 |
# File 'lib/config_builder/model/base.rb', line 93 def def_model_attribute(identifier) model_attributes << identifier end |
.model_attributes ⇒ Object
97 98 99 |
# File 'lib/config_builder/model/base.rb', line 97 def model_attributes (@identifiers ||= []) end |
.new_from_hash(attributes) ⇒ Object < ConfigBuilder::Model]
Deserialize a hash into a configbuilder model
31 32 33 34 35 |
# File 'lib/config_builder/model/base.rb', line 31 def self.new_from_hash(attributes) obj = new() obj.attrs = attributes obj end |
Instance Method Details
#attrs=(config) ⇒ Object
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
38 39 40 41 42 43 44 45 46 |
# File 'lib/config_builder/model/base.rb', line 38 def attrs=(config) hash = config.inject({}) { |hash, (key, value)| hash[key.to_sym] = value; hash } if @defaults @attrs = @defaults.merge(hash) else @attrs = hash end end |
#call(config) ⇒ void
This method returns an undefined value.
Generate a block based on the attribute configuration and call it with the given config.
61 62 63 |
# File 'lib/config_builder/model/base.rb', line 61 def call(config) to_proc.call(config) end |
#to_proc ⇒ Proc
Generate a block based on configuration specified by the attributes
52 53 54 |
# File 'lib/config_builder/model/base.rb', line 52 def to_proc raise NotImplementedError end |