Class: Wee::CallbackStream
Overview
The intersection of registered callbacks and those that occured.
Instance Method Summary collapse
-
#all_of_type(type) ⇒ Object
Returns a [callback, value] array of all callbacks of
typefor which an id was given. -
#initialize(callbacks, ids_and_values) ⇒ CallbackStream
constructor
callbacks-
A Wee::CallbackRegistry.
- #with_callbacks_for(object, type) ⇒ Object
Constructor Details
#initialize(callbacks, ids_and_values) ⇒ CallbackStream
callbacks-
A Wee::CallbackRegistry
ids_and_values-
A hash that contains all callback ids together with their values that occurend in a request, e.g. { id => value }.
78 79 80 81 82 |
# File 'lib/wee/core/callback.rb', line 78 def initialize(callbacks, ids_and_values) @callbacks = callbacks @ids_and_values = ids_and_values @ids = @ids_and_values.keys end |
Instance Method Details
#all_of_type(type) ⇒ Object
Returns a [callback, value] array of all callbacks of type for which an id was given.
95 96 97 98 99 100 101 |
# File 'lib/wee/core/callback.rb', line 95 def all_of_type(type) a = [] @callbacks.all_of_type(type).each {|id, callback| a << [callback, @ids_and_values[id]] if @ids_and_values.include?(id) } return a end |
#with_callbacks_for(object, type) ⇒ Object
84 85 86 87 88 89 90 |
# File 'lib/wee/core/callback.rb', line 84 def with_callbacks_for(object, type) matching_ids = @callbacks.get_ids_for(object, type) & @ids matching_ids.each do |id| yield @callbacks.get_callback_for(id, type), @ids_and_values[id] end @ids -= matching_ids end |