Module: Yrpc::Configuration

Included in:
Yrpc
Defined in:
lib/yrpc/configuration.rb

Constant Summary collapse

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

Class Method Summary collapse

Instance Method Summary collapse

Class Method Details

.extended(base) ⇒ Object



19
20
21
# File 'lib/yrpc/configuration.rb', line 19

def self.extended(base)
  base.reset
end

Instance Method Details

#configure {|_self| ... } ⇒ Object

Yields:

  • (_self)

Yield Parameters:



23
24
25
# File 'lib/yrpc/configuration.rb', line 23

def configure
  yield self
end

#optionsObject



27
28
29
30
31
32
33
# File 'lib/yrpc/configuration.rb', line 27

def options
  opts = {}
  VALID_CONFIG_KEYS.each_key do |k|
    opts.merge!(k => send(k))
  end
  opts
end

#resetObject

重制一些配置



36
37
38
39
40
41
42
43
44
45
46
# File 'lib/yrpc/configuration.rb', line 36

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