Module: Sinclair::EnvSettable

Extended by:
Settable::ClassMethods
Includes:
Settable
Defined in:
lib/sinclair/env_settable.rb

Overview

Module to be extended allowing configurations from environment

Examples:

class MyAppClient
  extend Sinclair::EnvSettable

  settings_prefix 'MY_APP'

  with_settings :username, :password, host: 'my-host.com'
  setting_with_options :port, type: :integer
end

ENV['MY_APP_USERNAME'] = 'my_login'
ENV['MY_APP_PORT']     = '8080'

MyAppClient.username # returns 'my_login'
MyAppClient.password # returns nil
MyAppClient.host     # returns 'my-host.com'
MyAppClient.port     # returns 8080

Author:

  • darthjee

Instance Method Summary collapse

Methods included from Settable::ClassMethods

read_with

Methods included from Settable

#settable_module, #setting_with_options, #with_settings

Instance Method Details

#settings_prefix(prefix = nil) ⇒ String

Sets environment keys prefix

Examples:

class MyAppClient
  extend Sinclair::EnvSettable

  settings_prefix 'MY_APP'

  with_settings :username, :password, host: 'my-host.com'
  setting_with_options :port, type: :integer
end

ENV['MY_APP_USERNAME'] = 'my_login'
ENV['MY_APP_PORT']     = '8080'

MyAppClient.username # returns 'my_login'
MyAppClient.password # returns nil
MyAppClient.host     # returns 'my-host.com'
MyAppClient.port     # returns 8080

Parameters:

  • prefix (String) (defaults to: nil)

    prefix of the env keys

Returns:

  • (String)


49
50
51
52
53
# File 'lib/sinclair/env_settable.rb', line 49

def settings_prefix(prefix = nil)
  return @settings_prefix || superclass_prefix unless prefix

  @settings_prefix = prefix
end