Module: Vedeu::Events::Aliases

Extended by:
Aliases, Repositories::Storage
Includes:
Common
Included in:
Aliases
Defined in:
lib/vedeu/events/aliases.rb

Overview

Allows the storing of event aliases. Each alias can contain multiple event names.

Class Method Summary collapse

Instance Method Summary collapse

Class 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:

.become(klass, attributes) ⇒ Class 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 one class into another.

Parameters:

  • klass (Class)

    The class to become an instance of.

  • attributes (Hash)

    The attributes of klass.

Returns:

  • (Class)

    Returns a new instance of klass.

.bind_alias(alias_name, event_name) ⇒ Hash<Symbol => Array<Symbol>> Also known as: add

Parameters:

  • alias_name (Symbol)

    The name of the alias. This can represent a single event or group of events.

  • event_name (Symbol)

    The name of the event to bind to the alias. When the alias is triggered, all events bound will also be triggered.

Returns:

  • (Hash<Symbol => Array<Symbol>>)


23
24
25
# File 'lib/vedeu/events/aliases.rb', line 23

def bind_alias(alias_name, event_name)
  storage[alias_name] << event_name
end

.boolean(value) ⇒ 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 the value was a boolean.

Parameters:

  • value (void)

Returns:

.boolean?(value) ⇒ 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 the value is a Boolean.

Parameters:

Returns:

.empty?Boolean

Return a boolean indicating whether the storage is empty.

Returns:



31
32
33
# File 'lib/vedeu/events/aliases.rb', line 31

def empty?
  storage.empty?
end

.escape?(value) ⇒ 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 the value is an escape sequence object (e.g. Vedeu::Cells::Escape.)

Returns:

.falsy?(value) ⇒ 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 the value should be considered false.

Parameters:

  • value (void)

Returns:

.find(alias_name) ⇒ Array<Symbol>

Parameters:

  • alias_name (Symbol)

Returns:

  • (Array<Symbol>)


37
38
39
# File 'lib/vedeu/events/aliases.rb', line 37

def find(alias_name)
  storage[alias_name]
end

.hash?(value) ⇒ 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 the value is a Hash.

Parameters:

  • value (Hash|void)

Returns:

.in_memoryHash<Symbol => Array<Symbol>> (private)

Returns:

  • (Hash<Symbol => Array<Symbol>>)


80
81
82
# File 'lib/vedeu/events/aliases.rb', line 80

def in_memory
  Hash.new { |hash, key| hash[key] = [] }
end

.line_model?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 the model is a Views::Line.

Returns:

.numeric?(value) ⇒ 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 the value is a Fixnum.

Parameters:

  • value (Fixnum|void)

Returns:

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

.registered?(alias_name) ⇒ Boolean

Returns a boolean indicating whether the alias is registered.

Parameters:

  • alias_name (Symbol)

Returns:



45
46
47
48
49
# File 'lib/vedeu/events/aliases.rb', line 45

def registered?(alias_name)
  return false if empty? || absent?(alias_name)

  storage.include?(alias_name)
end

.reset!void Also known as: reset Originally defined in module Repositories::Storage

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.

This method returns an undefined value.

Remove all currently stored data for this repository.

.snake_case(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.

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"

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

Parameters:

  • klass (Module|Class|String)

Returns:

  • (String)

.storagevoid Also known as: all Originally defined in module Repositories::Storage

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.

This method returns an undefined value.

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

.stream_model?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 the model is a Views::Stream.

Returns:

.string?(value) ⇒ 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 the value is a Fixnum.

Parameters:

  • value (String|void)

Returns:

.trigger(alias_name, *args) ⇒ Boolean|Array<void>|void

Parameters:

  • alias_name (Symbol)
  • args (void)

Returns:



66
67
68
69
70
71
72
73
74
75
# File 'lib/vedeu/events/aliases.rb', line 66

def trigger(alias_name, *args)
  return [] unless registered?(alias_name)

  find(alias_name).map do |event_name|
    Vedeu.log(type:    :event,
              message: "Triggering: '#{event_name}' from alias " \
                       "'#{alias_name}'")
    Vedeu::Events::Trigger.trigger(event_name, *args)
  end
end

.truthy?(value) ⇒ 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 the value should be considered true.

Parameters:

  • value (void)

Returns:

.unbind_alias(alias_name) ⇒ Boolean|Hash<Symbol => Array<Symbol>> Also known as: remove

Parameters:

  • alias_name (Symbol)

    The name of the alias.

Returns:

  • (Boolean|Hash<Symbol => Array<Symbol>>)


54
55
56
57
58
59
60
# File 'lib/vedeu/events/aliases.rb', line 54

def unbind_alias(alias_name)
  return false if empty?
  return false unless registered?(alias_name)

  storage.delete(alias_name)
  storage
end

.view_model?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 the model is a Views::View.

Returns:

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:

#become(klass, attributes) ⇒ Class 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 one class into another.

Parameters:

  • klass (Class)

    The class to become an instance of.

  • attributes (Hash)

    The attributes of klass.

Returns:

  • (Class)

    Returns a new instance of klass.

#bind_alias(alias_name, event_name) ⇒ Hash<Symbol => Array<Symbol>> Also known as: add

Parameters:

  • alias_name (Symbol)

    The name of the alias. This can represent a single event or group of events.

  • event_name (Symbol)

    The name of the event to bind to the alias. When the alias is triggered, all events bound will also be triggered.

Returns:

  • (Hash<Symbol => Array<Symbol>>)


23
24
25
# File 'lib/vedeu/events/aliases.rb', line 23

def bind_alias(alias_name, event_name)
  storage[alias_name] << event_name
end

#boolean(value) ⇒ 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 the value was a boolean.

Parameters:

  • value (void)

Returns:

#boolean?(value) ⇒ 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 the value is a Boolean.

Parameters:

Returns:

#empty?Boolean

Return a boolean indicating whether the storage is empty.

Returns:



31
32
33
# File 'lib/vedeu/events/aliases.rb', line 31

def empty?
  storage.empty?
end

#escape?(value) ⇒ 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 the value is an escape sequence object (e.g. Vedeu::Cells::Escape.)

Returns:

#falsy?(value) ⇒ 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 the value should be considered false.

Parameters:

  • value (void)

Returns:

#find(alias_name) ⇒ Array<Symbol>

Parameters:

  • alias_name (Symbol)

Returns:

  • (Array<Symbol>)


37
38
39
# File 'lib/vedeu/events/aliases.rb', line 37

def find(alias_name)
  storage[alias_name]
end

#hash?(value) ⇒ 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 the value is a Hash.

Parameters:

  • value (Hash|void)

Returns:

#in_memoryHash<Symbol => Array<Symbol>> (private)

Returns:

  • (Hash<Symbol => Array<Symbol>>)


80
81
82
# File 'lib/vedeu/events/aliases.rb', line 80

def in_memory
  Hash.new { |hash, key| hash[key] = [] }
end

#line_model?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 the model is a Views::Line.

Returns:

#numeric?(value) ⇒ 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 the value is a Fixnum.

Parameters:

  • value (Fixnum|void)

Returns:

#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:

#registered?(alias_name) ⇒ Boolean

Returns a boolean indicating whether the alias is registered.

Parameters:

  • alias_name (Symbol)

Returns:



45
46
47
48
49
# File 'lib/vedeu/events/aliases.rb', line 45

def registered?(alias_name)
  return false if empty? || absent?(alias_name)

  storage.include?(alias_name)
end

#snake_case(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.

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"

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

Parameters:

  • klass (Module|Class|String)

Returns:

  • (String)

#stream_model?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 the model is a Views::Stream.

Returns:

#string?(value) ⇒ 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 the value is a Fixnum.

Parameters:

  • value (String|void)

Returns:

#trigger(alias_name, *args) ⇒ Boolean|Array<void>|void

Parameters:

  • alias_name (Symbol)
  • args (void)

Returns:



66
67
68
69
70
71
72
73
74
75
# File 'lib/vedeu/events/aliases.rb', line 66

def trigger(alias_name, *args)
  return [] unless registered?(alias_name)

  find(alias_name).map do |event_name|
    Vedeu.log(type:    :event,
              message: "Triggering: '#{event_name}' from alias " \
                       "'#{alias_name}'")
    Vedeu::Events::Trigger.trigger(event_name, *args)
  end
end

#truthy?(value) ⇒ 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 the value should be considered true.

Parameters:

  • value (void)

Returns:

#unbind_alias(alias_name) ⇒ Boolean|Hash<Symbol => Array<Symbol>> Also known as: remove

Parameters:

  • alias_name (Symbol)

    The name of the alias.

Returns:

  • (Boolean|Hash<Symbol => Array<Symbol>>)


54
55
56
57
58
59
60
# File 'lib/vedeu/events/aliases.rb', line 54

def unbind_alias(alias_name)
  return false if empty?
  return false unless registered?(alias_name)

  storage.delete(alias_name)
  storage
end

#view_model?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 the model is a Views::View.

Returns: