Class: Embork::Server

Inherits:
Object
  • Object
show all
Includes:
BuildVersions
Defined in:
lib/embork/server.rb

Constant Summary

Constants included from BuildVersions

BuildVersions::VERSION_FORMAT_EXP

Instance Attribute Summary collapse

Instance Method Summary collapse

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, options = {})
  @borkfile = borkfile
  if options.has_key?(:bundle_version) && !options[:bundle_version].nil?
    @bundle_version = options[:bundle_version]
    setup_bundled_mode
  elsif options.has_key?(:with_latest_bundle) && !!options[:with_latest_bundle]
    @asset_bundle_version = sorted_versions(@borkfile.project_root).first
  else
    setup_dev_mode
  end
  @port = options[:port]
  @host = options[:host]
end

Instance Attribute Details

#appObject (readonly)

Returns the value of attribute app.



14
15
16
# File 'lib/embork/server.rb', line 14

def app
  @app
end

#backendObject (readonly)

Returns the value of attribute backend.



11
12
13
# File 'lib/embork/server.rb', line 11

def backend
  @backend
end

#project_rootObject (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_environmentObject (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

#runObject



76
77
78
# File 'lib/embork/server.rb', line 76

def run
  Rack::Handler::WEBrick.run @app, :Port => @port, :Host => @host
end

#set_backendObject



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_modeObject



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_modeObject



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