View Source Conditioner (Conditioner v0.2.2)

Conditioner allows you to define and process conditional logic in separated way:

  1. Create logical representation of conditions:
conditions = %{
    "and" => [
      ["filename", "containsfn", "he"],
      ["filename", "containsfn", "lo"],
      ["otherrule", "contains", "lo"],
      %{
        "or" => [
          ["filename", "containsfn", "bo"],
          ["filename", "containsfn", "he"],
          %{"and" => true}
        ]
      }
    ]
  }
  1. Define matcher module with rules:
defmodule SomeMatcher do
  use Conditioner.Matcher

  def match?(["filename", "containsfn", str], _original_value) do
    fn val ->
      String.contains?(val, str)
    end
  end

  def match?(["otherrule", "contains", str], value) do
    String.contains?(value, str)
  end
end
  1. Verify conditions by calling matcher with rules:
result = Conditioner.match?(conditions, "hello", SomeMatcher)

Link to this section Summary

Link to this section Functions

Link to this function

match?(conditions, value, matcher)

View Source
@spec match?(map(), any(), any()) :: boolean()
@spec match?(list(), any(), any()) :: boolean()