Class: Embork::Server

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

Direct Known Subclasses

Phrender

Instance Attribute Summary collapse

Instance Method Summary collapse

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, options = {})
  @borkfile = borkfile
  if !options[:bundle_version].nil?
    Embork.bundle_version = options[:bundle_version]
    setup_bundled_mode
  elsif options[:with_latest_bundle]
    Embork.bundle_version = File.read(File.join(borkfile.project_root, Embork.env, current-version))
    setup_bundled_mode
  elsif options[:enable_tests]
    setup_test_mode
  else
    setup_dev_mode
  end
  @disable_logging = options[:disable_logging]
  @port = options[:port]
  @host = options[:host]
end

Instance Attribute Details

#appObject (readonly)

Returns the value of attribute app.



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

def app
  @app
end

#backendObject (readonly)

Returns the value of attribute backend.



9
10
11
# File 'lib/embork/server.rb', line 9

def backend
  @backend
end

#disable_loggingObject (readonly)

Returns the value of attribute disable_logging.



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

def disable_logging
  @disable_logging
end

#hostObject (readonly)

Returns the value of attribute host.



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

def host
  @host
end

#portObject (readonly)

Returns the value of attribute port.



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

def port
  @port
end

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



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_webrickObject



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_modeObject



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_modeObject



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_modeObject



58
59
60
61
# File 'lib/embork/server.rb', line 58

def setup_test_mode
  setup_dev_mode
  @sprockets_environment.prepend_path 'tests'
end