From: Vsevolod Stakhov Date: Tue, 31 Oct 2023 15:18:22 +0000 (+0000) Subject: [Minor] Add selector transformer `filter_method` X-Git-Tag: 3.8.0~96 X-Git-Url: https://source.dussan.org/?a=commitdiff_plain;h=3a3c66d232b6e91e3baf8cf6c9c64b48d63e57a8;p=rspamd.git [Minor] Add selector transformer `filter_method` --- 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