Module: Monk

Defined in:
lib/monk.rb,
lib/monk/log.rb,
lib/monk/auth.rb,
lib/monk/base.rb,
lib/monk/jobs.rb,
lib/monk/live.rb,
lib/monk/mail.rb,
lib/monk/views.rb,
lib/monk/assets.rb,
lib/monk/errors.rb,
lib/monk/context.rb,
lib/monk/version.rb,
lib/monk/jobs/job.rb,
lib/monk/mail/url.rb,
lib/monk/scaffold.rb,
lib/monk/settings.rb,
lib/monk/jobs/args.rb,
lib/monk/mail/mime.rb,
lib/monk/websocket.rb,
lib/monk/jobs/claim.rb,
lib/monk/mail/later.rb,
lib/monk/auth/errors.rb,
lib/monk/environment.rb,
lib/monk/jobs/errors.rb,
lib/monk/jobs/worker.rb,
lib/monk/live/errors.rb,
lib/monk/live/policy.rb,
lib/monk/mail/errors.rb,
lib/monk/persistence.rb,
lib/monk/auth/helpers.rb,
lib/monk/auth/session.rb,
lib/monk/freeze_hooks.rb,
lib/monk/jobs/runtime.rb,
lib/monk/live/helpers.rb,
lib/monk/live/session.rb,
lib/monk/mail/address.rb,
lib/monk/mail/message.rb,
lib/monk/state_ractor.rb,
lib/monk/live/envelope.rb,
lib/monk/live/renderer.rb,
lib/monk/live/publisher.rb,
lib/monk/persistence/pg.rb,
lib/monk/mail/transports.rb,
lib/monk/websocket/frame.rb,
lib/monk/auth/login_token.rb,
lib/monk/jobs/adapters/pg.rb,
lib/monk/websocket/errors.rb,
lib/monk/websocket/server.rb,
lib/monk/auth/rate_limiter.rb,
lib/monk/persistence/model.rb,
lib/monk/persistence/errors.rb,
lib/monk/websocket/registry.rb,
lib/monk/websocket/handshake.rb,
lib/monk/websocket/pg_fanout.rb,
lib/monk/persistence/pg/model.rb,
lib/monk/websocket/connection.rb,
lib/monk/persistence/pg/errors.rb,
lib/monk/websocket/redis_fanout.rb,
lib/monk/persistence/pg/migrator.rb

Overview

Opt-in, like Monk::Persistence backends and Monk::Auth: require "monk/websocket" explicitly. require "monk" alone must not load this (docs/history/plan-websocket.md Decision 7).

Defined Under Namespace

Modules: Assets, Auth, Jobs, Live, Log, Mail, Persistence, Settings, Views, WebSocket Classes: AmbiguousLiveTransportError, AuthNotConfiguredError, Base, Context, DuplicateSettingError, Environment, InvalidLogLevelError, InvalidMonkEnvError, InvalidRedirectError, Job, MalformedMigrationError, MissingAuthConfigError, MissingAuthDeliveryError, MissingSettingError, PersistenceTimeoutError, Scaffold, ScaffoldExistsError, SettingsFrozenError, StateRactor, TemplateNotFoundError, TemplateSyntaxError, UnknownPersistenceError, UnknownSettingError, UnshareableBlockError, UnshareableModelError, UnshareableRouteError

Constant Summary collapse

VERSION =

Frozen, not just a plain literal: reading a String constant from a non-main Ractor raises Ractor::IsolationError unless it's shareable, and a frozen String with no unshareable ivars qualifies -- the same class of bug .freeze! guards against for routes/error handlers/models, just on a top-level constant that every worker Ractor reads on boot (found live under kino: GET /hello 500'd until this was frozen).

"0.18.0".freeze

Class Method Summary collapse

Class Method Details

.boot(app) ⇒ Object



19
20
21
22
23
24
25
26
27
28
29
30
31
# File 'lib/monk.rb', line 19

def self.boot(app)
  app.freeze!

  app_class = app.is_a?(Class) ? app : app.class
  parts = ['', "Monk #{VERSION} plays!", " - env=#{env}", " - routes=#{app_class.routes.size}"]
  parts << " - auth=on" if defined?(Auth) && Auth.config
  backends = persistence_backends
  parts << " - persistence=#{backends.join(",")}" unless backends.empty?
  parts << "\n"

  $stdout.puts parts.join("\n")
  app
end

.env ⇒ Object



47
48
49
# File 'lib/monk/environment.rb', line 47

def self.env
  Environment.new(Settings[:monk_env])
end

.freeze! ⇒ Object

Extracted out of Base#freeze! (docs/history/plan-websocket.md Phase 5 step 20): Monk::Base.freeze! calls this, but so can any process that never touches Monk::Base at all -- Monk::WebSocket::Server's boot script, per Decision 1 -- and still needs Monk::Auth/Monk::Persistence config readable from a worker Ractor. Without this, that config stays an unfrozen Hash, and the first Monk::Auth.verify call from inside a connection Ractor raises Ractor::IsolationError -- the same bug class already hit and fixed for persistence (Phase 4/5) and for Base-booted auth (docs/history/plan-auth.md Phase 5 step 17).



19
20
21
22
# File 'lib/monk/freeze_hooks.rb', line 19

def self.freeze!
  freeze_hooks.each(&:freeze_registry!)
  Persistence::Model.freeze_all!
end

.freeze_hooks ⇒ Object

Objects responding to #freeze_registry! that Base#freeze! (Seam B) must seal at boot, so a worker Ractor can read their config without tripping Ractor::IsolationError. Not persistence-specific: Monk::Persistence:: Registry backends and Monk::Auth both register themselves here.



6
7
8
# File 'lib/monk/freeze_hooks.rb', line 6

def self.freeze_hooks
  @freeze_hooks ||= []
end