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.



489
490
491
492
# File 'lib/contracts.rb', line 489

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

Instance Method Details

#allObject



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

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

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



500
501
502
503
504
# File 'lib/contracts.rb', line 500

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



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

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

#register(contract) ⇒ Object



494
495
496
497
498
# File 'lib/contracts.rb', line 494

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