class Anyway::Settings
Use Settings
name to not confuse with Config
.
Settings
contain the library-wide configuration.
Attributes
Define whether to load data from *.yml.local (or credentials/local.yml.enc)
A proc returning a path to YML config file given the config name
Define whether to load data from *.yml.local (or credentials/local.yml.enc)
Define whether to load data from *.yml.local (or credentials/local.yml.enc)
Suppress required validations for CI/CD pipelines
Enable source tracing
Define whether to load data from *.yml.local (or credentials/local.yml.enc)
Public Class Methods
Source
# File lib/anyway/rails/settings.rb, line 16 def autoload_static_config_path=(val) if autoload_via_zeitwerk raise "Cannot setup autoloader after application has been initialized" if ::Rails.application.initialized? return unless ::Rails.root.join(val).exist? return if ::Rails.root.join(val.to_s) == ::Rails.root.join(autoload_static_config_path.to_s) autoloader&.unload @autoload_static_config_path = val # See Rails 6 https://github.com/rails/rails/blob/8ab4fd12f18203b83d0f252db96d10731485ff6a/railties/lib/rails/autoloaders.rb#L10 # and Rails 7 https://github.com/rails/rails/blob/5462fbd5de1900c1b1ce1c9dc11c1a2d8cdcd809/railties/lib/rails/autoloaders.rb#L15 @autoloader = Zeitwerk::Loader.new.tap do |loader| loader.tag = "anyway.config" if defined?(ActiveSupport::Dependencies::ZeitwerkIntegration::Inflector) loader.inflector = ActiveSupport::Dependencies::ZeitwerkIntegration::Inflector elsif defined?(::Rails::Autoloaders::Inflector) loader.inflector = ::Rails::Autoloaders::Inflector end loader.push_dir(::Rails.root.join(val)) loader.setup end else if autoload_static_config_path old_path = ::Rails.root.join(autoload_static_config_path).to_s ActiveSupport::Dependencies.autoload_paths.delete(old_path) ::Rails.application.config.eager_load_paths.delete(old_path) end @autoload_static_config_path = val new_path = ::Rails.root.join(val).to_s ActiveSupport::Dependencies.autoload_paths << new_path ::Rails.application.config.eager_load_paths << new_path end end
Source
# File lib/anyway/rails/settings.rb, line 62 def autoload_via_zeitwerk return @autoload_via_zeitwerk if instance_variable_defined?(:@autoload_via_zeitwerk) @autoload_via_zeitwerk = defined?(::Zeitwerk) end
Source
# File lib/anyway/rails/settings.rb, line 55 def cleanup_autoload_paths return unless autoload_via_zeitwerk return unless autoload_static_config_path ActiveSupport::Dependencies.autoload_paths.delete(::Rails.root.join(autoload_static_config_path).to_s) end
Source
# File lib/anyway/rails/settings.rb, line 68 def current_environment @current_environment || ::Rails.env.to_s end
Define whether to load data from *.yml.local (or credentials/local.yml.enc)
Source
# File lib/anyway/settings.rb, line 61 def default_config_path=(val) if val.is_a?(Proc) @default_config_path = val return end val = val.to_s @default_config_path = ->(name) { File.join(val, "#{name}.yml") } end
Source
# File lib/anyway/settings.rb, line 83 def default_environmental_key? !default_environmental_key.nil? end
Source
# File lib/anyway/settings.rb, line 87 def matching_env?(env) return true if env.nil? || env.to_s == current_environment if env.is_a?(::Hash) envs = env[:except] excluded_envs = [*envs].flat_map(&:to_s) excluded_envs.none?(current_environment) elsif env.is_a?(::Array) env.flat_map(&:to_s).include?(current_environment) else false end end