Class: FeatureHub::Sdk::Impl::SemanticVersionMatcher

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

Overview

matches using semantic versions

Instance Method Summary collapse

Instance Method Details

#match(supplied_value, attr) ⇒ Object



110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
# File 'lib/feature_hub/sdk/impl/strategy_wrappers.rb', line 110

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

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

  if cond.includes? || cond.equals?
    vals.any? { |v| val.satisfies?(v) }
  elsif cond.excludes? || cond.not_equals?
    vals.none? { |v| val.satisfies?(v) }
  else
    comparison_vals = vals.filter { |x| SemVersion.valid?(x) }
    if cond.greater?
      comparison_vals.any? { |v| supplied_value > v }
    elsif cond.greater_equals?
      comparison_vals.any? { |v| supplied_value >= v }
    elsif cond.less?
      comparison_vals.any? { |v| supplied_value < v }
    elsif cond.less_equals?
      comparison_vals.any? { |v| supplied_value <= v }
    else
      false
    end
  end
end