Module: Dry::Protocol

Defined in:
lib/dry/behaviour.rb,
lib/dry/errors/not_protocol.rb,
lib/dry/errors/not_implemented.rb,
lib/dry/errors/duplicate_definition.rb,
lib/dry/errors/malformed_definition.rb

Overview

rubocop:enable Style/EmptyCaseCondition rubocop:enable Style/AsciiIdentifiers

Defined Under Namespace

Classes: DuplicateDefinition, MalformedDefinition, NotImplemented, NotProtocol

Class Method Summary collapse

Class Method Details

.defimpl(protocol = nil, target: nil, delegate: [], map: {}, &λ) ⇒ Object

rubocop:disable Style/AsciiIdentifiers



27
28
29
# File 'lib/dry/behaviour.rb', line 27

def defimpl(protocol = nil, target: nil, delegate: [], map: {}, &λ)
  Dry::BlackTie.defimpl(protocol, target: target, delegate: delegate, map: map, &λ)
end

.implemented_for?(protocol, receiver) ⇒ Boolean

rubocop:disable Style/RaiseArgs

Returns:

  • (Boolean)

Raises:



33
34
35
36
# File 'lib/dry/behaviour.rb', line 33

def implemented_for?(protocol, receiver)
  raise ::Dry::Protocol::NotProtocol.new(protocol) unless protocol < ::Dry::Protocol
  !protocol.implementation_for(receiver).nil?
end

.included(base) ⇒ Object



21
22
23
# File 'lib/dry/behaviour.rb', line 21

def self.included(base)
  base.singleton_class.prepend(::Dry::BlackTie)
end