Module: Pangea::ProviderContract

Defined in:
lib/pangea/provider_contract.rb

Overview

Contract that all provider modules must satisfy. Validates that a provider gem exposes the expected interface for cross-provider composition in pangea-architectures.

Usage:

Pangea::ProviderContract.validate!(Pangea::Resources::AWS)

Defined Under Namespace

Modules: Metadata Classes: ViolationError

Class Method Summary collapse

Class Method Details

.check(provider_module, prefix: nil) ⇒ Object

Check without raising — returns [valid?, errors]



39
40
41
42
43
44
# File 'lib/pangea/provider_contract.rb', line 39

def self.check(provider_module, prefix: nil)
  validate!(provider_module, prefix: prefix)
  [true, []]
rescue ViolationError => e
  [false, [e.message]]
end

.validate!(provider_module, prefix: nil) ⇒ Object

Validate that a module satisfies the provider contract.

A valid provider module must:

  1. Be a Module (not a Class)

  2. Define at least one resource method (matching its prefix)

  3. Be extendable onto a synthesizer object

Parameters:

  • provider_module (Module)

    The provider module to validate

  • prefix (String) (defaults to: nil)

    Expected resource method prefix (e.g., ‘aws_’)

Raises:



24
25
26
27
28
29
30
31
32
33
34
35
36
# File 'lib/pangea/provider_contract.rb', line 24

def self.validate!(provider_module, prefix: nil)
  unless provider_module.is_a?(Module) && !provider_module.is_a?(Class)
    raise ViolationError, "#{provider_module} must be a Module, got #{provider_module.class}"
  end

  if prefix
    methods = provider_module.instance_methods(false)
    matching = methods.select { |m| m.to_s.start_with?(prefix) }
    if matching.empty?
      raise ViolationError, "#{provider_module} has no methods starting with '#{prefix}'"
    end
  end
end