Module: Vedeu::Events::Aliases
Overview
Allows the storing of event aliases. Each alias can contain multiple event names.
Class Method Summary collapse
-
.bind_alias(alias_name, event_name) ⇒ Hash<Symbol => Array<Symbol>>
(also: #add)
Add events by name to the alias name group.
-
.empty? ⇒ Boolean
Return a boolean indicating whether the storage is empty.
- .find(alias_name) ⇒ Array<Symbol>
- .in_memory ⇒ Hash<Symbol => Array<Symbol>> private
-
.registered?(alias_name) ⇒ Boolean
Returns a boolean indicating whether the alias is registered.
- .reset ⇒ Hash<Symbol => Array<Symbol>> (also: #reset!)
-
.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
-
#bind_alias(alias_name, event_name) ⇒ Hash<Symbol => Array<Symbol>>
(also: #add)
Add events by name to the alias name group.
-
#empty? ⇒ Boolean
Return a boolean indicating whether the storage is empty.
- #find(alias_name) ⇒ Array<Symbol>
- #in_memory ⇒ Hash<Symbol => Array<Symbol>> private
-
#registered?(alias_name) ⇒ Boolean
Returns a boolean indicating whether the alias is registered.
- #reset ⇒ Hash<Symbol => Array<Symbol>> (also: #reset!)
-
#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
.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.
28 29 30 |
# File 'lib/vedeu/events/aliases.rb', line 28 def bind_alias(alias_name, event_name) storage[alias_name] << event_name end |
.empty? ⇒ Boolean
Return a boolean indicating whether the storage is empty.
36 37 38 |
# File 'lib/vedeu/events/aliases.rb', line 36 def empty? storage.empty? end |
.find(alias_name) ⇒ Array<Symbol>
42 43 44 |
# File 'lib/vedeu/events/aliases.rb', line 42 def find(alias_name) storage[alias_name] end |
.in_memory ⇒ Hash<Symbol => Array<Symbol>> (private)
102 103 104 |
# File 'lib/vedeu/events/aliases.rb', line 102 def in_memory Hash.new { |hash, key| hash[key] = [] } end |
.registered?(alias_name) ⇒ Boolean
Returns a boolean indicating whether the alias is registered.
50 51 52 53 54 55 |
# File 'lib/vedeu/events/aliases.rb', line 50 def registered?(alias_name) return false if alias_name.nil? || alias_name.empty? return false if empty? storage.include?(alias_name) end |
.reset ⇒ Hash<Symbol => Array<Symbol>> Also known as: reset!
75 76 77 |
# File 'lib/vedeu/events/aliases.rb', line 75 def reset @storage = in_memory end |
.storage ⇒ Hash<Symbol => Array<Symbol>>
Access to the storage for this repository.
83 84 85 |
# File 'lib/vedeu/events/aliases.rb', line 83 def storage @storage ||= in_memory end |
.trigger(alias_name, *args) ⇒ FalseClass|Array<void>|void
90 91 92 93 94 95 96 97 |
# File 'lib/vedeu/events/aliases.rb', line 90 def trigger(alias_name, *args) return [] unless registered?(alias_name) storage[alias_name].map do |event_name| Vedeu.log(type: :debug, message: "#{event_name}") 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.
65 66 67 68 69 70 71 |
# File 'lib/vedeu/events/aliases.rb', line 65 def unbind_alias(alias_name) return false if empty? return false unless registered?(alias_name) storage.delete(alias_name) storage end |
Instance Method Details
#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.
28 29 30 |
# File 'lib/vedeu/events/aliases.rb', line 28 def bind_alias(alias_name, event_name) storage[alias_name] << event_name end |
#empty? ⇒ Boolean
Return a boolean indicating whether the storage is empty.
36 37 38 |
# File 'lib/vedeu/events/aliases.rb', line 36 def empty? storage.empty? end |
#find(alias_name) ⇒ Array<Symbol>
42 43 44 |
# File 'lib/vedeu/events/aliases.rb', line 42 def find(alias_name) storage[alias_name] end |
#in_memory ⇒ Hash<Symbol => Array<Symbol>> (private)
102 103 104 |
# File 'lib/vedeu/events/aliases.rb', line 102 def in_memory Hash.new { |hash, key| hash[key] = [] } end |
#registered?(alias_name) ⇒ Boolean
Returns a boolean indicating whether the alias is registered.
50 51 52 53 54 55 |
# File 'lib/vedeu/events/aliases.rb', line 50 def registered?(alias_name) return false if alias_name.nil? || alias_name.empty? return false if empty? storage.include?(alias_name) end |
#reset ⇒ Hash<Symbol => Array<Symbol>> Also known as: reset!
75 76 77 |
# File 'lib/vedeu/events/aliases.rb', line 75 def reset @storage = in_memory end |
#storage ⇒ Hash<Symbol => Array<Symbol>>
Access to the storage for this repository.
83 84 85 |
# File 'lib/vedeu/events/aliases.rb', line 83 def storage @storage ||= in_memory end |
#trigger(alias_name, *args) ⇒ FalseClass|Array<void>|void
90 91 92 93 94 95 96 97 |
# File 'lib/vedeu/events/aliases.rb', line 90 def trigger(alias_name, *args) return [] unless registered?(alias_name) storage[alias_name].map do |event_name| Vedeu.log(type: :debug, message: "#{event_name}") 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.
65 66 67 68 69 70 71 |
# File 'lib/vedeu/events/aliases.rb', line 65 def unbind_alias(alias_name) return false if empty? return false unless registered?(alias_name) storage.delete(alias_name) storage end |