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.

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.



85
86
87
# File 'lib/LittleWeasel/metadata/metadatable.rb', line 85

def 
  @metadata
end

Class Method Details

.included(base) ⇒ Object



11
12
13
# File 'lib/LittleWeasel/metadata/metadatable.rb', line 11

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

rubocop: disable Lint/UnusedMethodArgument



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

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

#metadata_keyObject



24
25
26
# File 'lib/LittleWeasel/metadata/metadatable.rb', line 24

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).

rubocop: disable Lint/UnusedMethodArgument

Examples:


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

Raises:



78
79
80
# File 'lib/LittleWeasel/metadata/metadatable.rb', line 78

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.



114
115
116
# File 'lib/LittleWeasel/metadata/metadatable.rb', line 114

def 
  @metadata = .
end

#update_dictionary_metadata(value:) ⇒ Object (private)

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

rubocop: disable Lint/UnusedMethodArgument

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:



130
131
132
# File 'lib/LittleWeasel/metadata/metadatable.rb', line 130

def (value:)
  raise Errors::MustOverrideError
end