Class: Project

Inherits:
Object
  • Object
show all
Defined in:
lib/templates/lib/project.rb

Class Method Summary collapse

Class Method Details

.dbObject



37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
# File 'lib/templates/lib/project.rb', line 37

def self.db
  @db ||= begin
    defaults = {:user => 'root', :encoding => 'utf8'}
    db = case self.env
    when 'production'
      opts = defaults.merge(:password => 'ROCK')
      Sequel.mysql('<%= application %>_production', opts)
    when 'test'
      Sequel.sqlite
    else
      Sequel.mysql('<%= application %>_development', defaults)
    end
    db.loggers << self.logger
    db
  end
end

.envObject



14
15
16
# File 'lib/templates/lib/project.rb', line 14

def self.env
  ENV['RACK_ENV'] || 'development'
end

.loggerObject



18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
# File 'lib/templates/lib/project.rb', line 18

def self.logger
  @logger ||= begin
    if self.env == 'production'
      FileUtils.mkdir_p(File.join(self.root, 'log'))
      logger = Logger.new(File.new(File.join(self.root, 'log', 'production.log'), 'a'))
      logger.level = Logger::WARN
      logger
    elsif self.env == 'test'
      logger = Logger.new(STDOUT)
      logger.level = Logger::ERROR
      logger
    else
      logger = Logger.new(STDOUT)
      logger.level = Logger::INFO
      logger
    end
  end
end

.migration_dirObject



10
11
12
# File 'lib/templates/lib/project.rb', line 10

def self.migration_dir
  File.expand_path(File.join(File.dirname(__FILE__), 'migrations'))
end

.rootObject



6
7
8
# File 'lib/templates/lib/project.rb', line 6

def self.root
  File.expand_path(File.join(File.dirname(__FILE__), '..'))
end