Module: Contracts::Core

Defined in:
lib/contracts/core.rb

Class Method Summary collapse

Class Method Details

.common(base) ⇒ Object



11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
# File 'lib/contracts/core.rb', line 11

def self.common(base)
  base.extend(MethodDecorators)

  base.instance_eval do
    def functype(funcname)
      contracts = Engine.fetch_from(self).decorated_methods_for(:class_methods, funcname)
      return "No contract for #{self}.#{funcname}" if contracts.nil?
      "#{funcname} :: #{contracts[0]}"
    end
  end

  base.class_eval do
    def functype(funcname)
      contracts = Engine.fetch_from(self.class).decorated_methods_for(:instance_methods, funcname)
      return "No contract for #{self.class}.#{funcname}" if contracts.nil?
      "#{funcname} :: #{contracts[0]}"
    end
  end
end

.extended(base) ⇒ Object



7
8
9
# File 'lib/contracts/core.rb', line 7

def self.extended(base)
  common(base)
end

.included(base) ⇒ Object



3
4
5
# File 'lib/contracts/core.rb', line 3

def self.included(base)
  common(base)
end