Class: Fakecrm::Application

Inherits:
Object
  • Object
show all
Includes:
Singleton
Defined in:
lib/fakecrm/application.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Instance Attribute Details

#loggerObject



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

#configureObject



8
9
10
11
12
# File 'lib/fakecrm/application.rb', line 8

def configure
  configure_logger
  configure_dm
  configure_server
end

#configure_dmObject



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_loggerObject



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_serverObject



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_initializeObject



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

#start_serverObject



70
71
72
# File 'lib/fakecrm/application.rb', line 70

def start_server
  Fakecrm::Server.run!
end