Sha256: d398f35b7cbba03294e5ffd11e83f6643245488d85fa7a9e6e8d32519192e2ee

Contents?: true

Size: 1.34 KB

Versions: 17

Compression:

Stored size: 1.34 KB

Contents

module Protobuf
  class Lifecycle
    include ::Protobuf::Logger::LogMethods

    def self.register(event_name, &blk)
      raise "Lifecycle register must have a block" unless block_given?
      event_name = normalized_event_name(event_name)

      if ::Protobuf.print_deprecation_warnings?
        $stderr.puts <<-ERROR
            [DEPRECATED] ::Protobuf::Lifecycle has been deprecated and will be removed in a future version.
                         Use ::ActiveSupport::Notifications.subscribe('#{event_name}')
        ERROR
      end

      ::ActiveSupport::Notifications.subscribe(event_name) do |name, start, finish, id, args|
        blk.call(*args)
      end
    end

    def self.trigger( event_name, *args )
      if ::Protobuf.print_deprecation_warnings?
        $stderr.puts <<-ERROR
            [DEPRECATED] ::Protobuf::Lifecycle has been deprecated and will be removed in a future version.
                         Use ::ActiveSupport::Notifications.instrument(...)
        ERROR
      end

      event_name = normalized_event_name( event_name )

      ::ActiveSupport::Notifications.instrument(event_name, args)
    end

    def self.normalized_event_name(event_name)
      return "#{event_name}".downcase
    end

    class << self
      attr_accessor :lifecycle_events

      alias_method :on, :register
    end

    @lifecycle_events ||= {}
  end
end

Version data entries

17 entries across 17 versions & 2 rubygems

Version Path
protobuffy-3.6.0 lib/protobuf/lifecycle.rb
protobuffy-3.5.1 lib/protobuf/lifecycle.rb
protobuffy-3.4.0 lib/protobuf/lifecycle.rb
protobuffy-3.3.0 lib/protobuf/lifecycle.rb
protobuffy-3.2.0 lib/protobuf/lifecycle.rb
protobuffy-3.1.0 lib/protobuf/lifecycle.rb
protobuf-3.2.1 lib/protobuf/lifecycle.rb
protobuf-3.2.0 lib/protobuf/lifecycle.rb
protobuf-3.1.0 lib/protobuf/lifecycle.rb
protobuf-3.0.5 lib/protobuf/lifecycle.rb
protobuf-3.0.4 lib/protobuf/lifecycle.rb
protobuf-3.0.3 lib/protobuf/lifecycle.rb
protobuf-3.0.2 lib/protobuf/lifecycle.rb
protobuf-3.0.1 lib/protobuf/lifecycle.rb
protobuf-3.0.0 lib/protobuf/lifecycle.rb
protobuf-3.0.0.rc2 lib/protobuf/lifecycle.rb
protobuf-3.0.0.rc1 lib/protobuf/lifecycle.rb