Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
32 changes: 2 additions & 30 deletions bin/annyong
Original file line number Diff line number Diff line change
Expand Up @@ -8,33 +8,5 @@ require "optparse"
require "rack"
require "annyong"

options = {
:port => 9292,
:host => "0.0.0.0"
}
opts = OptionParser.new do |opts|
opts.banner = "Usage: annyong [options]

Options:
"
opts.on("--port [PORT]", "The port to use (default: 9292)") do |port|
options[:port] = port
end

opts.on("--host [HOST]", "The host to listen on (default: 0.0.0.0)") do |host|
options[:host] = host
end

#opts.on("--path [PATH]", "The directory to serve") do |path|
#options[:path] = path
#end

end
opts.parse!

Rack::Server.start({
:config => File.join(File.dirname(__FILE__), "../assets/rack/config.ru"),
:Port => options[:port],
:Host => options[:host],
:AccessLog => [],
})
application = Annyong::Application.new(ARGV)
application.run
1 change: 1 addition & 0 deletions lib/annyong.rb
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
module Annyong
VERSION = '0.3'
autoload :Directory, "annyong/directory"
require "annyong/application"
end

unless "".respond_to?(:each)
Expand Down
66 changes: 66 additions & 0 deletions lib/annyong/application.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,66 @@
require 'ostruct'

module Annyong

class Application

def server
@server ||= Rack::Server.new({
:config => File.join(File.dirname(__FILE__), "../../assets/rack/config.ru"),
:Port => port,
:Host => host,
:AccessLog => [],
})
end

def run
server.start
end

def port
options[:port]
end

def host
options[:host]
end

def initialize(args)
@options = parse_options(args)
end

def options
@options ||= parse_options
end

private

def parse_options(args)
options = {
:port => 9292,
:host => "0.0.0.0"
}

option_parser = OptionParser.new do |opts|
opts.banner = "Usage: annyong [options]"
opts.separator ""
opts.separator "Options:"

opts.on("--port [PORT]", "The port to use (default: #{options[:port]})") do |port|
options[:port] = port
end
opts.on("--host [HOST]", "The host to listen on (default: #{options[:host]})") do |host|
options[:host] = host
end

#opts.on("--path [PATH]", "The directory to serve") do |path|
#options[:path] = path
#end
end

option_parser.parse!(args)
options
end

end
end