Class: Contracts::Registry

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

Instance Method Summary collapse

Constructor Details

#initializeRegistry

Returns a new instance of Registry.



429
430
431
432
# File 'lib/contracts.rb', line 429

def initialize
  (@lock = Monitor.new
   @contracts = {})
end

Instance Method Details

#allObject



447
# File 'lib/contracts.rb', line 447

def all = @lock.synchronize { @contracts.values.dup.freeze }

#find(owner, method_name, method_type: :instance) ⇒ Object



440
441
442
443
444
# File 'lib/contracts.rb', line 440

def find(owner, method_name, method_type: :instance)
  @lock.synchronize do
    @contracts[[owner, method_type, method_name.to_sym]] || inherited(owner, method_name, method_type)
  end
end

#for_class(owner) ⇒ Object



446
# File 'lib/contracts.rb', line 446

def for_class(owner) = @lock.synchronize { @contracts.values.select { |c| c.owner == owner }.dup.freeze }

#register(contract) ⇒ Object



434
435
436
437
438
# File 'lib/contracts.rb', line 434

def register(contract)
  @lock.synchronize do
    @contracts[[contract.owner, contract.method_type, contract.method_name]] = contract
  end
end