Class: Protobuf::Lifecycle

Inherits:
Object
  • Object
show all
Includes:
Protobuf::Logger::LogMethods
Defined in:
lib/protobuf/lifecycle.rb

Class Attribute Summary collapse

Class Method Summary collapse

Methods included from Protobuf::Logger::LogMethods

included, #log_exception, #log_signature, #sign_message

Class Attribute Details

.lifecycle_eventsObject

Returns the value of attribute lifecycle_events.



39
40
41
# File 'lib/protobuf/lifecycle.rb', line 39

def lifecycle_events
  @lifecycle_events
end

Class Method Details

.normalized_event_name(event_name) ⇒ Object



34
35
36
# File 'lib/protobuf/lifecycle.rb', line 34

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

.register(event_name, &blk) ⇒ Object Also known as: on



5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
# File 'lib/protobuf/lifecycle.rb', line 5

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 "        [DEPRECATED] ::Protobuf::Lifecycle has been deprecated and will be removed in a future version.\n                     Use ::ActiveSupport::Notifications.subscribe('\#{event_name}')\n    ERROR\n  end\n\n  ::ActiveSupport::Notifications.subscribe(event_name) do |name, start, finish, id, args|\n    blk.call(*args)\n  end\nend\n"

.trigger(event_name, *args) ⇒ Object



21
22
23
24
25
26
27
28
29
30
31
32
# File 'lib/protobuf/lifecycle.rb', line 21

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