Class: Unleash::Strategy::RemoteAddress

Inherits:
Base
  • Object
show all
Defined in:
lib/unleash/strategy/remote_address.rb

Constant Summary collapse

PARAM =
'IPs'.freeze

Instance Method Summary collapse

Instance Method Details

#is_enabled?(params = {}, context = nil) ⇒ Boolean

need: params, context.remote_address

Returns:

  • (Boolean)


11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
# File 'lib/unleash/strategy/remote_address.rb', line 11

def is_enabled?(params = {}, context = nil)
  return false unless params.is_a?(Hash) && params.has_key?(PARAM)
  return false unless params.fetch(PARAM, nil).is_a? String
  return false unless context.instance_of?(Unleash::Context)

  remote_address = ipaddr_or_nil_from_str(context.remote_address)

  params[PARAM]
    .split(',')
    .map(&:strip)
    .map{ |ipblock| ipaddr_or_nil_from_str(ipblock) }
    .compact
    .map{ |ipb| ipb.include? remote_address }
    .any?
end

#nameObject



6
7
8
# File 'lib/unleash/strategy/remote_address.rb', line 6

def name
  'remoteAddress'
end