Module: Gruf::Configuration

Included in:
Gruf
Defined in:
lib/gruf/configuration.rb

Overview

Represents configuration settings for the system

Constant Summary collapse

VALID_CONFIG_KEYS =
{
  root_path: '',
  server_binding_url: '0.0.0.0:9001',
  server_options: {},
  interceptors: nil,
  hooks: nil,
  default_channel_credentials: nil,
  default_client_host: '',
  use_ssl: false,
  ssl_crt_file: '',
  ssl_key_file: '',
  controllers_path: '',
  services: [],
  logger: nil,
  grpc_logger: nil,
  error_metadata_key: :'error-internal-bin',
  error_serializer: nil,
  append_server_errors_to_trailing_metadata: true,
  use_default_interceptors: true,
  backtrace_on_error: false,
  backtrace_limit: 10,
  use_exception_message: true,
  internal_error_message: 'Internal Server Error',
  event_listener_proc: nil,
  synchronized_client_internal_cache_expiry: 60,
  rpc_server_options: {
    pool_size: GRPC::RpcServer::DEFAULT_POOL_SIZE,
    max_waiting_requests: GRPC::RpcServer::DEFAULT_MAX_WAITING_REQUESTS,
    poll_period: GRPC::RpcServer::DEFAULT_POLL_PERIOD,
    pool_keep_alive: GRPC::Pool::DEFAULT_KEEP_ALIVE,
    connect_md_proc: nil,
    server_args: {}
  }.freeze
}.freeze

Class Method Summary collapse

Instance Method Summary collapse

Class Method Details

.extended(base) ⇒ Object

Whenever this is extended into a class, setup the defaults



63
64
65
66
67
68
69
# File 'lib/gruf/configuration.rb', line 63

def self.extended(base)
  if defined?(Rails)
    Gruf::Integrations::Rails::Railtie.config.before_initialize { base.reset }
  else
    base.reset
  end
end

Instance Method Details

#configure {|_self| ... } ⇒ Gruf::Configuration

Yield self for ruby-style initialization

Yields:

  • (_self)

Yield Parameters:



77
78
79
# File 'lib/gruf/configuration.rb', line 77

def configure
  yield self
end

#optionsHash

Return the current configuration options as a Hash



86
87
88
89
90
91
92
# File 'lib/gruf/configuration.rb', line 86

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

#resetHash

Set the default configuration onto the extended class



99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
# File 'lib/gruf/configuration.rb', line 99

def reset
  VALID_CONFIG_KEYS.each do |k, v|
    send((k.to_s + '='), v)
  end
  self.interceptors = Gruf::Interceptors::Registry.new
  self.hooks = Gruf::Hooks::Registry.new
  self.root_path = Rails.root.to_s.chomp('/') if defined?(Rails)
  if defined?(Rails) && Rails.logger
    self.logger = Rails.logger
  else
    require 'logger'
    self.logger = ::Logger.new(STDOUT)
  end
  self.grpc_logger = logger if grpc_logger.nil?
  self.ssl_crt_file = "#{root_path}config/ssl/#{environment}.crt"
  self.ssl_key_file = "#{root_path}config/ssl/#{environment}.key"
  self.controllers_path = root_path.to_s.empty? ? 'app/rpc' : "#{root_path}/app/rpc"
  if use_default_interceptors
    interceptors.use(Gruf::Interceptors::ActiveRecord::ConnectionReset)
    interceptors.use(Gruf::Interceptors::Instrumentation::OutputMetadataTimer)
  end
  options
end