Class: VagrantPlugins::Conductor::Modules
- Inherits:
-
Object
- Object
- VagrantPlugins::Conductor::Modules
- Defined in:
- lib/vagrant/conductor/modules/modules.rb
Instance Attribute Summary collapse
-
#args ⇒ Object
Returns the value of attribute args.
-
#config ⇒ Object
Returns the value of attribute config.
-
#modules ⇒ Object
Returns the value of attribute modules.
-
#sync_path ⇒ Object
Returns the value of attribute sync_path.
Instance Method Summary collapse
- #get_classname(hash) ⇒ Object
- #get_defaults(path) ⇒ Object
- #init ⇒ Object
-
#initialize(modules, args, config, sync_path) ⇒ Modules
constructor
A new instance of Modules.
- #merge_defaults(name, args, defaults) ⇒ Object
Constructor Details
#initialize(modules, args, config, sync_path) ⇒ Modules
Returns a new instance of Modules.
10 11 12 13 14 15 |
# File 'lib/vagrant/conductor/modules/modules.rb', line 10 def initialize(modules, args, config, sync_path) @modules = modules @args = args @config = config @sync_path = sync_path end |
Instance Attribute Details
#args ⇒ Object
Returns the value of attribute args.
6 7 8 |
# File 'lib/vagrant/conductor/modules/modules.rb', line 6 def args @args end |
#config ⇒ Object
Returns the value of attribute config.
7 8 9 |
# File 'lib/vagrant/conductor/modules/modules.rb', line 7 def config @config end |
#modules ⇒ Object
Returns the value of attribute modules.
5 6 7 |
# File 'lib/vagrant/conductor/modules/modules.rb', line 5 def modules @modules end |
#sync_path ⇒ Object
Returns the value of attribute sync_path.
8 9 10 |
# File 'lib/vagrant/conductor/modules/modules.rb', line 8 def sync_path @sync_path end |
Instance Method Details
#get_classname(hash) ⇒ Object
21 22 23 24 25 |
# File 'lib/vagrant/conductor/modules/modules.rb', line 21 def get_classname(hash) classname = hash.find?('classname', nil) hash.delete('classname') classname end |
#get_defaults(path) ⇒ Object
17 18 19 |
# File 'lib/vagrant/conductor/modules/modules.rb', line 17 def get_defaults(path) YAML::load(File.read(path + '/config.yml')) end |
#init ⇒ Object
37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 |
# File 'lib/vagrant/conductor/modules/modules.rb', line 37 def init() initialized = Hash.new @modules.each do |path| name = File.basename(path) params = args.find?(name, nil) # Skip if module not requested next if params.nil? require path + "/#{name}" defaults = get_defaults(path) classname = get_classname(defaults) params = merge_defaults(name, params, defaults) initialized[name] = Kernel.const_get(classname).new(@config, params, path, @sync_path + "/#{name}") end initialized end |
#merge_defaults(name, args, defaults) ⇒ Object
27 28 29 30 31 32 33 34 35 |
# File 'lib/vagrant/conductor/modules/modules.rb', line 27 def merge_defaults(name, args, defaults) if args.kind_of?(Array) defaults.deep_merge({name => args}) elsif args.kind_of?(Hash) defaults.deep_merge(args) elsif args.kind_of?(String) args; end end |