Class: Microengine::Initializer

Inherits:
Object
  • Object
show all
Defined in:
lib/initializer.rb

Overview

Load configs, create pages cache if necessary

Instance Method Summary collapse

Constructor Details

#initializeInitializer

Initialize microengine



31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
# File 'lib/initializer.rb', line 31

def initialize
  logger = Logger.new(STDERR)
  logger.level = Logger::WARN
  config = load_config
  
  admin = Admin.new
  dispatcher = Dispatcher.new
  assambler = Assambler.new
  if 'memory' == config['cache']
    cache = MemoryCache.new
  elsif 'file' == config['cache']
    cache = FileCache.new
  else
    logger.warn "Unknown value '#{config['cache']}' for 'cache' in config/settings.yaml . Will be used file cache."
    cache = MemoryCache.new
  end
  
  [admin, dispatcher, assambler].each do |object|
    object.logger = logger
    object.config = config
  end
  [admin, dispatcher].each do |object|
    object.cache = cache
  end
  admin.shadow = load_shadow
  admin.dispatcher = dispatcher
  admin.assambler = assambler
  dispatcher.admin = admin
  
  begin
    assambler.refresh
    cache.refresh
  rescue Exception => e
    logger.error "Cache was not created. " + e.message + "\n" + e.backtrace.join("\n")
  end
  dispatcher.run
rescue Exception => e
  logger.error(e)
end

Instance Method Details

#load_configObject

Load settings



72
73
74
75
76
# File 'lib/initializer.rb', line 72

def load_config
  YAML::load_file(MICROENGINE_ROOT + '/config/settings.yaml')
rescue
  raise "Can't open settings file. Please ensure that config/settings.yaml exists and can be read by engine."
end

#load_shadowObject

Load admin password



79
80
81
82
83
# File 'lib/initializer.rb', line 79

def load_shadow
  YAML::load_file(MICROENGINE_ROOT + '/config/shadow.yaml')
rescue
  raise "Can't open shadow file. Please ensure that config/shadow.yaml exists and can be read by engine."
end