Sha256: 9812dd6430b58db03ed1746ad7e5e6639681cddd38279733a868ecc2820e8eab
Contents?: true
Size: 1.06 KB
Versions: 16
Compression:
Stored size: 1.06 KB
Contents
# -*- encoding : utf-8 -*- module Kabutops module Extensions module CallbackSupport extend Includable class Manager attr_reader :map, :allowed def initialize allowed=nil @allowed = allowed || [] @map ||= Hashie::Mash.new end def method_missing name, *args, &block return super unless block_given? && @allowed.include?(name) @map[name] ||= [] @map[name] << block end def notify name, *args return unless @map (@map[name] || []).map do |block| block.call(*args) end end end def callbacks &block @manager ||= Manager.new(allowed_callbacks) @manager.instance_eval &block end def notify name, *args @manager ||= Manager.new(allowed_callbacks) @manager.notify(name, *args) end module ClassMethods def callbacks *args define_method :allowed_callbacks do args end end end end end end
Version data entries
16 entries across 16 versions & 1 rubygems