Class: LanGrove::ModuleLoader

Inherits:
Object
  • Object
show all
Defined in:
lib/langrove/ext/module_loader.rb

Class Method Summary collapse

Class Method Details

.create(args = {}) ⇒ Object



5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
# File 'lib/langrove/ext/module_loader.rb', line 5

def create(args={})
  
  #
  # args = {
  # 
  #   :config => <hash of config>,
  #   :key    => <daemon_root_component_key>,
  #   :mandatory => <default true>
  # 
  # }
  #
  

  # if the config has no 'module key'
  unless args[:config].has_key?(args[:key])

    mandatory = args[:mandatory]
    mandatory = true if mandatory.nil?    #stu defaults to correct

    if mandatory
      raise DaemonConfigException, "Cannot find key with '#{args[:key]}'"
    else
      # just exit
      return nil
    end
  end

  params = { 
    :class => "Default", 
    :module => args[:key].to_s.camelize
  }
  
  begin
    class_name = args[:config][args[:key]][:class]
  rescue
    #class_name = 'Base' if args[:config].has_key?( args[:key] )
  end
  
  params.merge!(:class => class_name) unless class_name.nil?
  


  ClassLoader.create(params, args[:logger])
end