Module: Pangea::ProviderContract
- Defined in:
- lib/pangea/provider_contract.rb
Overview
Defined Under Namespace
Modules: Metadata Classes: ViolationError
Class Method Summary collapse
-
.check(provider_module, prefix: nil) ⇒ Object
Check without raising — returns [valid?, errors].
-
.validate!(provider_module, prefix: nil) ⇒ Object
Validate that a module satisfies the provider contract.
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.]] end |
.validate!(provider_module, prefix: nil) ⇒ Object
Validate that a module satisfies the provider contract.
A valid provider module must:
-
Be a Module (not a Class)
-
Define at least one resource method (matching its prefix)
-
Be extendable onto a synthesizer object
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 |