Class: Machined::Server

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

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(machined) ⇒ Server

Creates a new Rack server that will serve up the processed files.



11
12
13
14
15
# File 'lib/machined/server.rb', line 11

def initialize(machined)
  @machined = machined
  @files    = Rack::File.new(machined.output_path)
  remap
end

Instance Attribute Details

#machinedObject (readonly)

A reference to the Machined environment which created this instance.



7
8
9
# File 'lib/machined/server.rb', line 7

def machined
  @machined
end

Instance Method Details

#call(env) ⇒ Object

Using the URLMap, determine which sprocket should handle the request and then…let it handle it.



20
21
22
23
24
25
# File 'lib/machined/server.rb', line 20

def call(env)
  refresh if machined.config.environment == "development"
  response = @url_map.call(env)
  response = @files.call(env) if response.first == 404
  response
end

#remapObject

Remaps the Machined environment’s current sprockets using ‘Rack::URLMap`.



29
30
31
32
33
34
35
36
# File 'lib/machined/server.rb', line 29

def remap
  map = {}
  machined.sprockets.each do |sprocket|
    next unless sprocket.compile?
    map[sprocket.config.url] = sprocket
  end
  @url_map = Rack::URLMap.new map
end