Class: Waylon::WebhookRegistry

Inherits:
Object
  • Object
show all
Includes:
Singleton
Defined in:
lib/waylon/webhook_registry.rb

Overview

Registry of Webhook subclasses known to Waylon

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Instance Attribute Details

#webhooksObject (readonly)

Returns the value of attribute webhooks.



8
9
10
# File 'lib/waylon/webhook_registry.rb', line 8

def webhooks
  @webhooks
end

Class Method Details

.register(name, class_name) ⇒ Class

A convenience wrapper around the singleton instance #register method

Parameters:

  • name (String)

    The name of the Webhook in the registry

  • class_name (Class)

    The Webhook subclass to add

Returns:

  • (Class)

    The Webhook subclass



13
14
15
# File 'lib/waylon/webhook_registry.rb', line 13

def self.register(name, class_name)
  instance.register(name, class_name)
end

Instance Method Details

#register(name, class_name) ⇒ Class

Add the provided Webhook class to the registry under ‘name`

Parameters:

  • name (String)

    The name of the Webhook in the registry

  • class_name (Class)

    The Webhook subclass to add

Returns:

  • (Class)

    The Webhook subclass



21
22
23
24
# File 'lib/waylon/webhook_registry.rb', line 21

def register(name, class_name)
  @webhooks ||= {}
  @webhooks[name.to_s] = class_name
end

#to_hashHash

Provides a Hash version of this registry

Returns:

  • (Hash)


28
29
30
# File 'lib/waylon/webhook_registry.rb', line 28

def to_hash
  (@webhooks || {}).transform_keys { |k| "/hooks/#{k}" }
end