hyperstack-org / hyperstack-org/hyperstack

for policy white and black lists ignore nils, and flatten arrays

Offen
#319 0 Kommentare 0 Reaktionen 0 zugewiesene Personen Auf GitHub ansehen
enhancement good first issue
Vorherrschende Sprache
JavaScript
Sterne
538
Forks
41
PR-Merge-Kennzahlen
Keine gemergten PRs in 30 T.

Beschreibung

for example
`policy.send_all_but(nil).to(Application)`
should work.

It doesn't because it tries to convert nil to a symbol and fails.

This is handy for a case like this:

`policy.send_all_but(production_job? && :ship_by_date).to(Application)`

Otherwise the code looks like this:

```ruby
if production_job?
policy.send_all_but(:ship_by_date).to(Application)
else
policy.send_all.to(Application)
end

# or

policy.send_all_but(*[*(production_job? && :ship_by_date)]).to(Application)
```

Allowing an array of symbols to be passed in might also be handy in cases as well so basically we want to flatten and compress the parameters (which is already a splat) to `send_all_but` and `send_only`. We use `reject(&:!)` instead of `compact` so that any falsy value will be removed (false as well as nil.)

```ruby
module Hyperstack
class InternalPolicy
def send_all_but(*exceptions)
SendSet.new(self, exclude: exceptions.flatten.reject(&:!))
end

def send_only(*white_list)
SendSet.new(self, white_list: white_list.flatten.reject(&:!))
end
end
end
```

Beitragsleitfaden

Beitragsleitfaden öffnen

Bewertung

Dieses Issue wurde noch nicht bewertet.

Neue Issues direkt in Ihr Postfach

Eine kurze Übersicht über anfängerfreundliche GitHub-Issues.