Method: Thoth.init_thoth

Defined in:
lib/thoth.rb

.init_thothObject

Opens a connection to the Thoth database and loads helpers, controllers, models and plugins.



191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
# File 'lib/thoth.rb', line 191

def init_thoth
  trait[:ip]   ||= Config.server['address']
  trait[:port] ||= Config.server['port']

  open_db

  # Ensure that the database schema is up to date.
  #
  # TODO: need to rethink how migration works since newer versions of Sequel
  # don't expose the migration versions.
  #
  # unless Sequel::Migrator.get_current_migration_version(@db) ==
  #     Sequel::Migrator.latest_migration_version(File.join(LIB_DIR, 'migrate'))
  # 
  #   if trait[:mode] == :production
  #     raise SchemaError, "Database schema is missing or out of date. " <<
  #         "Please run `thoth --migrate`."
  #   else
  #     raise SchemaError, "Database schema is missing or out of date. " <<
  #         "Please run `thoth --devel --migrate`."
  #   end
  # end

  # If caching is disabled, replace the default cache store with a no-op
  # API.
  if Config.server['enable_cache']
    # Cache templates once read to prevent unnecessary disk thrashing.
    Innate::View.options.read_cache = true

    if Config.server['memcache']['enabled']
      Ramaze::Cache::MemCache::OPTIONS[:servers] = Config.server['memcache']['servers']
      Ramaze::Cache.options.default = Ramaze::Cache::MemCache
    end
  else
    require 'thoth/cache'
    Ramaze::Cache.options.default = Thoth::Cache::Noop
  end

  # Create a cache for plugins to use.
  Ramaze::Cache.add(:plugin)

  # Tell Innate where to find Thoth's helpers.
  Innate::HelpersHelper.options.paths << LIB_DIR
  Innate::HelpersHelper.options.namespaces << Thoth::Helper

  # Load Thoth controllers.
  require File.join(LIB_DIR, 'controller')

  # Load Thoth models.
  require File.join(LIB_DIR, 'helper/wiki')
  Thoth.acquire(File.join(LIB_DIR, 'model', '*'))

  # Load startup plugins.
  Config.plugins.each {|plugin| Plugin.load(plugin)}

  Ramaze::Log.info "Thoth home: #{HOME_DIR}"
  Ramaze::Log.info "Thoth lib : #{LIB_DIR}"
  Ramaze::Log.info "Running in #{trait[:mode] == :production ? 'live' : 'dev'} mode"

  Ramaze.options.setup << self
end