Module: CallbacksAttachable

Defined in:
lib/all/error.rb,
lib/all/version.rb,
lib/all/callback.rb,
lib/all/callback_registry.rb,
lib/all/callbacks_attachable.rb

Defined Under Namespace

Modules: RegistryOwnable Classes: Callback, CallbackRegistry, Error

Constant Summary collapse

VERSION =
"3.0.0"

Class Method Summary collapse

Instance Method Summary collapse

Class Method Details

.extended(object) ⇒ Object



39
40
41
# File 'lib/all/callbacks_attachable.rb', line 39

def self.extended(object)
  object.singleton_class.extend RegistryOwnable
end

.included(klass) ⇒ Object



43
44
45
# File 'lib/all/callbacks_attachable.rb', line 43

def self.included(klass)
  klass.extend RegistryOwnable
end

Instance Method Details

#on(*events, &callback) ⇒ Object



47
48
49
# File 'lib/all/callbacks_attachable.rb', line 47

def on(*events, &callback)
  singleton_class.on *events, &callback
end

#on?(event) ⇒ Boolean

Returns:

  • (Boolean)


58
59
60
# File 'lib/all/callbacks_attachable.rb', line 58

def on?(event)
  singleton_class.on? event
end

#once_on(*events, &callback) ⇒ Object



51
52
53
54
55
56
# File 'lib/all/callbacks_attachable.rb', line 51

def once_on(*events, &callback)
  singleton_class.instance_variable_set :@on_opts, {once?: true}
  on *events, &callback
ensure
  singleton_class.remove_instance_variable :@on_opts
end

#trigger(event, *args) ⇒ Object



62
63
64
# File 'lib/all/callbacks_attachable.rb', line 62

def trigger(event, *args)
  singleton_class.trigger_for_instance(self, event, args)
end