class PIM::Services::DataModelLoaders::AbstractFileLoader

Public Class Methods

new(file_extensions:, cached: false) click to toggle source
# File services.rb, line 1695
def initialize file_extensions:, cached: false
  @file_repositories = {}
  @file_extensions = Array(file_extensions)
  @cached = cached
end

Public Instance Methods

close() click to toggle source
# File services.rb, line 1701
def close
  @file_repositories.each do |repository|
    close_repository(repository)
  end
end
get(data_module, request) click to toggle source
# File services.rb, line 1712
def get data_module, request

  repository = get_repository(data_module)
  return nil if repository.nil?

  # Since the FileLoader always is the last loader,
  # we can safely return nil values for non found keys!
  return get_from_repository(repository, request, cached: @cached, return_nil: true)
end
use_next_loader?(data_module) click to toggle source
# File services.rb, line 1707
def use_next_loader? data_module
  # Only use next loader if current loader does not have a repository for the data module
  return !has_repository?(data_module)
end

Protected Instance Methods

close_repository(repository) click to toggle source

Implement in subclass

# File services.rb, line 1751
def close_repository repository
end
get_repository(data_module) click to toggle source
# File services.rb, line 1729
def get_repository data_module

  service_name = get_service_name(data_module)
  return @file_repositories[service_name] if @file_repositories.include?(service_name)

  data_model_definitions_file = get_data_model_definitions_file(data_module, *@file_extensions)
  unless data_model_definitions_file.nil?
    repository = open_repository(data_model_definitions_file)
  end
  @file_repositories[service_name] = repository

  return repository

end
has_repository?(data_module) click to toggle source
# File services.rb, line 1724
def has_repository? data_module
  service_name = get_service_name(data_module)
  return !@file_repositories[service_name].nil?
end
open_repository(filename) click to toggle source

Implement in subclass

# File services.rb, line 1746
def open_repository filename
end