Class: FeatureHub::Sdk::Impl::IpNetworkMatcher

Inherits:
StrategyMatcher show all
Defined in:
lib/feature_hub/sdk/impl/strategy_wrappers.rb

Overview

matches based on ip addresses and CIDRs

Instance Method Summary collapse

Instance Method Details

#match(supplied_value, attr) ⇒ Object



139
140
141
142
143
144
145
146
147
148
149
150
151
152
# File 'lib/feature_hub/sdk/impl/strategy_wrappers.rb', line 139

def match(supplied_value, attr)
  cond = attr.conditional

  val = IPAddr.new(supplied_value)
  vals = attr.str_values

  if cond.includes? || cond.equals?
    vals.any? { |v| IPAddr.new(v).include?(val) }
  elsif cond.excludes? || cond.not_equals?
    vals.none? { |v| IPAddr.new(v).include?(val) }
  else
    false
  end
end