Module: Syntropy

Extended by:
Utilities
Defined in:
lib/syntropy.rb,
lib/syntropy/app.rb,
lib/syntropy/test.rb,
lib/syntropy/utils.rb,
lib/syntropy/errors.rb,
lib/syntropy/logger.rb,
lib/syntropy/request.rb,
lib/syntropy/session.rb,
lib/syntropy/version.rb,
lib/syntropy/db/store.rb,
lib/syntropy/json_api.rb,
lib/syntropy/markdown.rb,
lib/syntropy/side_run.rb,
lib/syntropy/db/schema.rb,
lib/syntropy/mime_types.rb,
lib/syntropy/http/client.rb,
lib/syntropy/http/server.rb,
lib/syntropy/http/status.rb,
lib/syntropy/routing_tree.rb,
lib/syntropy/module_loader.rb,
lib/syntropy/request/response.rb,
lib/syntropy/db/connection_pool.rb,
lib/syntropy/http/io_extensions.rb,
lib/syntropy/request/validation.rb,
lib/syntropy/request/mock_adapter.rb,
lib/syntropy/request/request_info.rb,
lib/syntropy/http/client_connection.rb,
lib/syntropy/http/server_connection.rb

Overview

Syntropy is a web framework for building web apps in Ruby. Syntropy uses UringMachine for I/O and concurrency, and provides a comprehensive and flexible solution for writing web apps with minimal boilerplate.

Defined Under Namespace

Modules: DB, HTTP, Markdown, MimeTypes, RequestInfoClassMethods, RequestInfoMethods, RequestValidationMethods, ResponseMethods, SideRun, TestRequestExtensions, Utilities Classes: App, BadRequestError, Error, Flash, InvalidRequestContentTypeError, JSONAPI, Logger, MockAdapter, Module, ModuleLoader, NowFlash, ProtocolError, Request, RoutingTree, Session, Test, TestHarness, UnsupportedHTTPVersionError, ValidationError

Constant Summary collapse

VERSION =
'0.34.1'

Constants included from Utilities

Utilities::BUILTIN_APPLET_app_root

Class Attribute Summary collapse

Class Method Summary collapse

Methods included from Utilities

app, builtin_applet, page_list, route_by_host, tmp_path

Class Attribute Details

.dev_modeObject

Returns the value of attribute dev_mode.



32
33
34
# File 'lib/syntropy.rb', line 32

def dev_mode
  @dev_mode
end

.machineObject

Returns the value of attribute machine.



32
33
34
# File 'lib/syntropy.rb', line 32

def machine
  @machine
end

Class Method Details

.load_config(env) ⇒ Object



80
81
82
83
84
85
86
87
88
89
90
91
# File 'lib/syntropy.rb', line 80

def load_config(env)
  return if !env[:config_root]

  loader_env = env.merge(
    app_root: env[:config_root],
    logger: nil
  )
  loader = ModuleLoader.new(loader_env)
  config = loader.load(env[:mode])

  env[:config] = config
end

.run(env = {}, &app) ⇒ void

This method returns an undefined value.

Runs a web app with the given environment hash. The given block is either an instance of Syntropy::App, or a Proc/callable that takes a request as argument.

Parameters:

  • env (Hash) (defaults to: {})

    environment



50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
# File 'lib/syntropy.rb', line 50

def run(env = {}, &app)
  if @in_run
    @env = env
    @env[:app] = app if app
    return
  end

  env ||= @env || {}
  begin
    @in_run = true
    machine = env[:machine] || UM.new

    if (logger = env[:logger])
      logger.info(
        message: "Syntropy #{Syntropy::VERSION}, UringMachine #{UM::VERSION}, Ruby #{RUBY_VERSION}"
      )
      logger.info(
        message: "Running in #{env[:mode]} mode"
      )
    end

    server = HTTP::Server.new(machine, env, &app)

    setup_signal_handling(machine, Fiber.current)
    server.run
  ensure
    @in_run = false
  end
end

.side_run(&block) ⇒ any

Runs the given block on a separate thread. Use this method for running code that is not fiber-aware (i.e. does not use UringMachine).

Returns:

  • (any)

    operation return value



38
39
40
41
42
# File 'lib/syntropy.rb', line 38

def side_run(&block)
  raise 'Syntropy.machine not set' if !@machine

  SideRun.call(@machine, &block)
end