Class: Settings

Inherits:
Object
  • Object
show all
Defined in:
config/initializers/settings.rb

Overview

Global setting object loaded from ‘config/settings/environment.yml` which is generated on running `rake config:generate`

Class Method Summary collapse

Class Method Details

.configuration_filenameObject



9
10
11
# File 'config/initializers/settings.rb', line 9

def configuration_filename
  Rails.root.join('config', 'settings', "#{Rails.env}.yml")
end

.instanceObject

rubocop:todo Metrics/AbcSize



14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
# File 'config/initializers/settings.rb', line 14

def instance # rubocop:todo Metrics/AbcSize
  return @instance if @instance.present?

  # Ideally we'd do Hashie::Mash.load(File.read(configuration_filename)) here
  # but the creates an immutable setting object that messes with tests.
  # Immutability is good here though, so we should probably fix that.
  # Added flag onto safe_load to allow read of anchors (aliases) in yml files.
  config_file_descriptor = File.open(configuration_filename, 'r:bom|utf-8')
  @instance = Hashie::Mash.new(YAML.safe_load(config_file_descriptor, permitted_classes: [Symbol], aliases: true))

  # To view a list of pipeline groups and respective pipelines:
  # e.g. Settings.pipelines.group_by(&:pipeline_group).transform_values { |pipelines| pipelines.map(&:name) }
  @instance.pipelines = ConfigLoader::PipelinesLoader.new.pipelines

  @instance
rescue Errno::ENOENT
  # This before we've fully initialized and is intended to report issues to
  # the user.
  # rubocop:disable Style/StderrPuts
  star_length = [96, 12 + configuration_filename.to_s.length].max
  $stderr.puts('*' * star_length)
  $stderr.puts "WARNING! No #{configuration_filename}"
  $stderr.puts "You need to run 'rake config:generate' and can ignore this message if that's what you are doing!"
  $stderr.puts('*' * star_length)
  # rubocop:enable Style/StderrPuts
end

.reinitializeObject



43
44
45
46
# File 'config/initializers/settings.rb', line 43

def reinitialize
  @instance = nil
  self
end