Sha256: 1ed6de7e581f25d2c948b19e6e38a483bb3b705efa18e5f0770e0086bd995165

Contents?: true

Size: 1.04 KB

Versions: 2

Compression:

Stored size: 1.04 KB

Contents

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

Version data entries

2 entries across 2 versions & 1 rubygems

Version Path
ampedxx-yrpc-0.1.6 lib/yrpc/configuration.rb
ampedxx-yrpc-0.1.4 lib/yrpc/configuration.rb