module Cura::Attributes::HasEvents::ClassMethods

The class methods to be mixed in when included.

Public Instance Methods

callbacks() click to toggle source

The callbacks stored on this class.

@return [Hash<Symbol,Array<Proc>>]

# File lib/cura/attributes/has_events.rb, line 17
def callbacks
  @callbacks ||= {}
end
inherited(subclass) click to toggle source

Register this classes callbacks onto the subclass, when inherited.

# File lib/cura/attributes/has_events.rb, line 34
def inherited(subclass)
  callbacks.each do |event_name, blocks|
    blocks.each do |block|
      subclass.on_event(event_name, &block)
    end
  end
end
on_event(event_name=:default, &block) click to toggle source

Store a callback on this class. Stored callbacks will be registered on the event handler on initialization.

@param [nil, to_sym] event_name The event name. @yield The callback block. @return [Proc] The callback block.

# File lib/cura/attributes/has_events.rb, line 27
def on_event(event_name=:default, &block)
  (callbacks[event_name.to_sym] ||= []) << block

  block
end