Module: Boxlet

Extended by:
Boxlet, Config
Included in:
Boxlet
Defined in:
lib/boxlet.rb,
lib/boxlet/db.rb,
lib/boxlet/app.rb,
lib/boxlet/log.rb,
lib/boxlet/util.rb,
lib/boxlet/config.rb,
lib/boxlet/runner.rb,
lib/handlers/auth.rb,
lib/handlers/thin.rb,
lib/boxlet/version.rb,
lib/boxlet/app/models.rb,
lib/boxlet/app/router.rb,
lib/boxlet/app/templates.rb,
lib/boxlet/app/controller.rb

Defined Under Namespace

Modules: Config, Db, Handlers, Models, Util Classes: App, Controller, Log, Router, Runner, Templates

Constant Summary collapse

PUBLIC_COMMANDS =
{
  run: "Run the Boxlet server",
  stop: "Stop a daemonized server"
}.freeze
VERSION =
"1.0.5"

Constants included from Config

Config::ARGS

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods included from Config

populate_params!, symbolize_keys

Instance Attribute Details

#configObject

Returns the value of attribute config.



20
21
22
# File 'lib/boxlet.rb', line 20

def config
  @config
end

#raw_configObject

Returns the value of attribute raw_config.



20
21
22
# File 'lib/boxlet.rb', line 20

def raw_config
  @raw_config
end

#raw_paramsObject

Returns the value of attribute raw_params.



20
21
22
# File 'lib/boxlet.rb', line 20

def raw_params
  @raw_params
end

#runnerObject

Returns the value of attribute runner.



20
21
22
# File 'lib/boxlet.rb', line 20

def runner
  @runner
end

Instance Method Details

#debug?Boolean

Returns:

  • (Boolean)


55
56
57
# File 'lib/boxlet.rb', line 55

def debug?
  @config[:debug] == true
end

#log(level, message) ⇒ Object



67
68
69
# File 'lib/boxlet.rb', line 67

def log(level, message)
  @log.write(level, message)
end

#paramsObject



63
64
65
# File 'lib/boxlet.rb', line 63

def params
  @params
end

#run!(argv, command = 'run', config_file = 'config.yml', &blk) ⇒ Object



22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
# File 'lib/boxlet.rb', line 22

def run!(argv, command='run', config_file='config.yml', &blk)
  populate_params!(argv, config_file)
  @log = Boxlet::Log.new(@config[:log_file], (debug? ? Logger::DEBUG : Logger::INFO))
  @app = Boxlet::App.new

  command = command.to_s.to_sym
  case command
  when :run
    Boxlet.log(:debug, @config)
    @runner = Boxlet::Runner.new
    @runner.start(@app.bind, &blk)
  when :stop
    if @config[:daemonize] == true
      pid = File.read(@config[:pid_file]).to_i
      puts "Killing #{pid}..."
      Process.kill(Signal.list["TERM"], pid)
    end
  else
    if App::PUBLIC_COMMANDS.keys.include?(command)
      @app.send(command, argv)
    else
      print_menu
    end
  end

  @app
end

#stop!Object



50
51
52
53
# File 'lib/boxlet.rb', line 50

def stop!
  @runner.stop
  @app
end