Class: Async::Matrix::ApplicationService::Config
- Inherits:
-
Object
- Object
- Async::Matrix::ApplicationService::Config
- Extended by:
- Forwardable
- Defined in:
- lib/async/matrix/application_service/config.rb,
lib/async/matrix/application_service/config/vivify.rb
Overview
Loads, validates, and provides dot-notation access to a mautrix bridgev2-compatible YAML configuration file.
The full schema mirrors the Go structs defined in mautrix/go v0.27.0 bridgev2/bridgeconfig — split across multiple JSON Schema files under config/schema/ and composed at runtime via $ref.
Validated config data is exposed through Vivify-enhanced hashes, giving natural dot-notation access to every nested field:
config = Config.load("bridge.yml")
config.homeserver.address # => "http://synapse:8008"
config.homeserver.domain # => "localhost"
config.appservice.as_token # => "secret..."
config.appservice.bot.username # => "bot"
config.bot_mxid # => "@bot:localhost"
Defined Under Namespace
Modules: Vivify
Constant Summary collapse
- SCHEMA_DIR =
Pathname.new(__dir__).join("config", "schema").freeze
Class Method Summary collapse
-
.load(path) ⇒ Object
Load and validate a YAML config file from disk.
-
.schema ⇒ Object
—————————————————————— Schema loading & validation ——————————————————————.
- .validate!(data) ⇒ Object
Instance Method Summary collapse
-
#bot_mxid ⇒ Object
Convenience: derive the bot’s full Matrix ID from appservice.bot.username + homeserver.domain.
-
#initialize(data) ⇒ Config
constructor
A new instance of Config.
Constructor Details
#initialize(data) ⇒ Config
Returns a new instance of Config.
46 47 48 49 |
# File 'lib/async/matrix/application_service/config.rb', line 46 def initialize(data) self.class.validate!(data) @data = Vivify.deep_vivify(data) end |
Class Method Details
.load(path) ⇒ Object
Load and validate a YAML config file from disk.
52 53 54 55 56 57 58 59 |
# File 'lib/async/matrix/application_service/config.rb', line 52 def self.load(path) raise Async::Matrix::NotFoundError.new( "M_NOT_FOUND", "Config not found: #{path}" ) unless File.exist?(path) data = YAML.safe_load_file(path, permitted_classes: [Symbol]) new(data) end |
.schema ⇒ Object
Schema loading & validation
71 72 73 74 75 76 |
# File 'lib/async/matrix/application_service/config.rb', line 71 def self.schema @schema ||= JSONSchemer.schema( SCHEMA_DIR.join("config.json"), insert_property_defaults: true ) end |
.validate!(data) ⇒ Object
78 79 80 81 82 83 84 85 86 |
# File 'lib/async/matrix/application_service/config.rb', line 78 def self.validate!(data) errors = schema.validate(data).to_a return if errors.empty? = errors.map { |e| e["error"] }.join("; ") raise Async::Matrix::BadJsonError.new( "M_BAD_JSON", "Config validation failed: #{}" ) end |
Instance Method Details
#bot_mxid ⇒ Object
Convenience: derive the bot’s full Matrix ID from appservice.bot.username + homeserver.domain.
63 64 65 |
# File 'lib/async/matrix/application_service/config.rb', line 63 def bot_mxid "@#{appservice.bot.username}:#{homeserver.domain}" end |