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

Instance Method Summary collapse

Class Attribute Details

.autoload_static_config_pathObject (readonly)

Returns the value of attribute autoload_static_config_path.



17
18
19
# File 'lib/anyway/rails/settings.rb', line 17

def autoload_static_config_path
  @autoload_static_config_path
end

.autoloaderObject (readonly)

Returns the value of attribute autoloader.



17
18
19
# File 'lib/anyway/rails/settings.rb', line 17

def autoloader
  @autoloader
end

.default_config_pathObject

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



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

def default_config_path
  @default_config_path
end

.known_environmentsObject

Returns the value of attribute known_environments.



18
19
20
# File 'lib/anyway/rails/settings.rb', line 18

def known_environments
  @known_environments
end

.tracing_enabledObject

Enable source tracing



63
64
65
# File 'lib/anyway/settings.rb', line 63

def tracing_enabled
  @tracing_enabled
end

.use_local_filesObject

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



46
47
48
# File 'lib/anyway/settings.rb', line 46

def use_local_files
  @use_local_files
end

Class Method Details

.futureObject



65
66
67
# File 'lib/anyway/settings.rb', line 65

def future
  @future ||= Future.new
end

Instance Method Details

#autoload_static_config_path=(val) ⇒ Object



21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
# File 'lib/anyway/rails/settings.rb', line 21

def autoload_static_config_path=(val)
  raise "Cannot setup autoloader after application has been initialized" if ::Rails.application.initialized?

  return unless ::Rails.root.join(val).exist?

  autoloader&.unload

  @autoload_static_config_path = val

  # See https://github.com/rails/rails/blob/8ab4fd12f18203b83d0f252db96d10731485ff6a/railties/lib/rails/autoloaders.rb#L10
  @autoloader = Zeitwerk::Loader.new.tap do |loader|
    loader.tag = "anyway.config"
    loader.inflector = ActiveSupport::Dependencies::ZeitwerkIntegration::Inflector
    loader.push_dir(::Rails.root.join(val))
    loader.setup
  end
end

#cleanup_autoload_pathsObject



39
40
41
42
# File 'lib/anyway/rails/settings.rb', line 39

def cleanup_autoload_paths
  return unless autoload_static_config_path
  ActiveSupport::Dependencies.autoload_paths.delete(::Rails.root.join(autoload_static_config_path).to_s)
end