Class: VagrantPlugins::Conductor::Modules

Inherits:
Object
  • Object
show all
Defined in:
lib/vagrant/conductor/modules/modules.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

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

#argsObject

Returns the value of attribute args.



6
7
8
# File 'lib/vagrant/conductor/modules/modules.rb', line 6

def args
  @args
end

#configObject

Returns the value of attribute config.



7
8
9
# File 'lib/vagrant/conductor/modules/modules.rb', line 7

def config
  @config
end

#modulesObject

Returns the value of attribute modules.



5
6
7
# File 'lib/vagrant/conductor/modules/modules.rb', line 5

def modules
  @modules
end

#sync_pathObject

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

#initObject



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