Class: Syntropy::App

Inherits:
Object
  • Object
show all
Defined in:
lib/syntropy/app.rb

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(machine, location, mount_path, opts = {}) ⇒ App

Returns a new instance of App.



35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
# File 'lib/syntropy/app.rb', line 35

def initialize(machine, location, mount_path, opts = {})
  @machine = machine
  @location = File.expand_path(location)
  @mount_path = mount_path
  @opts = opts

  @module_loader = Syntropy::ModuleLoader.new(@location, @opts)
  @router = Syntropy::Router.new(@opts, @module_loader)

  @machine.spin do
    # we do startup stuff asynchronously, in order to first let TP2 do its
    # setup tasks
    @machine.sleep 0.15
    @opts[:logger]&.info(
      message: "Serving from #{File.expand_path(@location)}"
    )
    @router.start_file_watcher if opts[:watch_files]
  end
end

Class Method Details

.load(opts) ⇒ Object



16
17
18
# File 'lib/syntropy/app.rb', line 16

def load(opts)
  site_file_app(opts) || default_app(opts)
end

Instance Method Details

#call(req) ⇒ Object



55
56
57
58
59
60
61
62
63
64
65
# File 'lib/syntropy/app.rb', line 55

def call(req)
  entry = @router[req.path]
  render_entry(req, entry)
rescue Syntropy::Error => e
  msg = e.message
  req.respond(msg.empty? ? nil : msg, ':status' => e.http_status)
rescue StandardError => e
  p e
  p e.backtrace
  req.respond(e.message, ':status' => Qeweney::Status::INTERNAL_SERVER_ERROR)
end