Class: Embork::Server
- Inherits:
-
Object
- Object
- Embork::Server
- Defined in:
- lib/embork/server.rb
Direct Known Subclasses
Instance Attribute Summary collapse
-
#app ⇒ Object
readonly
Returns the value of attribute app.
-
#backend ⇒ Object
readonly
Returns the value of attribute backend.
-
#disable_logging ⇒ Object
readonly
Returns the value of attribute disable_logging.
-
#host ⇒ Object
readonly
Returns the value of attribute host.
-
#port ⇒ Object
readonly
Returns the value of attribute port.
-
#project_root ⇒ Object
readonly
Returns the value of attribute project_root.
-
#sprockets_environment ⇒ Object
readonly
Returns the value of attribute sprockets_environment.
Instance Method Summary collapse
- #build_app ⇒ Object
-
#initialize(borkfile, options = {}) ⇒ Server
constructor
A new instance of Server.
- #run_webrick ⇒ Object
- #setup_bundled_mode ⇒ Object
- #setup_dev_mode ⇒ Object
- #setup_test_mode ⇒ Object
Constructor Details
#initialize(borkfile, options = {}) ⇒ Server
Returns a new instance of Server.
17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 |
# File 'lib/embork/server.rb', line 17 def initialize(borkfile, = {}) @borkfile = borkfile if ![:bundle_version].nil? Embork.bundle_version = [:bundle_version] setup_bundled_mode elsif [:with_latest_bundle] Embork.bundle_version = File.read(File.join(borkfile.project_root, Embork.env, current-version)) setup_bundled_mode elsif [:enable_tests] setup_test_mode else setup_dev_mode end @disable_logging = [:disable_logging] @port = [:port] @host = [:host] end |
Instance Attribute Details
#app ⇒ Object (readonly)
Returns the value of attribute app.
15 16 17 |
# File 'lib/embork/server.rb', line 15 def app @app end |
#backend ⇒ Object (readonly)
Returns the value of attribute backend.
9 10 11 |
# File 'lib/embork/server.rb', line 9 def backend @backend end |
#disable_logging ⇒ Object (readonly)
Returns the value of attribute disable_logging.
14 15 16 |
# File 'lib/embork/server.rb', line 14 def disable_logging @disable_logging end |
#host ⇒ Object (readonly)
Returns the value of attribute host.
13 14 15 |
# File 'lib/embork/server.rb', line 13 def host @host end |
#port ⇒ Object (readonly)
Returns the value of attribute port.
12 13 14 |
# File 'lib/embork/server.rb', line 12 def port @port end |
#project_root ⇒ Object (readonly)
Returns the value of attribute project_root.
10 11 12 |
# File 'lib/embork/server.rb', line 10 def project_root @project_root end |
#sprockets_environment ⇒ Object (readonly)
Returns the value of attribute sprockets_environment.
11 12 13 |
# File 'lib/embork/server.rb', line 11 def sprockets_environment @sprockets_environment end |
Instance Method Details
#build_app ⇒ Object
63 64 65 66 67 68 69 70 71 72 73 74 75 |
# File 'lib/embork/server.rb', line 63 def build_app if @borkfile.backend == :static_index backend = Embork::Pushstate else Embork::Forwarder.target = @borkfile.backend backend = Embork::Forwarder end cascade_apps = @cascade_apps Rack::Builder.new do use backend run Rack::Cascade.new(cascade_apps) end end |
#run_webrick ⇒ Object
77 78 79 80 81 82 83 84 85 86 87 |
# File 'lib/embork/server.rb', line 77 def run_webrick opts = { :Port => @port, :Host => @host } if @disable_logging opts[:Logger] = WEBrick::Log.new("/dev/null") opts[:AccessLog] = [] end Rack::Handler::WEBrick.run @app, opts end |
#setup_bundled_mode ⇒ Object
49 50 51 52 53 54 55 56 |
# File 'lib/embork/server.rb', line 49 def setup_bundled_mode @project_root = File.join @borkfile.project_root, 'build', Embork.env.to_s static_directory = @project_root @cascade_apps = [ Rack::File.new(static_directory) ] @app = build_app end |
#setup_dev_mode ⇒ Object
35 36 37 38 39 40 41 42 43 44 45 46 47 |
# File 'lib/embork/server.rb', line 35 def setup_dev_mode @environment = Embork::Environment.new(@borkfile) @sprockets_environment = @environment.sprockets_environment @project_root = @borkfile.project_root static_directory = File.join(project_root, 'static') @cascade_apps = [ @sprockets_environment, Rack::File.new(static_directory) ] @app = build_app end |
#setup_test_mode ⇒ Object
58 59 60 61 |
# File 'lib/embork/server.rb', line 58 def setup_test_mode setup_dev_mode @sprockets_environment.prepend_path 'tests' end |