Class: Unleash::Strategy::RemoteAddress
- Defined in:
- lib/unleash/strategy/remote_address.rb
Constant Summary collapse
- PARAM =
'IPs'.freeze
Instance Method Summary collapse
-
#is_enabled?(params = {}, context = nil) ⇒ Boolean
need: params, context.remote_address.
- #name ⇒ Object
Instance Method Details
#is_enabled?(params = {}, context = nil) ⇒ Boolean
need: params, context.remote_address
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 |
#name ⇒ Object
6 7 8 |
# File 'lib/unleash/strategy/remote_address.rb', line 6 def name 'remoteAddress' end |