Class: Fakecrm::Application
- Inherits:
-
Object
- Object
- Fakecrm::Application
- Includes:
- Singleton
- Defined in:
- lib/fakecrm/application.rb
Instance Attribute Summary collapse
- #logger ⇒ Object readonly
Instance Method Summary collapse
- #configure ⇒ Object
- #configure_dm ⇒ Object
- #configure_logger ⇒ Object
- #configure_server ⇒ Object
- #load_and_initialize ⇒ Object
- #prepare! ⇒ Object
- #run! ⇒ Object
- #start_server ⇒ Object
Instance Attribute Details
#logger ⇒ Object
74 75 76 77 78 79 80 |
# File 'lib/fakecrm/application.rb', line 74 def logger if !@logger $stderr.puts("Warning: Logger has not been configured! Defaulting to nil logger") self.logger = Logger.new(nil) end @logger end |
Instance Method Details
#configure ⇒ Object
8 9 10 11 12 |
# File 'lib/fakecrm/application.rb', line 8 def configure configure_logger configure_dm configure_server end |
#configure_dm ⇒ Object
44 45 46 47 48 49 50 51 |
# File 'lib/fakecrm/application.rb', line 44 def configure_dm logger.debug("Configuring default database to: #{Configuration.database}") DataMapper.setup(:default, Configuration.database) logger.debug("Configuring localizations") I18n.load_path += Dir[File.join(File.dirname(__FILE__), '../../locales', '*.yml').to_s] logger.debug("Using i18n files: #{I18n.load_path.inspect}") require 'fakecrm/localized_dm' end |
#configure_logger ⇒ Object
14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 |
# File 'lib/fakecrm/application.rb', line 14 def configure_logger level_map = { :info => Logger::INFO, :debug => Logger::DEBUG, :warn => Logger::WARN, :error => Logger::ERROR, :fatal => Logger::FATAL } if Configuration.silent Thin::Logging.silent = true DataMapper::Logger.new($stderr, :fatal) self.logger = Logger.new(nil) else DataMapper::Logger.new($stderr, Configuration.log_level) self.logger = Logger.new($stderr, level_map[Configuration.log_level]) end # replace sinatra logger Fakecrm::Server.disable :logging Fakecrm::Server.use Rack::CommonLogger, self.logger end |
#configure_server ⇒ Object
53 54 55 56 57 58 |
# File 'lib/fakecrm/application.rb', line 53 def configure_server logger.debug("Configuring server to run on port #{Configuration.port}") Fakecrm::Server.set :port, Configuration.port logger.debug("Switching do production environment") Fakecrm::Server.set :environment, :production end |
#load_and_initialize ⇒ Object
37 38 39 40 41 42 |
# File 'lib/fakecrm/application.rb', line 37 def load_and_initialize logger.debug("Loading resources") require 'fakecrm/resources' logger.debug("Initializing resources") require 'fakecrm/initialize' end |
#prepare! ⇒ Object
60 61 62 63 |
# File 'lib/fakecrm/application.rb', line 60 def prepare! configure load_and_initialize end |
#run! ⇒ Object
65 66 67 68 |
# File 'lib/fakecrm/application.rb', line 65 def run! prepare! start_server end |