Class: Pieces::Server
- Inherits:
-
Rack::Server
- Object
- Rack::Server
- Pieces::Server
- Defined in:
- lib/pieces/server.rb
Instance Attribute Summary collapse
-
#config ⇒ Object
readonly
Returns the value of attribute config.
Class Method Summary collapse
Instance Method Summary collapse
- #app ⇒ Object
-
#initialize(config) ⇒ Server
constructor
A new instance of Server.
- #sprockets_env ⇒ Object
- #start ⇒ Object
Constructor Details
#initialize(config) ⇒ Server
Returns a new instance of Server.
14 15 16 17 |
# File 'lib/pieces/server.rb', line 14 def initialize(config) @config = config super({}) end |
Instance Attribute Details
#config ⇒ Object (readonly)
Returns the value of attribute config.
12 13 14 |
# File 'lib/pieces/server.rb', line 12 def config @config end |
Class Method Details
.start(config = {}) ⇒ Object
8 9 10 |
# File 'lib/pieces/server.rb', line 8 def self.start(config = {}) new(Config.new(config)).start end |
Instance Method Details
#app ⇒ Object
32 33 34 35 36 37 38 39 40 41 42 43 |
# File 'lib/pieces/server.rb', line 32 def app urls = files_to_serve(config.path) build_path = "#{config.path}/build" assets_app = sprockets_env Rack::Builder.app do use Rack::Reloader map('/assets') { run assets_app } unless defined? ::Rails use Rack::Static, urls: [''], root: build_path, index: 'index.html' run Proc.new { |env| [404, {}, ['Not found']] } end end |
#sprockets_env ⇒ Object
24 25 26 27 28 29 30 |
# File 'lib/pieces/server.rb', line 24 def sprockets_env Sprockets::Environment.new(config.path).tap do |env| env.append_path 'app/assets/javascripts' env.append_path 'app/assets/stylesheets' env.append_path 'app/views' end end |
#start ⇒ Object
19 20 21 22 |
# File 'lib/pieces/server.rb', line 19 def start Pieces::Listener.new(config).listen super end |