Class: Anyway::Settings

Inherits:
Object
  • Object
show all
Defined in:
lib/anyway/settings.rb,
lib/anyway/rails/settings.rb

Overview

Use Settings name to not confuse with Config.

Settings contain the library-wide configuration.

Defined Under Namespace

Classes: Future

Class Attribute Summary collapse

Class Method Summary collapse

Class Attribute Details

.autoload_static_config_pathObject

Returns the value of attribute autoload_static_config_path.



13
14
15
# File 'lib/anyway/rails/settings.rb', line 13

def autoload_static_config_path
  @autoload_static_config_path
end

.autoload_via_zeitwerkObject



62
63
64
65
66
# 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

.autoloaderObject (readonly)

Returns the value of attribute autoloader.



13
14
15
# File 'lib/anyway/rails/settings.rb', line 13

def autoloader
  @autoloader
end

.current_environmentObject

Define whether to load data from *.yml.local (or credentials/local.yml.enc)



50
51
52
# File 'lib/anyway/settings.rb', line 50

def current_environment
  @current_environment
end

.default_config_pathObject

A proc returning a path to YML config file given the config name



56
57
58
# File 'lib/anyway/settings.rb', line 56

def default_config_path
  @default_config_path
end

.default_environmental_keyObject

Define whether to load data from *.yml.local (or credentials/local.yml.enc)



50
51
52
# File 'lib/anyway/settings.rb', line 50

def default_environmental_key
  @default_environmental_key
end

.known_environmentsObject

Define whether to load data from *.yml.local (or credentials/local.yml.enc)



50
51
52
# File 'lib/anyway/settings.rb', line 50

def known_environments
  @known_environments
end

.tracing_enabledObject

Enable source tracing



70
71
72
# File 'lib/anyway/settings.rb', line 70

def tracing_enabled
  @tracing_enabled
end

.use_local_filesObject

Define whether to load data from *.yml.local (or credentials/local.yml.enc)



50
51
52
# File 'lib/anyway/settings.rb', line 50

def use_local_files
  @use_local_files
end

Class Method Details

.app_rootObject



76
77
78
# File 'lib/anyway/settings.rb', line 76

def app_root
  Pathname.new(Dir.pwd)
end

.cleanup_autoload_pathsObject



55
56
57
58
59
60
# 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

.default_environmental_key?Boolean

Returns:

  • (Boolean)


80
81
82
# File 'lib/anyway/settings.rb', line 80

def default_environmental_key?
  !default_environmental_key.nil?
end

.futureObject



72
73
74
# File 'lib/anyway/settings.rb', line 72

def future
  @future ||= Future.new
end

.matching_env?(env) ⇒ Boolean

Returns:

  • (Boolean)


84
85
86
87
88
89
90
91
92
93
94
95
96
# File 'lib/anyway/settings.rb', line 84

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