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', authentication_options: {}, instrumentation_options: {}, hook_options: {}, default_client_host: '', use_ssl: false, ssl_crt_file: '', ssl_key_file: '', servers_path: '', services: [], logger: nil, grpc_logger: nil, error_metadata_key: :'error-internal-bin', error_serializer: nil, authorization_metadata_key: 'authorization', append_server_errors_to_trailing_metadata: true, use_default_hooks: true, backtrace_on_error: false, use_exception_message: true, internal_error_message: 'Internal Server Error' }.freeze
Class Method Summary collapse
-
.extended(base) ⇒ Object
Whenever this is extended into a class, setup the defaults.
Instance Method Summary collapse
-
#configure {|_self| ... } ⇒ Gruf::Configuration
Yield self for ruby-style initialization.
-
#options ⇒ Hash
Return the current configuration options as a Hash.
-
#reset ⇒ Hash
Set the default configuration onto the extended class.
Class Method Details
.extended(base) ⇒ Object
Whenever this is extended into a class, setup the defaults
51 52 53 |
# File 'lib/gruf/configuration.rb', line 51 def self.extended(base) base.reset end |
Instance Method Details
#configure {|_self| ... } ⇒ Gruf::Configuration
Yield self for ruby-style initialization
61 62 63 |
# File 'lib/gruf/configuration.rb', line 61 def configure yield self end |
#options ⇒ Hash
Return the current configuration options as a Hash
70 71 72 73 74 75 76 |
# File 'lib/gruf/configuration.rb', line 70 def opts = {} VALID_CONFIG_KEYS.each do |k, _v| opts.merge!(k => send(k)) end opts end |
#reset ⇒ Hash
Set the default configuration onto the extended class
83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 |
# File 'lib/gruf/configuration.rb', line 83 def reset VALID_CONFIG_KEYS.each do |k, v| send((k.to_s + '='), v) end if defined?(Rails) && Rails.logger self.root_path = Rails.root 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.servers_path = "#{root_path}/app/rpc" self. = { credentials: [{ username: 'grpc', password: 'magic' }] } if use_default_hooks Gruf::Hooks::Registry.add(:ar_connection_reset, Gruf::Hooks::ActiveRecord::ConnectionReset) Gruf::Instrumentation::Registry.add(:output_metadata_timer, Gruf::Instrumentation::OutputMetadataTimer) Gruf::Instrumentation::Registry.add(:request_logging, Gruf::Instrumentation::RequestLogging::Hook) end end |