Class: Minitext::AllowlistProxy

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

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(allowed:, gateway: nil) ⇒ AllowlistProxy

Returns a new instance of AllowlistProxy.



7
8
9
10
# File 'lib/minitext/allowlist_proxy.rb', line 7

def initialize(allowed:, gateway: nil)
  @allowed = Set.new(allowed)
  @gateway = gateway || TestGateway.new
end

Dynamic Method Handling

This class handles dynamic methods through the method_missing method

#method_missing(method, *args, &block) ⇒ Object



16
17
18
# File 'lib/minitext/allowlist_proxy.rb', line 16

def method_missing(method, *args, &block)
  gateway.send(method, *args, &block)
end

Instance Attribute Details

#allowedObject (readonly)

Returns the value of attribute allowed.



5
6
7
# File 'lib/minitext/allowlist_proxy.rb', line 5

def allowed
  @allowed
end

#gatewayObject (readonly)

Returns the value of attribute gateway.



5
6
7
# File 'lib/minitext/allowlist_proxy.rb', line 5

def gateway
  @gateway
end

Instance Method Details

#deliver(message) ⇒ Object



12
13
14
# File 'lib/minitext/allowlist_proxy.rb', line 12

def deliver(message)
  gateway.deliver(message) if allowed?(message.to)
end

#respond_to_missing?(method, *args) ⇒ Boolean

Returns:

  • (Boolean)


20
21
22
# File 'lib/minitext/allowlist_proxy.rb', line 20

def respond_to_missing?(method, *args)
  gateway.respond_to?(method)
end