module RabbotWeb
Constants
- DEFAULT_BIND
- DEFAULT_PORTS
- DEFAULT_ROOT
- ROOT
Public Instance Methods
Source
# File lib/rabbot_web.rb, line 28 def bot_id_from_path(path) File.basename(path.to_s, ".yml") end
Source
# File lib/rabbot_web.rb, line 64 def enabled?(config) config[:enabled] end
Source
# File lib/rabbot_web.rb, line 32 def normalize_config(raw, bot_id:, bot_role:, level:, root: ROOT) web = case raw when nil {} when Hash raw.transform_keys(&:to_s) else raise ConfigError, "web must be a YAML mapping" end resolved_level = BotIdentity.resolve_level(bot_role: bot_role, level: level) enabled = if web.key?("enabled") !!web["enabled"] else resolved_level == RabbotDb::LEVEL_OWNER end { enabled: enabled, bind: resolve_bind(web), port: resolve_port(web, bot_id: bot_id), root: resolve_root(web, root: root), public_base: web["public_base"].to_s.strip, sites: BotSites.normalize( web["sites"], bot_id: bot_id, bot_role: bot_role, level: level ) } end
Source
# File lib/rabbot_web.rb, line 68 def resolve_bind(web) bind = web.fetch("bind", DEFAULT_BIND).to_s.strip bind.empty? ? DEFAULT_BIND : bind end
Source
# File lib/rabbot_web.rb, line 73 def resolve_port(web, bot_id:) return Integer(web["port"]) if web.key?("port") DEFAULT_PORTS.fetch(bot_id.to_s, 8780) rescue ArgumentError, TypeError raise ConfigError, "web.port must be an integer" end
Source
# File lib/rabbot_web.rb, line 81 def resolve_root(web, root:) relative = web.fetch("root", DEFAULT_ROOT).to_s.strip relative = DEFAULT_ROOT if relative.empty? File.expand_path(relative, root) end