Module: Vedeu::Repositories::Store Private

Includes:
Enumerable, Common
Included in:
Repository
Defined in:
lib/vedeu/repositories/store.rb

Overview

This module is part of a private API. You should avoid using this module if possible, as it may be removed or be changed in the future.

Provides generic repository related behaviour.

Instance Method Summary collapse

Instance Method Details

#absent?(variable) ⇒ Boolean Originally defined in module Common

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

Returns a boolean indicating whether a variable is nil or empty.

Parameters:

  • variable (String|Symbol|Array|Fixnum)

    The variable to check.

Returns:

  • (Boolean)

#demodulize(klass) ⇒ String Originally defined in module Common

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

Removes the module part from the expression in the string.

Examples:

demodulize('Vedeu::SomeModule::SomeClass') # => "SomeClass"

Parameters:

  • klass (Class|String)

Returns:

  • (String)

#each(&block) ⇒ Enumerator

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

Parameters:

  • block (Proc)

Returns:

  • (Enumerator)


16
17
18
# File 'lib/vedeu/repositories/store.rb', line 16

def each(&block)
  storage.each(&block)
end

#empty?Boolean

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

Return a boolean indicating whether the storage is empty.

Returns:

  • (Boolean)


23
24
25
# File 'lib/vedeu/repositories/store.rb', line 23

def empty?
  storage.empty?
end

#exists?(name) ⇒ Boolean Also known as: registered?

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

Returns a boolean indicating whether the named model is registered.

Parameters:

  • name (String|Symbol)

Returns:

  • (Boolean)


32
33
34
35
36
# File 'lib/vedeu/repositories/store.rb', line 32

def exists?(name)
  return false if empty? || absent?(name)

  storage.include?(name)
end

#in_memoryHash

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

Returns:

  • (Hash)


80
81
82
# File 'lib/vedeu/repositories/store.rb', line 80

def in_memory
  {}
end

#present?(variable) ⇒ Boolean Originally defined in module Common

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

Returns a boolean indicating whether a variable has a useful value.

Parameters:

  • variable (String|Symbol|Array|Fixnum)

    The variable to check.

Returns:

  • (Boolean)

#registeredArray

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

Returns a collection of the names of all the registered entities.

Returns:

  • (Array)


43
44
45
46
47
48
49
# File 'lib/vedeu/repositories/store.rb', line 43

def registered
  return []           if empty?
  return storage.keys if storage.is_a?(Hash)
  return storage.to_a if storage.is_a?(Set)

  storage
end

#resetArray|Hash|Set Also known as: reset!, clear

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

Remove all currently stored data.

Returns:

  • (Array|Hash|Set)


54
55
56
57
58
59
# File 'lib/vedeu/repositories/store.rb', line 54

def reset
  Vedeu.log(type:    :reset,
            message: "(#{self.class.name}) #{registered.inspect}".freeze)

  @storage = in_memory
end

#sizeFixnum

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

Return the number of entries stored.

Returns:

  • (Fixnum)


66
67
68
# File 'lib/vedeu/repositories/store.rb', line 66

def size
  storage.size
end

#snake_case(name) ⇒ String Originally defined in module Common

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

Converts a class name to a lowercase snake case string.

Examples:

snake_case(MyClassName) # => "my_class_name"
snake_case(NameSpaced::ClassName)
# => "name_spaced/class_name"

Parameters:

  • name (String)

Returns:

  • (String)

#storageArray|Hash|Set Also known as: all

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

Return whole repository; provides raw access to the storage for this repository.

Returns:

  • (Array|Hash|Set)


74
75
76
# File 'lib/vedeu/repositories/store.rb', line 74

def storage
  @storage ||= in_memory
end