Class: Collavre::IntegrationRegistry

Inherits:
Object
  • Object
show all
Includes:
Singleton
Defined in:
lib/collavre/integration_registry.rb

Overview

Registry for third-party integrations (Slack, GitHub, Notion, etc.) Allows extensions to register themselves and provide UI components without modifying the core Collavre engine.

Examples:

Registering an integration

Collavre::IntegrationRegistry.register(:slack, {
  label: "Slack",
  icon: "slack",
  description: "Sync chat messages with Slack channels",
  routes: CollavreSlack::Engine.routes.url_helpers,
  creative_menu_partial: "collavre_slack/integrations/creative_menu",
  settings_partial: "collavre_slack/integrations/settings"
})

Instance Method Summary collapse

Constructor Details

#initializeIntegrationRegistry

Returns a new instance of IntegrationRegistry.



21
22
23
24
# File 'lib/collavre/integration_registry.rb', line 21

def initialize
  @integrations = {}
  @mutex = Mutex.new
end

Instance Method Details

#allObject

Get all registered integrations



60
61
62
63
64
# File 'lib/collavre/integration_registry.rb', line 60

def all
  @mutex.synchronize do
    @integrations.values
  end
end

#any?Boolean

Check if any integrations are registered

Returns:

  • (Boolean)


72
73
74
75
76
# File 'lib/collavre/integration_registry.rb', line 72

def any?
  @mutex.synchronize do
    @integrations.any?
  end
end

#each(&block) ⇒ Object

Iterate over all integrations



67
68
69
# File 'lib/collavre/integration_registry.rb', line 67

def each(&block)
  all.each(&block)
end

#find(name) ⇒ Object

Get a specific integration by name



53
54
55
56
57
# File 'lib/collavre/integration_registry.rb', line 53

def find(name)
  @mutex.synchronize do
    @integrations[name.to_sym]
  end
end

#register(name, config) ⇒ Object

Register a new integration

Parameters:

  • name (Symbol)

    Unique identifier for the integration

  • config (Hash)

    Configuration options

Options Hash (config):

  • :label (String)

    Display name

  • :icon (String)

    Icon identifier (optional)

  • :description (String)

    Brief description (optional)

  • :routes (Object)

    Engine routes url_helpers

  • :creative_menu_partial (String)

    Partial for creative action menu

  • :settings_partial (String)

    Partial for settings page (optional)

  • :enabled_for (Proc)

    Lambda to check if enabled for a creative (optional)



36
37
38
39
40
41
42
43
# File 'lib/collavre/integration_registry.rb', line 36

def register(name, config)
  integration = Integration.new(name, config)
  @mutex.synchronize do
    @integrations[name.to_sym] = integration
  end
  Rails.logger.info("[Collavre] Integration registered: #{name}")
  integration
end

#reset!Object

Clear all integrations (useful for testing)



79
80
81
82
83
# File 'lib/collavre/integration_registry.rb', line 79

def reset!
  @mutex.synchronize do
    @integrations = {}
  end
end

#unregister(name) ⇒ Object

Unregister an integration



46
47
48
49
50
# File 'lib/collavre/integration_registry.rb', line 46

def unregister(name)
  @mutex.synchronize do
    @integrations.delete(name.to_sym)
  end
end