class Disposable::Callback::Group
Order matters.
on_change :change! collection :songs do on_add :notify_album! on_add :reset_song!
you can call collection :songs again, with :inherit. TODO: verify.
Attributes
invocations[R]
Public Class Methods
clone()
click to toggle source
# File lib/disposable/callback.rb, line 21 def self.clone Class.new(self) end
collection(name, options={}, &block)
click to toggle source
# File lib/disposable/callback.rb, line 25 def self.collection(name, options={}, &block) property(name, options.merge(collection: true), &block) end
default_nested_class()
click to toggle source
# File lib/disposable/callback.rb, line 17 def self.default_nested_class Group end
hooks()
click to toggle source
# File lib/disposable/callback.rb, line 53 def self.hooks @hooks ||= [] end
new(twin)
click to toggle source
# File lib/disposable/callback.rb, line 46 def initialize(twin) @twin = twin @invocations = [] end
property(name, options={}, &block)
click to toggle source
Calls superclass method
# File lib/disposable/callback.rb, line 29 def self.property(name, options={}, &block) # NOTE: while the API will stay the same, it's very likely i'm gonna use Declarative::Config here instead # of maintaining two stacks of callbacks. # it should have a Definition per callback where the representer_module will be a nested Group or a Callback. inherit = options[:inherit] # FIXME: this is deleted in ::property. super(name, options, &block).tap do |dfn| return if inherit hooks << ["property", dfn[:name]] end end
remove!(event, callback)
click to toggle source
# File lib/disposable/callback.rb, line 41 def self.remove!(event, callback) hooks.delete hooks.find { |cfg| cfg[0] == event && cfg[1] == callback } end
Public Instance Methods
call(options={})
click to toggle source
# File lib/disposable/callback.rb, line 69 def call(options={}) self.class.hooks.each do |event, method, property_options| if event == "property" # FIXME: make nicer. definition = self.class.definitions.get(method) twin = @twin.send(definition[:name]) # album.songs # recursively call nested group. @invocations += definition[:nested].new(twin).(options).invocations # Group.new(twin).() next end invocations << callback!(event, options, method, property_options) end self end
Private Instance Methods
callback!(event, options, method, property_options)
click to toggle source
Runs one callback, e.g. for ‘on_change :smile!`.
# File lib/disposable/callback.rb, line 88 def callback!(event, options, method, property_options) # TODO: remove args. context = options[:context] || self # TODO: test me. # TODO: Use Option::Value here. this could be created straight in the DSL with the twin being passed in. if context.methods.include?(method) && context.method(method).arity == 1 # TODO: remove in 0.3. warn "[Disposable] Callback handlers now receive two options: #{method}(twin, options)." return Dispatch.new(@twin).(event, method, property_options) { |twin| context.send(method, twin) } end Dispatch.new(@twin).(event, method, property_options) { |twin| context.send(method, twin, options) } end