Class: Indexer::WebUI::Server
- Inherits:
-
Object
- Object
- Indexer::WebUI::Server
- Defined in:
- lib/indexer/webui.rb
Overview
Server is a Rack-based server that simply serves up the editing page.
Defined Under Namespace
Classes: IndexHTML
Constant Summary collapse
- ROOT =
File.join(File.dirname(__FILE__), 'webui')
Instance Attribute Summary collapse
-
#options ⇒ Object
readonly
Server options, parsed from command line.
Class Method Summary collapse
Instance Method Summary collapse
-
#app ⇒ Object
If the site has a
brite.ru
file, that will be used to start the server, otherwise a standard Rack::Directory server ise used. - #index_json ⇒ Object
-
#initialize(argv) ⇒ Server
constructor
Setup new instance of Brite::Server.
-
#root ⇒ Object
Site root directory.
-
#start ⇒ Object
Start the server.
-
#tmp_dir ⇒ Object
Temporary directory used by the rack server.
Constructor Details
#initialize(argv) ⇒ Server
Setup new instance of Brite::Server.
41 42 43 44 45 46 47 48 49 50 |
# File 'lib/indexer/webui.rb', line 41 def initialize(argv) @options = ::Rack::Server::Options.new.parse!(argv) @root = argv.first || Dir.pwd @options[:app] = app #@options[:pid] = "#{tmp_dir}/pids/server.pid" @options[:Port] ||= '4444' end |
Instance Attribute Details
#options ⇒ Object (readonly)
Server options, parsed from command line.
36 37 38 |
# File 'lib/indexer/webui.rb', line 36 def @options end |
Class Method Details
.start(argv) ⇒ Object
29 30 31 |
# File 'lib/indexer/webui.rb', line 29 def self.start(argv) new(argv).start end |
Instance Method Details
#app ⇒ Object
If the site has a brite.ru
file, that will be used to start the server,
otherwise a standard Rack::Directory server ise used.
104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 |
# File 'lib/indexer/webui.rb', line 104 def app @app ||= ( #if ::File.exist?(rack_file) # app, options = Rack::Builder.parse_file(rack_file, opt_parser) # @options.merge!(options) # app #else root = self.root json = index_json Rack::Builder.new do use IndexHTML, root map '/index' do run Proc.new{ |env| [200, {"Content-Type" => "text/json"}, [json]] } end run Rack::Directory.new("#{root}") end #end ) end |
#index_json ⇒ Object
128 129 130 |
# File 'lib/indexer/webui.rb', line 128 def index_json YAML.load_file('.index').to_json end |
#root ⇒ Object
Site root directory.
91 92 93 |
# File 'lib/indexer/webui.rb', line 91 def root ROOT end |
#start ⇒ Object
Start the server.
65 66 67 68 69 70 71 72 73 74 |
# File 'lib/indexer/webui.rb', line 65 def start # ensure_site # create required tmp directories if not found # %w(cache pids sessions sockets).each do |dir_to_make| # FileUtils.mkdir_p(File.join(tmp_dir, dir_to_make)) # end ::Rack::Server.start() end |
#tmp_dir ⇒ Object
Temporary directory used by the rack server.
58 59 60 |
# File 'lib/indexer/webui.rb', line 58 def tmp_dir @tmp_dir ||= File.join(Dir.tmpdir, 'indexer', root) end |