class LittleWeasel::Services::DictionaryLoaderService

This class provides services to load dictionaries from either disk (if the dictionary has not been loaded) or from the dictionary cache if the dictionary has already been loaded from disk.

Public Class Methods

new(dictionary_key:, dictionary_cache:, dictionary_metadata:) click to toggle source
# File lib/LittleWeasel/services/dictionary_loader_service.rb, line 20
def initialize(dictionary_key:, dictionary_cache:, dictionary_metadata:)
  validate_dictionary_key dictionary_key: dictionary_key
  self.dictionary_key = dictionary_key

  validate_dictionary_cache dictionary_cache: dictionary_cache
  self.dictionary_cache = dictionary_cache

  validate_dictionary_metadata dictionary_metadata: dictionary_metadata
  self.dictionary_metadata = dictionary_metadata
end

Public Instance Methods

execute() click to toggle source
# File lib/LittleWeasel/services/dictionary_loader_service.rb, line 31
def execute
  if dictionary_cache_service.dictionary_exists?
    load_from_cache
  else
    dictionary_cache_service.dictionary_object = load_from_disk
  end
end

Private Instance Methods

dictionary_file_loader_service() click to toggle source
# File lib/LittleWeasel/services/dictionary_loader_service.rb, line 54
def dictionary_file_loader_service
  Services::DictionaryFileLoaderService.new dictionary_key: dictionary_key, dictionary_cache: dictionary_cache
end
dictionary_for(dictionary_words:) click to toggle source
# File lib/LittleWeasel/services/dictionary_loader_service.rb, line 49
def dictionary_for(dictionary_words:)
  Dictionary.new dictionary_key: dictionary_key, dictionary_cache: dictionary_cache,
    dictionary_metadata: dictionary_metadata, dictionary_words: dictionary_words
end
load_from_cache() click to toggle source
# File lib/LittleWeasel/services/dictionary_loader_service.rb, line 41
def load_from_cache
  dictionary_cache_service.dictionary_object!
end
load_from_disk() click to toggle source
# File lib/LittleWeasel/services/dictionary_loader_service.rb, line 45
def load_from_disk
  dictionary_for dictionary_words: dictionary_file_loader_service.execute
end