Class: Callme::ContractValidator

Inherits:
Object
  • Object
show all
Defined in:
lib/callme/contract_validator.rb

Overview

Instance Method Summary collapse

Instance Method Details

#validate(dependency_class, contract_class, const_loader) ⇒ Object



4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
# File 'lib/callme/contract_validator.rb', line 4

def validate(dependency_class, contract_class, const_loader)
  contract_class = const_loader.load_const(contract_class) if contract_class.is_a?(String)
  #get the methods defined for the contract
  contract_methods = (contract_class.instance_methods - Object.instance_methods)
  #get the methods defined for the dependency
  dependency_methods = (dependency_class.instance_methods - Object.instance_methods)
  #calculate any methods specified in the contract that are not specified in the dependency
  missing_methods = contract_methods - dependency_methods

  if !missing_methods.empty?
    raise Callme::Errors::DependencyContractMissingMethodsException.new({
        dep: dependency_class,
        contract: contract_class,
        missing: missing_methods
    })
  end

  validate_methods(dependency_class, contract_class, contract_methods)
end