@@ -442,17 +442,8 @@ defmodule Flagsmith.Engine do
442442 trait_value: t_value
443443 } ->
444444 case prop == t_key do
445- true ->
446- case cast_value ( t_value , value ) do
447- { :ok , casted } ->
448- trait_match ( operator , casted , t_value )
449-
450- _ ->
451- false
452- end
453-
454- _ ->
455- false
445+ true -> trait_match ( operator , value , t_value )
446+ _ -> false
456447 end
457448 end )
458449 end
@@ -580,10 +571,21 @@ defmodule Flagsmith.Engine do
580571 end
581572 end
582573
583- def trait_match ( :MODULO , trait , % Trait.Value { value: value } ) do
584- with true <- is_binary ( trait ) ,
574+ def trait_match ( :IN , condition_value , % Trait.Value { type: :string , value: t_value } ) do
575+ Enum . member? ( String . split ( condition_value , "," ) , t_value )
576+ end
577+
578+ def trait_match ( :IN , condition_value , % Trait.Value {
579+ type: :decimal ,
580+ value: % Decimal { exp: 0 } = t_value
581+ } ) do
582+ Enum . member? ( String . split ( condition_value , "," ) , t_value |> Decimal . to_string ( ) )
583+ end
584+
585+ def trait_match ( :MODULO , condition_value , % Trait.Value { value: value } ) do
586+ with true <- is_binary ( condition_value ) ,
585587 % Decimal { } <- value ,
586- [ mod , result ] <- String . split ( trait , "|" ) ,
588+ [ mod , result ] <- String . split ( condition_value , "|" ) ,
587589 % Decimal { } = mod_val <- Decimal . new ( mod ) ,
588590 % Decimal { } = result_val <- Decimal . new ( result ) ,
589591 % Decimal { } = remainder <- Decimal . rem ( value , mod_val ) do
@@ -595,7 +597,7 @@ defmodule Flagsmith.Engine do
595597 rescue
596598 Decimal.Error ->
597599 Logger . warn (
598- "invalid MODULO segment rule or trait value :: rule: #{ inspect ( trait ) } :: value: #{ inspect ( value ) } "
600+ "invalid MODULO segment rule or trait value :: rule: #{ inspect ( condition_value ) } :: value: #{ inspect ( value ) } "
599601 )
600602
601603 false
0 commit comments