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.

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

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



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.

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

.empty?Boolean

Return a boolean indicating whether the storage is empty.



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

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

.find(alias_name) ⇒ 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.

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



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.

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

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

.registered?(alias_name) ⇒ Boolean

Returns a boolean indicating whether the alias is registered.



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"

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

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

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



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.

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



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.

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.

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

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



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.

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

#empty?Boolean

Return a boolean indicating whether the storage is empty.



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

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

#find(alias_name) ⇒ 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.

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



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.

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

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

#registered?(alias_name) ⇒ Boolean

Returns a boolean indicating whether the alias is registered.



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"

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

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

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



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.

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



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.