Class: KO::Signals::Connection

Inherits:
Object
  • Object
show all
Defined in:
lib/ko/signals/connection.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(receiver, signal, mode:, one_shot:) ⇒ Connection

Returns a new instance of Connection.



8
9
10
11
12
13
# File 'lib/ko/signals/connection.rb', line 8

def initialize(receiver, signal, mode:, one_shot:)
  @receiver = receiver
  @signal = signal
  @mode = mode
  @one_shot = one_shot
end

Instance Attribute Details

#modeObject (readonly)

Returns the value of attribute mode.



6
7
8
# File 'lib/ko/signals/connection.rb', line 6

def mode
  @mode
end

#receiverObject (readonly)

Returns the value of attribute receiver.



6
7
8
# File 'lib/ko/signals/connection.rb', line 6

def receiver
  @receiver
end

#signalObject (readonly)

Returns the value of attribute signal.



6
7
8
# File 'lib/ko/signals/connection.rb', line 6

def signal
  @signal
end

Instance Method Details

#call(*args, force_direct: false) ⇒ Object

rubocop:disable Lint/UnusedMethodArgument



17
18
19
20
21
22
23
# File 'lib/ko/signals/connection.rb', line 17

def call(*args, force_direct: false) # rubocop:disable Lint/UnusedMethodArgument
  @receiver.call(*args)
rescue StandardError => e
  warn(e)
ensure
  disconnect if one_shot?
end

#disconnectObject



25
# File 'lib/ko/signals/connection.rb', line 25

def disconnect = @signal.disconnect(@receiver)

#one_shot?Boolean

Returns:

  • (Boolean)


15
# File 'lib/ko/signals/connection.rb', line 15

def one_shot? = @one_shot