Reputation: 2900
I've got a field from github webhook - webhook.repository.private
- which checks if created repository was private (boolean). I want use return if
block to handle scenario:
check if webhook.repository.private
is true and if not call new class PublicRepositoryCreated
but if this is true - return and execute fields_hash
code below:
def required_fields
PublicRepositoryCreated.new(webhook).call unless webhook.repository.private
fields_hash
end
private
def fields_hash
{
'fields' => {
'summary' => 'summary',
'description' => 'description',
'project' => '123'
}
}
end
Right now it seems that fields_hash
is still executed even when webhook.repository.private
is false
Upvotes: 1
Views: 1241
Reputation: 4656
You have multiple ways of solving your problem.
You can either :
def required_fields
PublicRepositoryCreated.new(webhook).call && return unless webhook.repository.private
fields_hash
end
def required_fields
return PublicRepositoryCreated.new(webhook).call unless webhook.repository.private
fields_hash
end
def required_fields
webhook.repository.private ? fields_hash : PublicRepositoryCreated.new(webhook).call
end
Upvotes: 2