class Savvy::Configuration

Shared configuration object for a Savvy-enabled application

Constants

APP_ENV_VARS
DEFAULT_REDIS_ENV_VARS
DEFAULT_REDIS_URL

Attributes

app_env[RW]
app_name[R]

@overload app_name

Get the current app name
@return [String]

@overload app_name=(new_app_name)

@param [String, Symbol] new_app_name
@raise [TypeError] if provided with an invalid app name
env[R]
include_app_env[R]

@!attribute [rw] include_app_env Whether the Rails/Rack env should be included when building namespaces. @return [Boolean]

include_app_env?[R]

@!attribute [rw] include_app_env Whether the Rails/Rack env should be included when building namespaces. @return [Boolean]

redis_default_url[R]

@!attribute [rw] redis_default_url @return [String]

redis_env_vars[R]

@overload redis_env_vars

Get the current redis env keys
@return [<String>]

@overload redis_env_vars=(new_env_keys)

@param [<String>] new_env_keys
@raise [TypeError] if not an array of strings.
root[R]

Public Class Methods

new(root:, env: Savvy.env) click to toggle source
# File lib/savvy/configuration.rb, line 28
def initialize(root:, env: Savvy.env)
  @root = root
  @env  = env

  @config_file = find_config_file

  @app_name           = root.basename.to_s
  @include_app_env    = false
  @redis_env_vars     = DEFAULT_REDIS_ENV_VARS.dup
  @redis_default_url  = DEFAULT_REDIS_URL
end

Public Instance Methods

app_name=(new_app_name) click to toggle source
# File lib/savvy/configuration.rb, line 83
def app_name=(new_app_name)
  raise TypeError, "Must provide a string or symbol" unless new_app_name.kind_of?(String) || new_app_name.kind_of?(Symbol)
  raise TypeError, "Must provide a valid app name" unless Dux.presentish?(new_app_name)

  @app_name = new_app_name
end
build_namespace(*parts, prefix: nil, separator: ?.) click to toggle source

Build a namespace that takes environmental and application factors into account.

@param [<String>] parts additional parts that will be suffixed after the generated namespace @param [String] prefix a component that will appear before the savvy-generated namepsace @param [String] separator what separates the components used in the namespace @return [String]

# File lib/savvy/configuration.rb, line 52
def build_namespace(*parts, prefix: nil, separator: ?.)
  [
    prefix,
    app_name,
    ( app_env if include_app_env? ),
    *parts
  ].compact.join(separator)
end
configure() { |to_dsl| ... } click to toggle source
# File lib/savvy/configuration.rb, line 61
def configure
  yield to_dsl if block_given?

  return self
end
include_app_env=(new_value) click to toggle source
# File lib/savvy/configuration.rb, line 98
def include_app_env=(new_value)
  @include_app_env = !!new_value
end
read_from_env(*vars, **options) click to toggle source

@see [Savvy::EnvironmentReader# @return [String]

# File lib/savvy/configuration.rb, line 69
def read_from_env(*vars, **options)
  @env[*vars, **options]
end
redis_default_url=(new_url) click to toggle source
# File lib/savvy/configuration.rb, line 106
def redis_default_url=(new_url)
  raise TypeError, "Must be a redis:// url: `#{new_url.inspect}`" unless Savvy::Utility.valid_url?(new_url, scheme: 'redis')

  @redis_default_url = new_url
end
redis_env_vars=(new_env_keys) click to toggle source
# File lib/savvy/configuration.rb, line 120
def redis_env_vars=(new_env_keys)
  raise TypeError, "Must be an array of strings" unless Savvy::Utility.valid_env_vars?(new_env_keys)

  @redis_env_vars = new_env_keys
end
setup!() click to toggle source
# File lib/savvy/configuration.rb, line 40
def setup!
  @app_env = @env[*APP_ENV_VARS]

  load_from_file!
end

Private Instance Methods

find_config_file() click to toggle source

@return [Pathname]

# File lib/savvy/configuration.rb, line 129
def find_config_file
  Savvy::FILES.each do |file|
    config_path = @root.join(file)

    return config_path if config_path.exist?
  end

  return nil
end
load_from_file!() click to toggle source

@return [void]

# File lib/savvy/configuration.rb, line 140
def load_from_file!
  to_dsl.evaluate_file(@config_file) if @config_file
end
to_dsl() click to toggle source

@return [Savvy::ConfigurationDSL]

# File lib/savvy/configuration.rb, line 145
def to_dsl
  ConfigurationDSL.new self
end