Class: Falcon::Limiter::Socket

Inherits:
BasicObject
Defined in:
lib/falcon/limiter/socket.rb

Overview

A transparent socket wrapper that automatically manages token release. Behaves exactly like the wrapped socket but releases the limiter token on close.

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(delegate, token) ⇒ Socket

Initialize the socket wrapper with delegation and token management.



14
15
16
17
# File 'lib/falcon/limiter/socket.rb', line 14

def initialize(delegate, token)
	@delegate = delegate
	@token = token
end

Dynamic Method Handling

This class handles dynamic methods through the method_missing method

#method_missingObject

Transparent delegation to the wrapped delegate.



33
34
35
# File 'lib/falcon/limiter/socket.rb', line 33

def method_missing(...)
	@delegate.public_send(...)
end

Instance Attribute Details

#tokenObject (readonly)

Provide access to the token for manual management if needed.



20
21
22
# File 'lib/falcon/limiter/socket.rb', line 20

def token
  @token
end

Instance Method Details

#closeObject

Override close to release the token.



23
24
25
26
27
28
29
30
# File 'lib/falcon/limiter/socket.rb', line 23

def close
	@delegate.close
ensure
	if token = @token
		@token = nil
		token.release
	end
end

#inspectObject

Forward common inspection methods



53
54
55
# File 'lib/falcon/limiter/socket.rb', line 53

def inspect
	"#<#{Socket} #{@delegate.inspect}>"
end

#respond_to?(method, include_private = false) ⇒ Boolean

Check if this wrapper or the delegate responds to a method.

Returns:

  • (Boolean)


41
42
43
44
45
46
47
48
49
50
# File 'lib/falcon/limiter/socket.rb', line 41

def respond_to?(method, include_private = false)
	# Check our own methods first (token, close, inspect, to_s, etc.)
	case method.to_sym
	when :token
		true
	else
		# Check delegate for other methods
		@delegate.respond_to?(method, include_private)
	end
end

#to_sObject

String representation of the wrapped socket.



59
60
61
# File 'lib/falcon/limiter/socket.rb', line 59

def to_s
	@delegate.to_s
end