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

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

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

Returns a new instance of ConfigLoader.



23
24
25
26
27
28
29
30
31
# File 'lib/djin/config_loader.rb', line 23

def initialize(template_file_path, context_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 }
  @context_config = context_config
end

Class Method Details

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



19
20
21
# File 'lib/djin/config_loader.rb', line 19

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

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



13
14
15
16
17
# File 'lib/djin/config_loader.rb', line 13

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

Instance Method Details

#load!Object



33
34
35
36
37
38
# File 'lib/djin/config_loader.rb', line 33

def load!
  validate_version!
  validate_missing_config!

  file_config
end