require_relative "interceptors/active_record" require 'logger' module Yrpc module Configuration VALID_CONFIG_KEYS = { server_binding_url: '0.0.0.0:9001', interceptors: nil, use_default_interceptors: true, default_client_host: '', controllers_path: 'app/controllers', server_options: {}, services: [], logger:nil, use_ssl: false, }.freeze attr_accessor *VALID_CONFIG_KEYS.keys def self.extended(base) base.reset end def configure yield self end def options opts = {} VALID_CONFIG_KEYS.each_key do |k| opts.merge!(k => send(k)) end opts end #重制一些配置 def reset VALID_CONFIG_KEYS.each do |k, v| send((k.to_s + '='), v) end self.logger = ::Logger.new(STDOUT) self.interceptors = Yrpc::Interceptors::Registry.new if use_default_interceptors interceptors.use(Yrpc::Interceptors::ActiveRecord::ResetConnection) end options end end end