lib/submodules/ably-ruby/lib/ably/modules/state_emitter.rb in ably-rest-0.9.3 vs lib/submodules/ably-ruby/lib/ably/modules/state_emitter.rb in ably-rest-1.0.0

- old
+ new

@@ -2,11 +2,12 @@ # StateEmitter module adds a set of generic state related methods to a class on the assumption that # the instance variable @state is used exclusively, the {Enum} STATE is defined prior to inclusion of this # module, and the class is an {EventEmitter}. It then emits state changes. # # It also ensures the EventEmitter is configured to retrict permitted events to the - # the available STATEs and :error. + # the available STATEs or EVENTs if defined i.e. if EVENTs includes an additional type such as + # :update, then it will support all EVENTs being emitted. EVENTs must be a superset of STATEs # # @note This module requires that the method #logger is defined. # # @example # class Connection @@ -49,11 +50,11 @@ # # @return [Symbol] new state # @api private def state=(new_state, *args) if state != new_state - logger.debug("#{self.class}: StateEmitter changed from #{state} => #{new_state}") if respond_to?(:logger, true) + logger.debug { "#{self.class}: StateEmitter changed from #{state} => #{new_state}" } if respond_to?(:logger, true) @state = STATE(new_state) emit @state, *args end end alias_method :change_state, :state= @@ -151,11 +152,13 @@ end end def self.included(klass) klass.configure_event_emitter coerce_into: Proc.new { |event| - if event == :error - :error + # Special case allows EVENT instead of STATE to be emitted + # Relies on the assumption that EVENT is a superset of STATE + if klass.const_defined?(:EVENT) + klass::EVENT(event) else klass::STATE(event) end }