Class: Embork::Server
- Inherits:
-
Object
- Object
- Embork::Server
- Includes:
- BuildVersions
- Defined in:
- lib/embork/server.rb
Constant Summary
Constants included from BuildVersions
BuildVersions::VERSION_FORMAT_EXP
Instance Attribute Summary collapse
-
#app ⇒ Object
readonly
Returns the value of attribute app.
-
#backend ⇒ Object
readonly
Returns the value of attribute backend.
-
#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
-
#initialize(borkfile, options = {}) ⇒ Server
constructor
A new instance of Server.
- #run ⇒ Object
- #set_backend ⇒ Object
- #setup_bundled_mode ⇒ Object
- #setup_dev_mode ⇒ Object
Methods included from BuildVersions
#sorted_versions, #version_name
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 |
# File 'lib/embork/server.rb', line 17 def initialize(borkfile, = {}) @borkfile = borkfile if .has_key?(:bundle_version) && ![:bundle_version].nil? @bundle_version = [:bundle_version] setup_bundled_mode elsif .has_key?(:with_latest_bundle) && !![:with_latest_bundle] @asset_bundle_version = sorted_versions(@borkfile.project_root).first else setup_dev_mode end @port = [:port] @host = [:host] end |
Instance Attribute Details
#app ⇒ Object (readonly)
Returns the value of attribute app.
14 15 16 |
# File 'lib/embork/server.rb', line 14 def app @app end |
#backend ⇒ Object (readonly)
Returns the value of attribute backend.
11 12 13 |
# File 'lib/embork/server.rb', line 11 def backend @backend end |
#project_root ⇒ Object (readonly)
Returns the value of attribute project_root.
12 13 14 |
# File 'lib/embork/server.rb', line 12 def project_root @project_root end |
#sprockets_environment ⇒ Object (readonly)
Returns the value of attribute sprockets_environment.
13 14 15 |
# File 'lib/embork/server.rb', line 13 def sprockets_environment @sprockets_environment end |
Instance Method Details
#run ⇒ Object
76 77 78 |
# File 'lib/embork/server.rb', line 76 def run Rack::Handler::WEBrick.run @app, :Port => @port, :Host => @host end |
#set_backend ⇒ Object
67 68 69 70 71 72 73 74 |
# File 'lib/embork/server.rb', line 67 def set_backend if @borkfile.backend == :static_index @backend = Embork::Pushstate else Embork::Forwarder.target = @borkfile.backend @backend = Embork::Forwarder end end |
#setup_bundled_mode ⇒ Object
51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 |
# File 'lib/embork/server.rb', line 51 def setup_bundled_mode @project_root = File.join @borkfile.project_root, 'build', Embork.env.to_s set_backend static_directory = @project_root container = self @app = Rack::Builder.new do use container.backend use Rack::Static, :urls => [ '/' ], :root => static_directory # Should never reach here. It just need s an app to run run lambda { |env| [ 200, { 'Content-Type' => 'text/html', }, '' ] } end end |
#setup_dev_mode ⇒ Object
31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 |
# File 'lib/embork/server.rb', line 31 def setup_dev_mode @environment = Embork::Environment.new(@borkfile) @sprockets_environment = @environment.sprockets_environment @project_root = @borkfile.project_root set_backend container = self static_directory = File.join(container.project_root, 'static') @app = Rack::Builder.new do use container.backend use Rack::Static, :urls => [ '/images', '/fonts', ], :root => static_directory map '/' do run container.sprockets_environment end end end |