Module: Vedeu::Events::Aliases
Overview
Allows the storing of event aliases. Each alias can contain multiple event names.
Class Method Summary collapse
-
.absent?(variable) ⇒ Boolean
extended
from Common
private
Returns a boolean indicating whether a variable is nil or empty.
-
.bind_alias(alias_name, event_name) ⇒ Hash<Symbol => Array<Symbol>>
(also: #add)
Add events by name to the alias name group.
-
.demodulize(klass) ⇒ String
extended
from Common
private
Removes the module part from the expression in the string.
-
.empty? ⇒ Boolean
Return a boolean indicating whether the storage is empty.
- .find(alias_name) ⇒ Array<Symbol>
- .in_memory ⇒ Hash<Symbol => Array<Symbol>> private
-
.present?(variable) ⇒ Boolean
extended
from Common
private
Returns a boolean indicating whether a variable has a useful value.
-
.registered?(alias_name) ⇒ Boolean
Returns a boolean indicating whether the alias is registered.
- .reset ⇒ Hash<Symbol => Array<Symbol>> (also: #reset!)
-
.snake_case(name) ⇒ String
extended
from Common
private
Converts a class name to a lowercase snake case string.
-
.storage ⇒ Hash<Symbol => Array<Symbol>>
Access to the storage for this repository.
- .trigger(alias_name, *args) ⇒ FalseClass|Array<void>|void
-
.unbind_alias(alias_name) ⇒ FalseClass|Hash<Symbol => Array<Symbol>>
(also: #remove)
Remove an alias by name.
Instance Method Summary collapse
-
#absent?(variable) ⇒ Boolean
included
from Common
private
Returns a boolean indicating whether a variable is nil or empty.
-
#bind_alias(alias_name, event_name) ⇒ Hash<Symbol => Array<Symbol>>
(also: #add)
Add events by name to the alias name group.
-
#demodulize(klass) ⇒ String
included
from Common
private
Removes the module part from the expression in the string.
-
#empty? ⇒ Boolean
Return a boolean indicating whether the storage is empty.
- #find(alias_name) ⇒ Array<Symbol>
- #in_memory ⇒ Hash<Symbol => Array<Symbol>> private
-
#present?(variable) ⇒ Boolean
included
from Common
private
Returns a boolean indicating whether a variable has a useful value.
-
#registered?(alias_name) ⇒ Boolean
Returns a boolean indicating whether the alias is registered.
- #reset ⇒ Hash<Symbol => Array<Symbol>> (also: #reset!)
-
#snake_case(name) ⇒ String
included
from Common
private
Converts a class name to a lowercase snake case string.
-
#storage ⇒ Hash<Symbol => Array<Symbol>>
Access to the storage for this repository.
- #trigger(alias_name, *args) ⇒ FalseClass|Array<void>|void
-
#unbind_alias(alias_name) ⇒ FalseClass|Hash<Symbol => Array<Symbol>>
(also: #remove)
Remove an alias by name.
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.
.bind_alias(alias_name, event_name) ⇒ Hash<Symbol => Array<Symbol>> Also known as: add
Add events by name to the alias name group. When an alias is triggered, all the events stored in the group are also triggered.
26 27 28 |
# File 'lib/vedeu/events/aliases.rb', line 26 def bind_alias(alias_name, event_name) storage[alias_name] << event_name end |
.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.
.empty? ⇒ Boolean
Return a boolean indicating whether the storage is empty.
34 35 36 |
# File 'lib/vedeu/events/aliases.rb', line 34 def empty? storage.empty? end |
.find(alias_name) ⇒ Array<Symbol>
40 41 42 |
# File 'lib/vedeu/events/aliases.rb', line 40 def find(alias_name) storage[alias_name] end |
.in_memory ⇒ Hash<Symbol => Array<Symbol>> (private)
99 100 101 |
# File 'lib/vedeu/events/aliases.rb', line 99 def in_memory Hash.new { |hash, key| hash[key] = [] } 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.
.registered?(alias_name) ⇒ Boolean
Returns a boolean indicating whether the alias is registered.
48 49 50 51 52 |
# File 'lib/vedeu/events/aliases.rb', line 48 def registered?(alias_name) return false if empty? || absent?(alias_name) storage.include?(alias_name) end |
.reset ⇒ Hash<Symbol => Array<Symbol>> Also known as: reset!
72 73 74 |
# File 'lib/vedeu/events/aliases.rb', line 72 def reset @storage = in_memory 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.
.storage ⇒ Hash<Symbol => Array<Symbol>>
Access to the storage for this repository.
80 81 82 |
# File 'lib/vedeu/events/aliases.rb', line 80 def storage @storage ||= in_memory end |
.trigger(alias_name, *args) ⇒ FalseClass|Array<void>|void
87 88 89 90 91 92 93 94 |
# File 'lib/vedeu/events/aliases.rb', line 87 def trigger(alias_name, *args) return [] unless registered?(alias_name) find(alias_name).map do |event_name| Vedeu.log(type: :debug, message: "#{event_name}".freeze) Vedeu::Events::Trigger.trigger(event_name, *args) end end |
.unbind_alias(alias_name) ⇒ FalseClass|Hash<Symbol => Array<Symbol>> Also known as: remove
Remove an alias by name. The alias name group is destroyed,
but events stored within this alias are not.
62 63 64 65 66 67 68 |
# File 'lib/vedeu/events/aliases.rb', line 62 def unbind_alias(alias_name) return false if empty? return false unless registered?(alias_name) storage.delete(alias_name) storage end |
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.
#bind_alias(alias_name, event_name) ⇒ Hash<Symbol => Array<Symbol>> Also known as: add
Add events by name to the alias name group. When an alias is triggered, all the events stored in the group are also triggered.
26 27 28 |
# File 'lib/vedeu/events/aliases.rb', line 26 def bind_alias(alias_name, event_name) storage[alias_name] << event_name end |
#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.
#empty? ⇒ Boolean
Return a boolean indicating whether the storage is empty.
34 35 36 |
# File 'lib/vedeu/events/aliases.rb', line 34 def empty? storage.empty? end |
#find(alias_name) ⇒ Array<Symbol>
40 41 42 |
# File 'lib/vedeu/events/aliases.rb', line 40 def find(alias_name) storage[alias_name] end |
#in_memory ⇒ Hash<Symbol => Array<Symbol>> (private)
99 100 101 |
# File 'lib/vedeu/events/aliases.rb', line 99 def in_memory Hash.new { |hash, key| hash[key] = [] } 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.
#registered?(alias_name) ⇒ Boolean
Returns a boolean indicating whether the alias is registered.
48 49 50 51 52 |
# File 'lib/vedeu/events/aliases.rb', line 48 def registered?(alias_name) return false if empty? || absent?(alias_name) storage.include?(alias_name) end |
#reset ⇒ Hash<Symbol => Array<Symbol>> Also known as: reset!
72 73 74 |
# File 'lib/vedeu/events/aliases.rb', line 72 def reset @storage = in_memory 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.
#storage ⇒ Hash<Symbol => Array<Symbol>>
Access to the storage for this repository.
80 81 82 |
# File 'lib/vedeu/events/aliases.rb', line 80 def storage @storage ||= in_memory end |
#trigger(alias_name, *args) ⇒ FalseClass|Array<void>|void
87 88 89 90 91 92 93 94 |
# File 'lib/vedeu/events/aliases.rb', line 87 def trigger(alias_name, *args) return [] unless registered?(alias_name) find(alias_name).map do |event_name| Vedeu.log(type: :debug, message: "#{event_name}".freeze) Vedeu::Events::Trigger.trigger(event_name, *args) end end |
#unbind_alias(alias_name) ⇒ FalseClass|Hash<Symbol => Array<Symbol>> Also known as: remove
Remove an alias by name. The alias name group is destroyed,
but events stored within this alias are not.
62 63 64 65 66 67 68 |
# File 'lib/vedeu/events/aliases.rb', line 62 def unbind_alias(alias_name) return false if empty? return false unless registered?(alias_name) storage.delete(alias_name) storage end |