class Savvy::Configuration
Shared configuration object for a Savvy-enabled application
Constants
- APP_ENV_VARS
- DEFAULT_REDIS_ENV_VARS
- DEFAULT_REDIS_URL
Attributes
@!attribute [rw] include_app_env
Whether the Rails/Rack env should be included when building namespaces. @return [Boolean]
@!attribute [rw] include_app_env
Whether the Rails/Rack env should be included when building namespaces. @return [Boolean]
@!attribute [rw] redis_default_url
@return [String]
@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.
Public Class Methods
# 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
# 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 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
# File lib/savvy/configuration.rb, line 61 def configure yield to_dsl if block_given? return self end
# File lib/savvy/configuration.rb, line 98 def include_app_env=(new_value) @include_app_env = !!new_value end
@see [Savvy::EnvironmentReader# @return [String]
# File lib/savvy/configuration.rb, line 69 def read_from_env(*vars, **options) @env[*vars, **options] end
# 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
# 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
# File lib/savvy/configuration.rb, line 40 def setup! @app_env = @env[*APP_ENV_VARS] load_from_file! end
Private Instance Methods
@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
@return [void]
# File lib/savvy/configuration.rb, line 140 def load_from_file! to_dsl.evaluate_file(@config_file) if @config_file end
@return [Savvy::ConfigurationDSL]
# File lib/savvy/configuration.rb, line 145 def to_dsl ConfigurationDSL.new self end