Module: LittleWeasel::Metadata::Metadatable

Included in:
DictionaryMetadata, MetadataObserverable
Defined in:
lib/LittleWeasel/metadata/metadatable.rb

Overview

This module defines methods to support objects that manage other objects that manage metadata related to a dictionary/ies. rubocop: disable Lint/UnusedMethodArgument, ignored - Methods in this

module need to keep their argument names because of specs.

Defined Under Namespace

Modules: ClassMethods

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Instance Attribute Details

#metadataObject (private)

Returns the value of attribute metadata.



82
83
84
# File 'lib/LittleWeasel/metadata/metadatable.rb', line 82

def 
  @metadata
end

Class Method Details

.included(base) ⇒ Object



13
14
15
# File 'lib/LittleWeasel/metadata/metadatable.rb', line 13

def self.included(base)
  base.extend ClassMethods
end

Instance Method Details

#init(params: nil) ⇒ Object

This method should UNCONDITIONALLY update the local metadata, using the metadata_key and notify all observers (if any) to initialize themselves as well.

This method should be chainable (return self).

. # Example of a root-level dictionary metadata object (e.g. . # Metadata::DictionaryMetadata)

def init(_params: nil)
  self. = {}
  notify action: :init
  
  unless count_observers.zero? || .present?
    raise 'Observers were called to #init but the dictionary cache metadata was not initialized'
  end

  self
end

. # Example of a metadata observable object (e.g. . # Metadata::InvalidWords::InvalidWordsMetadata)

def init(params: nil)
  self. = Services::InvalidWordsService.new(dictionary_words).execute
  self
end


57
58
59
# File 'lib/LittleWeasel/metadata/metadatable.rb', line 57

def init(params: nil)
  raise Errors::MustOverrideError
end

#metadata_keyObject



26
27
28
# File 'lib/LittleWeasel/metadata/metadatable.rb', line 26

def 
  self.class.
end

#refresh(params: nil) ⇒ Object

This method should refresh the local metadata from the dictionary cache, if metadata exists in the dictionary cache for the given metatata_key. Otherwise, #init should be called to initialize this object. The idea is that metadata should be shared across metadata objects of the same type that use the same metadata_key.

This method should be chainable (return self).

Examples:


def refresh(params: nil)
  
  init unless .present?
  self
end

Raises:



76
77
78
# File 'lib/LittleWeasel/metadata/metadatable.rb', line 76

def refresh(params: nil)
  raise Errors::MustOverrideError
end

#refresh_local_metadataObject (private)

This method updates the local metadata ONLY. Use this method if you need to update the local metadata from the dictionary cache metadata.

Override this method in metadata observable classes as needed.



111
112
113
# File 'lib/LittleWeasel/metadata/metadatable.rb', line 111

def 
  @metadata = .
end

#update_dictionary_metadata(value:) ⇒ Object (private)

This method should update the dictionary metadata for the the object when it is called.

:reek:UnusedParameters, ignored - This method is meant to be called with the given argument and raises an

error if not overridden

Examples:


def (value:)
  dictionary_cache_service = LittleWeasel::Services::DictionaryCacheService.new(
    dictionary_key: dictionary_key, dictionary_cache: dictionary_cache)
  dictionary_cache_service.(
    metadata_key: , value: value)
end

Raises:



128
129
130
# File 'lib/LittleWeasel/metadata/metadatable.rb', line 128

def (value:)
  raise Errors::MustOverrideError
end