Sha256: 97e3b016b85bc6ef7773a9d82dff477a669b77999e0fa4442795fccbc1b34da3
Contents?: true
Size: 1.46 KB
Versions: 28
Compression:
Stored size: 1.46 KB
Contents
# frozen_string_literal: true class Sinclair # @api public # @author darthjee # # Module to be extended allowing configurations from environment # # @example # class MyAppClient # extend Sinclair::EnvSettable # # settings_prefix 'MY_APP' # # with_settings :username, :password, host: 'my-host.com' # end # # ENV['MY_APP_USERNAME'] = 'my_login' # # MyAppClient.username # returns 'my_login' # MyAppClient.password # returns nil # MyAppClient.host # returns 'my-host.com' # # ENV['MY_APP_HOST'] = 'other-host.com' # # MyAppClient.host # returns 'other-host.com' # module EnvSettable autoload :Builder, 'sinclair/env_settable/builder' private # @private # @api public # @visibility public # # Sets environment keys prefix # # @param prefix [String] prefix of the env keys # # @return [String] # # @example (see EnvSettable) def settings_prefix(prefix) @settings_prefix = prefix end # @private # @api public # @visibility public # # Adds settings # # @param settings_name [Array<Symbol,String>] Name of all settings # to be added # @param defaults [Hash] Settings with default values # # @return (see Sinclair#build) # # @example (see EnvSettable) def with_settings(*settings_name, **defaults) Builder.new(self, @settings_prefix, *settings_name, **defaults).build end end end
Version data entries
28 entries across 28 versions & 1 rubygems