Class: Disposable::Callback::Group

Inherits:
Object
  • Object
show all
Extended by:
Uber::InheritableAttr
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

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(twin) ⇒ Group

Returns a new instance of Group.



52
53
54
55
# File 'lib/disposable/callback.rb', line 52

def initialize(twin)
  @twin = twin
  @invocations = []
end

Instance Attribute Details

#invocationsObject (readonly)

Returns the value of attribute invocations.



57
58
59
# File 'lib/disposable/callback.rb', line 57

def invocations
  @invocations
end

Class Method Details

.collection(name, options = {}, &block) ⇒ Object



31
32
33
# File 'lib/disposable/callback.rb', line 31

def self.collection(name, options={}, &block)
  property(name, options.merge(collection: true), &block)
end

.feature(*args) ⇒ Object



28
29
# File 'lib/disposable/callback.rb', line 28

def self.feature(*args)
end

.property(name, options = {}, &block) ⇒ Object



35
36
37
38
39
40
41
42
43
44
45
# File 'lib/disposable/callback.rb', line 35

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.

  representer_class.property(name, options, &block).tap do |dfn|
    return if inherit
    hooks << ["property", dfn.name]
  end
end

.remove!(event, callback) ⇒ Object



47
48
49
# File 'lib/disposable/callback.rb', line 47

def self.remove!(event, callback)
  hooks.delete hooks.find { |cfg| cfg[0] == event && cfg[1][0] == callback }
end

Instance Method Details

#call(options = {}) ⇒ Object



71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
# File 'lib/disposable/callback.rb', line 71

def call(options={})
  self.class.hooks.each do |cfg|
    event, args = cfg

    if event == "property" # FIXME: make nicer.
      definition = self.class.representer_class.representable_attrs.get(args)
      twin = @twin.send(definition.getter) # album.songs

      @invocations += definition.representer_module.new(twin).(options).invocations # Group.new(twin).()
      next
    end

    invocations << callback!(event, options, args)
  end

  self
end