Class: Protobuf::Lifecycle
- Inherits:
-
Object
- Object
- Protobuf::Lifecycle
show all
- Includes:
- Logging
- Defined in:
- lib/protobuf/lifecycle.rb
Class Attribute Summary collapse
Class Method Summary
collapse
Methods included from Logging
initialize_logger, #log_exception, #log_signature, #logger, logger, logger=, #sign_message
Class Attribute Details
.lifecycle_events ⇒ Object
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 <<-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
|
.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 <<-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
|