Class: CodeStock::CLI_Cdweb

Inherits:
Object
  • Object
show all
Defined in:
lib/codestock/cdweb/cli_cdweb.rb

Class Method Summary collapse

Class Method Details

.execute(stdout, argv) ⇒ Object



58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
# File 'lib/codestock/cdweb/cli_cdweb.rb', line 58

def self.execute(stdout, argv)
  options = {
    :environment => ENV['RACK_ENV'] || "development",
    :pid         => nil,
    :Port        => 9292,
    :Host        => "0.0.0.0",
    :AccessLog   => [],
    :config      => "config.ru",
    # ----------------------------
    :server      => "thin",
    :LaunchBrowser => true,
    :DbDir => select_dbdir,
  }

  opts = OptionParser.new("#{File.basename($0)}")
  opts.on('--db DB_DIR', 'Database dir (default : ~/.codestock)') {|v| options[:DbDir] = v }
  opts.on("-o", "--host HOST", "listen on HOST (default: 0.0.0.0)") {|host| options[:Host] = host }
  opts.on('-p', '--port PORT', 'use PORT (default: 9292)') {|v| options[:Port] = v }
  opts.on('-n', '--no-browser', 'No launch browser.') {|v| options[:LaunchBrowser] = false }
  opts.parse!(argv)
  
  # 使用するデータベースの位置設定
  Database.setup(File.expand_path(options[:DbDir]))

  # サーバースクリプトのある場所へ移動
  FileUtils.cd(File.dirname(__FILE__))

  # Rackサーバー起動
  Rack::Server.start(options)
end

.select_dbdirObject



89
90
91
92
93
94
95
# File 'lib/codestock/cdweb/cli_cdweb.rb', line 89

def self.select_dbdir
  if (dbdir?('.') || !dbdir?(db_default_dir))
    '.'
  else
    db_default_dir
  end
end