commit 3a3c66d: [Minor] Add selector transformer `filter_method`

Vsevolod Stakhov vsevolod at rspamd.com
Tue Oct 31 15:21:03 UTC 2023


Author: Vsevolod Stakhov
Date: 2023-10-31 15:18:22 +0000
URL: https://github.com/rspamd/rspamd/commit/3a3c66d232b6e91e3baf8cf6c9c64b48d63e57a8 (HEAD -> master)

[Minor] Add selector transformer `filter_method`

---
 lualib/lua_selectors/transforms.lua | 23 ++++++++++++++++++++++-
 1 file changed, 22 insertions(+), 1 deletion(-)

diff --git a/lualib/lua_selectors/transforms.lua b/lualib/lua_selectors/transforms.lua
index 4b839de28..6c6bc7117 100644
--- a/lualib/lua_selectors/transforms.lua
+++ b/lualib/lua_selectors/transforms.lua
@@ -542,7 +542,28 @@ Empty string comes the first argument or 'true', non-empty string comes nil]],
       return res, 'string_list'
     end,
     ['description'] = 'Apply a list of method calls to the userdata object',
-  }
+  },
+  -- Apply method to list of userdata and use it as a filter, excluding elements for which method returns false/nil
+  ['filter_method'] = {
+    ['types'] = {
+      ['userdata_list'] = true
+    },
+    ['process'] = function(inp, t, args)
+      local meth = args[1]
+
+      if not meth then
+        logger.errx('invalid method name: %s', args[1])
+        return nil
+      end
+
+      return fun.filter(function(val)
+        return val[meth](val)
+      end, inp), 'userdata_list'
+    end,
+    ['description'] = 'Apply method to list of userdata and use it as a filter,' ..
+        ' excluding elements for which method returns false/nil',
+    ['args_schema'] = { ts.string }
+  },
 }
 
 transform_function.match = transform_function.regexp


More information about the Commits mailing list