Sha256: fae2e138b1890005e81486ab03193660904c973b0d7e0ac4a5c076e415fe038f
Contents?: true
Size: 1.18 KB
Versions: 2
Compression:
Stored size: 1.18 KB
Contents
require 'dry/equalizer' require 'dry/events/publisher' module Dry module Events # Extension for objects that can listen to events # # @example # class AppEvents # include Dry::Events::Publisher[:app] # # register_event("users.created") # end # # class MyListener # include Dry::Events::Listener[:app] # # subscribe("users.created") do |event| # # do something # end # end # # @api public class Listener < Module include Dry::Equalizer(:id) # @!attribute [r] :id # @return [Symbol,String] The publisher identifier # @api private attr_reader :id # Create a listener extension for a specific publisher # # @return [Module] # # @api public def self.[](id) new(id) end # @api private def initialize(id) @id = id define_method(:subscribe) do |event_id, query = EMPTY_HASH, &block| Publisher.registry[id].subscribe(event_id, query, &block) end end # @api private def included(klass) klass.extend(self) super end end end end
Version data entries
2 entries across 2 versions & 1 rubygems
Version | Path |
---|---|
dry-events-0.2.0 | lib/dry/events/listener.rb |
dry-events-0.1.1 | lib/dry/events/listener.rb |