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.



12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
# File 'lib/machined/server.rb', line 12

def initialize(machined)
  @machined = machined

  if machined.environment.development?
    # Configure watchable files
    files = []
    files << machined.config_path if machined.config_path.exist?

    # Configure watchable dirs
    dirs = {}
    dirs[machined.lib_path.to_s] = [:rb] if machined.lib_path.exist?

    # Setup file watching using ActiveSupport::FileUpdateChecker
    @reloader = ActiveSupport::FileUpdateChecker.new(files, dirs) do
      machined.reload
      reload
    end
  end

  reload
end

Instance Attribute Details

#machinedObject (readonly)

A reference to the Machined environment which created this instance.



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

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.



37
38
39
40
# File 'lib/machined/server.rb', line 37

def call(env)
  @reloader.execute_if_updated if machined.environment.development?
  @app.call(env)
end

#reloadObject

Rebuilds the Rack app with the current Machined configuration.



44
45
46
# File 'lib/machined/server.rb', line 44

def reload
  @app = to_app
end