Skip to content

Simplify the logic in _require.erb #2303

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Sep 8, 2022

Conversation

ekohl
Copy link
Collaborator

@ekohl ekohl commented Sep 7, 2022

If we take the expression:

!(_item['require'] && _item['require'] != '') && _item['require'] !~ /unmanaged/i && !(_item['auth_require'])

This is hard to read, but equal to:

(!_item['require'] || _item['require'] == '') && _item['require'] !~ /unmanaged/i && !(_item['auth_require'])

This makes it easier to see that item must be nil or ''. Those will never match /unmanaged/i so it can be simplified to:

(!_item['require'] || _item['require'] == '') && !(_item['auth_require'])

Just before it is a block that already checks the last section, so it can be reduced to an elsif on that block.

If we take the expression:

    !(_item['require'] && _item['require'] != '') && _item['require'] !~ /unmanaged/i && !(_item['auth_require'])

This is hard to read, but equal to:

    (!_item['require'] || _item['require'] == '') && _item['require'] !~ /unmanaged/i && !(_item['auth_require'])

This makes it easier to see that item must be `nil` or `''`. Those will
never match `/unmanaged/i` so it can be simplified to:

    (!_item['require'] || _item['require'] == '') && !(_item['auth_require'])

Just before it is a block that already checks the last section, so it
can be reduced to an elsif on that block.
Copy link
Member

@david22swan david22swan left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM
Logic looks much cleaner now

@david22swan david22swan merged commit accb538 into puppetlabs:main Sep 8, 2022
@ekohl ekohl deleted the simplify-require-logic branch September 8, 2022 08:45
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants