Class: LittleWeasel::Services::DictionaryFileLoaderService

Inherits:
Object
  • Object
show all
Includes:
Modules::Configurable, Modules::DictionaryCacheServicable, Modules::DictionaryFileLoader, Modules::DictionaryKeyable
Defined in:
lib/LittleWeasel/services/dictionary_file_loader_service.rb

Overview

This class provides a service for loading dictionaries from disk and returning a Hash of dictionary words that can be used to instantiate a Dictionary object or otherwise.

Instance Attribute Summary

Attributes included from Modules::DictionaryKeyable

#dictionary_key

Attributes included from Modules::DictionaryCacheServicable

#dictionary_cache, #dictionary_key

Instance Method Summary collapse

Methods included from Modules::DictionaryKeyValidatable

#validate_dictionary_key, validate_dictionary_key

Methods included from Modules::DictionaryFileLoader

#load

Methods included from Modules::DictionaryCacheServicable

#dictionary_cache_service

Methods included from Modules::DictionaryCacheValidatable

#validate_dictionary_cache, validate_dictionary_cache

Methods included from Modules::Configurable

#config, included

Constructor Details

#initialize(dictionary_key:, dictionary_cache:) ⇒ DictionaryFileLoaderService

Returns a new instance of DictionaryFileLoaderService.



19
20
21
22
23
24
25
# File 'lib/LittleWeasel/services/dictionary_file_loader_service.rb', line 19

def initialize(dictionary_key:, dictionary_cache:)
  validate_dictionary_key dictionary_key: dictionary_key
  self.dictionary_key = dictionary_key

  validate_dictionary_cache dictionary_cache: dictionary_cache
  self.dictionary_cache = dictionary_cache
end

Instance Method Details

#executeObject



27
28
29
30
31
32
33
34
# File 'lib/LittleWeasel/services/dictionary_file_loader_service.rb', line 27

def execute
  if dictionary_cache_service.dictionary_exist?
    raise ArgumentError,
      "The dictionary associated with key '#{key}' already exists."
  end

  load dictionary_cache_service.dictionary_file!
end