class Adhearsion::Mongoid::Plugin::Service
Public Class Methods
start()
click to toggle source
Load the mongoid preferences, models and initiate logger
# File lib/adhearsion/mongoid/plugin/service.rb, line 9 def start params = config.to_hash.select { |k,v| !v.nil? } mongoid_config_path = fullpath *params.delete(:config_path) environment = ENV['AHN_ENV'] environment ||= ENV['RACK_ENV'] environment ||= ENV['RAILS_ENV'] environment ||= 'development' logger.info "Loading Mongoid configuration ('#{environment}')" ::Mongoid.load!(mongoid_config_path, environment) logger.info "Loading Mongoid models" require_models(*params.delete(:models_paths)) logger.info "Loading Mongoid logger" ::Mongoid.logger = logger ::Moped.logger = logger logger.info "Mongoid successfully configured" end
stop()
click to toggle source
stop service (unused)
# File lib/adhearsion/mongoid/plugin/service.rb, line 35 def stop end
Private Class Methods
config()
click to toggle source
Access to mongoid plugin configuration
# File lib/adhearsion/mongoid/plugin/service.rb, line 73 def config @config ||= Plugin.config end
fullpath(path)
click to toggle source
Get full path from any path
# File lib/adhearsion/mongoid/plugin/service.rb, line 58 def fullpath(path) pn = Pathname.new path root_path = '' if pn.relative? root_path = Adhearsion.config.root root_path ||= Dir.pwd end File.join root_path, path end
require_models(*paths)
click to toggle source
models are ‘.rb’ file in models directory
# File lib/adhearsion/mongoid/plugin/service.rb, line 42 def require_models(*paths) paths.each do |path| models_path = fullpath path Dir.foreach(models_path) do |filename| final_path = File.join models_path, filename full_path = fullpath final_path if File.file? full_path and File.extname(full_path) == ".rb" require full_path end end end end