Class: Disposable::Callback::Group
- Inherits:
-
Object
- Object
- Disposable::Callback::Group
- Extended by:
- Declarative::Schema
- Defined in:
- lib/disposable/callback.rb
Overview
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.
Instance Attribute Summary collapse
-
#invocations ⇒ Object
readonly
Returns the value of attribute invocations.
Class Method Summary collapse
- .clone ⇒ Object
- .collection(name, options = {}, &block) ⇒ Object
- .default_nested_class ⇒ Object
- .hooks ⇒ Object
- .property(name, options = {}, &block) ⇒ Object
- .remove!(event, callback) ⇒ Object
Instance Method Summary collapse
- #call(options = {}) ⇒ Object
-
#initialize(twin) ⇒ Group
constructor
A new instance of Group.
Constructor Details
#initialize(twin) ⇒ Group
Returns a new instance of Group.
46 47 48 49 |
# File 'lib/disposable/callback.rb', line 46 def initialize(twin) @twin = twin @invocations = [] end |
Instance Attribute Details
#invocations ⇒ Object (readonly)
Returns the value of attribute invocations.
51 52 53 |
# File 'lib/disposable/callback.rb', line 51 def invocations @invocations end |
Class Method Details
.clone ⇒ Object
21 22 23 |
# File 'lib/disposable/callback.rb', line 21 def self.clone Class.new(self) end |
.collection(name, options = {}, &block) ⇒ Object
25 26 27 |
# File 'lib/disposable/callback.rb', line 25 def self.collection(name, ={}, &block) property(name, .merge(collection: true), &block) end |
.default_nested_class ⇒ Object
17 18 19 |
# File 'lib/disposable/callback.rb', line 17 def self.default_nested_class Group end |
.hooks ⇒ Object
53 54 55 |
# File 'lib/disposable/callback.rb', line 53 def self.hooks @hooks ||= [] end |
.property(name, options = {}, &block) ⇒ Object
29 30 31 32 33 34 35 36 37 38 39 |
# File 'lib/disposable/callback.rb', line 29 def self.property(name, ={}, &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 = [:inherit] # FIXME: this is deleted in ::property. super(name, , &block).tap do |dfn| return if inherit hooks << ["property", dfn[:name]] end end |
.remove!(event, callback) ⇒ Object
41 42 43 |
# File 'lib/disposable/callback.rb', line 41 def self.remove!(event, callback) hooks.delete hooks.find { |cfg| cfg[0] == event && cfg[1] == callback } end |
Instance Method Details
#call(options = {}) ⇒ Object
69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 |
# File 'lib/disposable/callback.rb', line 69 def call(={}) self.class.hooks.each do |event, method, | 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).().invocations # Group.new(twin).() next end invocations << callback!(event, , method, ) end self end |