Module: Technologic::ClassMethods

Defined in:
lib/technologic.rb

Instance Method Summary collapse

Instance Method Details

#_tl_instrument(severity, event, **data, &block) ⇒ Object (protected)



108
109
110
111
112
113
114
115
# File 'lib/technologic.rb', line 108

def _tl_instrument(severity, event, **data, &block)
  ActiveSupport::Notifications.instrument("#{event}.#{name}.#{severity}", data, &block).tap do
    # If a block was defined, :instrument will return the value of the block.
    # Otherwise, :instrument will return nil, since it didn't do anything.
    # Returning true here allows us to do fun things like `info :subscription_created and return subscription`
    return true unless block_given?
  end
end

#instrument(*args, **opts, &block) ⇒ Object

DEP-2021-01-14 Remove this method



65
66
67
68
69
# File 'lib/technologic.rb', line 65

def instrument(*args, **opts, &block)
  ActiveSupport::Deprecation.warn("Technologic.instrument is deprecated. Instead, use the corresponding severity-level convenience method (#info, #error etc)")

  _tl_instrument(*args, **opts, &block)
end

#surveil(event, severity: :info, **data, &block) ⇒ Object

Raises:

  • (LocalJumpError)


71
72
73
74
75
76
77
78
# File 'lib/technologic.rb', line 71

def surveil(event, severity: :info, **data, &block)
  raise LocalJumpError unless block_given?

  raise ArgumentError, "Invalid severity: #{severity}" unless severity.to_sym.in?(SEVERITIES)

  _tl_instrument(severity, "#{event}_started", **data)
  _tl_instrument(severity, "#{event}_finished", &block)
end