Class: Gruf::Hooks::Base

Inherits:
Object
  • Object
show all
Includes:
Loggable
Defined in:
lib/gruf/hooks/base.rb

Overview

Base class for a hook. Define before, around, outer_around, or after methods to utilize functionality.

Direct Known Subclasses

ActiveRecord::ConnectionReset

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods included from Loggable

#logger

Constructor Details

#initialize(service, options = {}) ⇒ Base

Initialize the hook and run setup

Parameters:

  • service (Gruf::Service)

    The gruf service that the hook will perform against

  • options (Hash) (defaults to: {})

    (Optional) A hash of options for this hook



36
37
38
39
40
# File 'lib/gruf/hooks/base.rb', line 36

def initialize(service, options = {})
  @service = service
  @options = options
  setup
end

Instance Attribute Details

#optionsHash (readonly)

Returns options Options to use for the hook.

Returns:

  • (Hash)

    options Options to use for the hook



28
29
30
# File 'lib/gruf/hooks/base.rb', line 28

def options
  @options
end

#serviceGruf::Service (readonly)

Returns service The service to perform the hook against.

Returns:

  • (Gruf::Service)

    service The service to perform the hook against



26
27
28
# File 'lib/gruf/hooks/base.rb', line 26

def service
  @service
end

Instance Method Details

#method_key(call_signature) ⇒ String

Parse the method signature into a service.method name format

Returns:

  • (String)

    The parsed service method name



61
62
63
# File 'lib/gruf/hooks/base.rb', line 61

def method_key(call_signature)
  "#{service_key}.#{call_signature.to_s.gsub('_without_intercept', '')}"
end

#service_keyString

Returns the service name as a translated name separated by periods

Returns:

  • (String)

    Returns the service name as a translated name separated by periods



52
53
54
# File 'lib/gruf/hooks/base.rb', line 52

def service_key
  service.class.name.underscore.tr('/', '.')
end

#setupObject

Method that can be used to setup the hook prior to running it



45
46
47
# File 'lib/gruf/hooks/base.rb', line 45

def setup
  # noop
end