Module: Zashoku::Module

Included in:
Conf
Defined in:
lib/core/module.rb

Class Method Summary collapse

Instance Method Summary collapse

Class Method Details

.load(modules) ⇒ Object



21
22
23
24
25
# File 'lib/core/module.rb', line 21

def self.load(modules)
  require_all(modules).map do |mod|
    [mod.name.split(':').last.downcase, mod]
  end.to_h
end

.require_all(modules) ⇒ Object



27
28
29
30
31
32
33
34
35
36
37
# File 'lib/core/module.rb', line 27

def self.require_all(modules)
  modules.map do |mod|
    if require_module(mod)
      Zashoku.logger.info("loaded module #{mod}")
      Zashoku.const_get(mod)
    else
      Zashoku.logger.error("failed to load module #{mod}")
      nil
    end
  end.compact
end

.require_module(mod) ⇒ Object



7
8
9
10
11
12
13
14
15
16
17
18
19
# File 'lib/core/module.rb', line 7

def self.require_module(mod)
  mod = mod.downcase
  Zashoku::LoadPaths.map do |path|
    mod_path = File.join(path, "#{mod}/lib/#{mod}.rb")
    next unless File.exist?(mod_path)
    begin
      require mod_path
    rescue LoadError => e
      Zashoku.logger.error("error: #{e} while loading #{mod}")
      false
    end
  end.any?
end

Instance Method Details

#controllerObject



43
# File 'lib/core/module.rb', line 43

def controller; end

#daemon_configObject



49
50
51
# File 'lib/core/module.rb', line 49

def daemon_config
  Util.get_yaml(File.join(self::Root, 'config/daemon.yml'))
end

#viewObject



41
# File 'lib/core/module.rb', line 41

def view; end

#view_configObject



45
46
47
# File 'lib/core/module.rb', line 45

def view_config
  Util.get_yaml(File.join(self::Root, 'config/view.yml'))
end