Class: Microengine::Initializer
- Inherits:
-
Object
- Object
- Microengine::Initializer
- Defined in:
- lib/initializer.rb
Overview
Load configs, create pages cache if necessary
Instance Method Summary collapse
-
#initialize ⇒ Initializer
constructor
Initialize microengine.
-
#load_config ⇒ Object
Load settings.
-
#load_seach_spiders ⇒ Object
Load search spider list.
-
#load_shadow ⇒ Object
Load admin password.
Constructor Details
#initialize ⇒ Initializer
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 70 |
# 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.spiders = load_seach_spiders dispatcher.admin = admin begin assambler.refresh cache.refresh rescue Exception => e logger.error "Cache was not created. " + e. + "\n" + e.backtrace.join("\n") end dispatcher.run rescue Exception => e logger.error(e) end |
Instance Method Details
#load_config ⇒ Object
Load settings
73 74 75 76 77 |
# File 'lib/initializer.rb', line 73 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_seach_spiders ⇒ Object
Load search spider list
87 88 89 90 91 |
# File 'lib/initializer.rb', line 87 def load_seach_spiders IO.readlines(MICROENGINE_ROOT + '/config/search spiders') rescue raise "Can't open spiders file. Please ensure that '/config/search spiders' exists and can be read by engine." end |
#load_shadow ⇒ Object
Load admin password
80 81 82 83 84 |
# File 'lib/initializer.rb', line 80 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 |