Skip to content
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

Add detailed reasons #58

Merged
merged 2 commits into from
Mar 12, 2019
Merged

Add detailed reasons #58

merged 2 commits into from
Mar 12, 2019

Conversation

palkan
Copy link
Owner

@palkan palkan commented Mar 11, 2019

What is the purpose of this pull request?

Add ability to provide additional information to failure reasons.

What changes did you make? (overview)

Add details Hash to specify per-rule meta information:

class ApplicantPolicy < ApplicationPolicy
  def show?
    allowed_to?(:show?, object.stage)
  end
end

class StagePolicy < ApplicationPolicy
  def show?
    # Add stage title to the failure reason (if any)
    # (could be used by client to show more descriptive message)
    details[:title] = record.title
     # then perform the checks
    user.stages.where(id: record.id).exists?
  end
end

# when accessing the reasons
p ex.result.reasons.details #=> { stage: [{show?: {title: "Onboarding"}] }

The main purpose of this feature is to generate more descriptive failure messages with i18n.

No breaking public API changes.

PR checklist:

  • Tests included
  • Documentation updated
  • Changelog entry added

@palkan palkan changed the title feat: add detailed reasons Add detailed reasons Mar 11, 2019
@palkan palkan force-pushed the feat/detailed-reasons branch 10 times, most recently from 8e2c780 to 94ab2c7 Compare March 12, 2019 01:25
- Add focus/skip methods
- Add more meaningful exception messages
@palkan palkan force-pushed the feat/detailed-reasons branch from 94ab2c7 to 36ac95a Compare March 12, 2019 01:32
@palkan palkan merged commit 17ac5f2 into master Mar 12, 2019
@palkan palkan deleted the feat/detailed-reasons branch March 12, 2019 02:04
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant