Class: ZAssets::Server
- Inherits:
-
Object
- Object
- ZAssets::Server
- Defined in:
- lib/zassets/server.rb
Instance Method Summary collapse
- #app ⇒ Object
- #handler ⇒ Object
-
#initialize(config) ⇒ Server
constructor
A new instance of Server.
- #options ⇒ Object
- #run ⇒ Object
Constructor Details
#initialize(config) ⇒ Server
Returns a new instance of Server.
5 6 7 |
# File 'lib/zassets/server.rb', line 5 def initialize(config) @config = config end |
Instance Method Details
#app ⇒ Object
29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 |
# File 'lib/zassets/server.rb', line 29 def app config = @config @app ||= Rack::Builder.app do use Rack::CommonLogger use Rack::ShowExceptions use Rack::Lint map config[:base_url] do run SprocketsEnv.new(config) end map '/' do static_files = Rack::File.new config[:public_path] if config[:public_file] run Rack::Cascade.new([ static_files, MemoryFile.new(File.new(File.join( config[:public_path], config[:public_file] ))) ]) else run static_files end end end end |
#handler ⇒ Object
17 18 19 |
# File 'lib/zassets/server.rb', line 17 def handler Rack::Handler.get(@config[:server]) || Rack::Handler.default end |
#options ⇒ Object
21 22 23 24 25 26 27 |
# File 'lib/zassets/server.rb', line 21 def @options ||= { environment: :development, Host: @config[:host], Port: @config[:port] } end |
#run ⇒ Object
9 10 11 12 13 14 15 |
# File 'lib/zassets/server.rb', line 9 def run handler.run app, do |server| [:INT, :TERM].each do |sig| trap(sig) { server.respond_to?(:stop!) ? server.stop! : server.stop } end end end |