Class: Mobox::Server
- Inherits:
-
Object
- Object
- Mobox::Server
- Defined in:
- lib/mobox/server.rb
Defined Under Namespace
Classes: IndexServer
Instance Method Summary collapse
- #app ⇒ Object
- #assets ⇒ Object
- #index ⇒ Object
-
#initialize(path) ⇒ Server
constructor
A new instance of Server.
- #map(path, &block) ⇒ Object
- #root_path ⇒ Object
- #root_path=(path) ⇒ Object
- #run! ⇒ Object
Constructor Details
#initialize(path) ⇒ Server
Returns a new instance of Server.
14 15 16 17 18 19 20 21 |
# File 'lib/mobox/server.rb', line 14 def initialize(path) root_path = self.root_path = Pathname(path).join('src') assets = self.assets map("/") {run IndexServer.new(root_path)} map("/stylesheets") {run assets} map("/javascripts") {run assets} map("/images") {run assets} end |
Instance Method Details
#app ⇒ Object
27 28 29 |
# File 'lib/mobox/server.rb', line 27 def app @app ||= Rack::Builder.new end |
#assets ⇒ Object
37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 |
# File 'lib/mobox/server.rb', line 37 def assets @assets ||= begin assets = Sprockets::Environment.new(root_path) www_source_root = root_path assets.context_class.instance_eval do include Mobox::Helpers end assets.context_class.const_set :WWW_SOURCE_ROOT, www_source_root assets.append_path(root_path.join('assets')) assets.append_path(root_path.join('assets', 'javascripts')) assets.append_path(root_path.join('assets', 'stylesheets')) assets.append_path(root_path.join('assets', 'images')) assets end end |
#index ⇒ Object
53 54 55 |
# File 'lib/mobox/server.rb', line 53 def index @index ||= IndexServer.new(root_path) end |
#map(path, &block) ⇒ Object
31 32 33 34 35 |
# File 'lib/mobox/server.rb', line 31 def map path, &block app.instance_eval do map path, &block end end |
#root_path ⇒ Object
61 62 63 |
# File 'lib/mobox/server.rb', line 61 def root_path @root_path end |
#root_path=(path) ⇒ Object
57 58 59 |
# File 'lib/mobox/server.rb', line 57 def root_path= path @root_path = Pathname(path.to_s) end |
#run! ⇒ Object
23 24 25 |
# File 'lib/mobox/server.rb', line 23 def run! Thin::Server.start('0.0.0.0', 3000, app) end |