Module: Insika::Allowlist
- Defined in:
- lib/insika/allowlist.rb
Overview
Profile allowlist semantics, defined once: nil = all; [] = none; [names] = subset. It used to be copied in the Builder, the SkillCatalog and the policies — the rule must live in a single place.
Class Method Summary collapse
-
.allows?(allow, value) ⇒ Boolean
Per-item boolean variant (to compose with other filters in a select).
-
.filter(candidates, allow, &key) ⇒ Object
Filters a collection by the allowlist, comparing
key.call(candidate)(or the candidate itself) against the allowed names.
Class Method Details
.allows?(allow, value) ⇒ Boolean
Per-item boolean variant (to compose with other filters in a select).
21 22 23 24 25 26 |
# File 'lib/insika/allowlist.rb', line 21 def allows?(allow, value) return true if allow.nil? return false if allow.empty? Array(allow).map(&:to_s).include?(value.to_s) end |
.filter(candidates, allow, &key) ⇒ Object
Filters a collection by the allowlist, comparing key.call(candidate) (or the
candidate itself) against the allowed names.
12 13 14 15 16 17 18 |
# File 'lib/insika/allowlist.rb', line 12 def filter(candidates, allow, &key) return candidates if allow.nil? return [] if allow.empty? names = Array(allow).map(&:to_s) candidates.select { |c| names.include?((key ? key.call(c) : c).to_s) } end |