Module: Vedeu::Events::Aliases
Overview
Allows the storing of event aliases. Each alias can contain multiple event names.
Instance Method Summary
collapse
reset!, storage
Methods included from Common
#absent?, #array?, #boolean, #boolean?, #empty_value?, #escape?, #falsy?, #hash?, #line_model?, #numeric?, #positionable?, #present?, #snake_case, #stream_model?, #string?, #symbol?, #truthy?, #view_model?
Instance Method Details
#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
|
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
|
#find(alias_name) ⇒ Array<Symbol>
37
38
39
|
# File 'lib/vedeu/events/aliases.rb', line 37
def find(alias_name)
storage[alias_name]
end
|
#in_memory ⇒ 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
|
#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
|
#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
|
#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
|