Module: Rosette::Integrations::Integratable

Included in:
Core::Configurator, Core::RepoConfig
Defined in:
lib/rosette/integrations/integratable.rb

Overview

Intended to be mixed in to classes that can be integrated with. Provides methods to add and retrieve integration configs as well as apply configured integrations to the parent.

Instance Method Summary collapse

Instance Method Details

#add_integration(integration_id) {|config| ... } ⇒ void

This method returns an undefined value.

Add an integration. Yields an instance of the integration's configurator object to the given block.

Parameters:

  • integration_id (String)

    The id of the integration to add.

Yields:

  • (config)

Yield Parameters:

  • config

    The integration's configurator.


24
25
26
27
# File 'lib/rosette/integrations/integratable.rb', line 24

def add_integration(integration_id, &block)
  klass = Rosette::Core::IntegrationId.resolve(integration_id)
  integrations << klass.configure(&block)
end

#apply_integrations(obj) ⇒ void

This method returns an undefined value.

Applies the integrations to the given object.

Parameters:

  • obj (Object)

    The object to apply the integrations to.


48
49
50
51
52
53
54
# File 'lib/rosette/integrations/integratable.rb', line 48

def apply_integrations(obj)
  integrations.each do |integration|
    if integration.integrates_with?(obj)
      integration.integrate(obj)
    end
  end
end

#get_integration(integration_id) ⇒ nil, Object

Retrieve the integration config by id.

Parameters:

  • integration_id (String)

    The integration id.

Returns:

  • (nil, Object)

    The integration's configurator.


33
34
35
36
37
38
39
40
41
42
# File 'lib/rosette/integrations/integratable.rb', line 33

def get_integration(integration_id)
  klass = Rosette::Core::IntegrationId.resolve(integration_id)

  if klass
    integrations.find do |integration|
      integration.is_a?(klass)
    end
  end
rescue ArgumentError
end

#integrationsArray

Returns the current list of integration configs.

Returns:

  • (Array)

13
14
15
# File 'lib/rosette/integrations/integratable.rb', line 13

def integrations
  @integrations ||= []
end