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

Migrate pretty print to Prism #262

Closed
palkan opened this issue May 4, 2024 · 0 comments
Closed

Migrate pretty print to Prism #262

palkan opened this issue May 4, 2024 · 0 comments
Labels
hackday RailsConf Hack Day challenges

Comments

@palkan
Copy link
Owner

palkan commented May 4, 2024

Context

Action Policy provides a useful pretty printing functionality that helps to see why the policy rule returns true or false:

irb> pp :feed?

MyPolicy#feed?
↳ (
    admin? #=> false
    OR
    allowed_to?(:access_feed?) #=> true
  )
  AND
  (
    user.name == "Jack" #=> false
    OR
    user.name == "Kate" #=> true
  )

Currently, it relies on Parse and Unparser gems; thus, requiring these libraries to present in the bundle to work. With Prism, we should be able to achieve the same behavior without any third-party dependencies.

TODO

Refactor utils/pretty_print to use Prism:

  • Prism Ruby API (it uses the same Visitor pattern that we already use with Parser)

  • Instead of unparsing, we can obtained the original source code string from node.location (using source[loc.start_offset...loc.end_offset]).

@palkan palkan added the hackday RailsConf Hack Day challenges label May 4, 2024
killondark added a commit to killondark/action_policy that referenced this issue May 9, 2024
palkan pushed a commit that referenced this issue May 21, 2024
@palkan palkan closed this as completed May 21, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
hackday RailsConf Hack Day challenges
Projects
None yet
Development

No branches or pull requests

1 participant