Sha256: 3b58214c2ef9f801248217f666e4d297850852f48be75279679da09e538f6844

Contents?: true

Size: 949 Bytes

Versions: 1

Compression:

Stored size: 949 Bytes

Contents

# frozen_string_literal: true

module Micro
  module Observers
    module For

      module ActiveModel
        module ClassMethods
          def notify_observers!(events)
            proc do |object|
              object.observers.subject_changed!
              object.observers.send(:broadcast_if_subject_changed, events)
            end
          end

          def notify_observers(*events)
            notify_observers!(Event::Names.fetch(events))
          end

          def notify_observers_on(*callback_methods)
            Utils.compact_array(callback_methods).each do |callback_method|
              self.public_send(callback_method, &notify_observers!([callback_method]))
            end
          end
        end

        def self.included(base)
          base.extend(ClassMethods)
          base.send(:private_class_method, :notify_observers!)
          base.send(:include, ::Micro::Observers)
        end
      end

    end
  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
u-observers-2.0.0 lib/micro/observers/for/active_model.rb