Class: Djin::ConfigLoader

Inherits:
Object
  • Object
show all
Defined in:
lib/djin/config_loader.rb

Overview

rubocop:disable Metrics/ClassLength

Constant Summary collapse

RESERVED_WORDS =
%w[djin_version variables tasks include].freeze
FileNotFoundError =

Change Base Error

Class.new(Interpreter::InvalidConfigurationError)

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(template_file_path, runtime_config: {}, base_directory: '.') ⇒ ConfigLoader

Returns a new instance of ConfigLoader.



26
27
28
29
30
31
32
33
34
# File 'lib/djin/config_loader.rb', line 26

def initialize(template_file_path, runtime_config: {}, base_directory: '.')
  @base_directory = Pathname.new(base_directory)
  @template_file = @base_directory.join(template_file_path)

  file_not_found!(@template_file) unless @template_file.exist?

  @template_file_content = Djin.cache.fetch(@template_file.realpath.to_s) { @template_file.read }
  @runtime_config = runtime_config
end

Class Method Details

.load!(template_file_path, runtime_config: {}, base_directory: '.') ⇒ Object



22
23
24
# File 'lib/djin/config_loader.rb', line 22

def self.load!(template_file_path, runtime_config: {}, base_directory: '.')
  new(template_file_path, runtime_config: runtime_config, base_directory: base_directory).load!
end

.load_files!(*files, runtime_config: {}, base_directory: '.') ⇒ Object



16
17
18
19
20
# File 'lib/djin/config_loader.rb', line 16

def self.load_files!(*files, runtime_config: {}, base_directory: '.')
  files.map do |file_path|
    ConfigLoader.load!(file_path, runtime_config: runtime_config, base_directory: base_directory)
  end&.reduce(:deep_merge)
end

Instance Method Details

#load!Object



36
37
38
39
40
41
# File 'lib/djin/config_loader.rb', line 36

def load!
  validate_version!
  validate_missing_config!

  file_config
end