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.

Class Attribute Summary collapse

Instance Method Summary collapse

Class Attribute Details

.autoload_static_config_pathObject (readonly)

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

.autoloaderObject (readonly)

Returns the value of attribute autoloader.



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

def autoloader
  @autoloader
end

.default_config_pathObject

Return a path to YML config file given the config name



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

def default_config_path
  @default_config_path
end

.tracing_enabledObject

Enable source tracing



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

def tracing_enabled
  @tracing_enabled
end

.use_local_filesObject

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



11
12
13
# File 'lib/anyway/settings.rb', line 11

def use_local_files
  @use_local_files
end

Instance Method Details

#autoload_static_config_path=(val) ⇒ Object



16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
# File 'lib/anyway/rails/settings.rb', line 16

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



34
35
36
37
# File 'lib/anyway/rails/settings.rb', line 34

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