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

Improve dump and dd features #519

Merged
merged 9 commits into from
Feb 3, 2022

Conversation

girardinsamuel
Copy link
Contributor

@girardinsamuel girardinsamuel commented Jan 28, 2022

This PR refactor dd and dump helpers by moving this into a dumps feature.
It should not be a breaking change. Builtins helpers are still there, there are no new providers.

TLDR

  • a Dump facade
  • dd and dump builtins are still there. clear_dumps builtin has been added
  • when using ClearDumpsBetweenRequestsMiddleware dumps are automatically deleted between each requests
  • we can make several dumps at different locations in code
  • when using dd which stands for "dump and die", a DumpException is raised and handled, showing a beautiful
    HTML page which contains all the dumps collected until dd has been called.
    For example, in the following controller method we can do:
def show(self, request: Request, view: View):
        dump({"test": "value"}, 1)
        my_var = "hello"
        dump(my_var)
        dd(request)  # == code will stop here, showing dump and die page
        return view.render("welcome")

It will then display this page instead of the welcome view:
image
image

  • dumped objects are analyzed to show private and public attributes. Standard python attributes starting with __ won't be shown.
  • dump timestamp along with method, filename and line where the call to dump has beeen made is displayed

API

from masonite.facades import Dump

# self.application.make("dumper") or you can use Dump facade

Dump.dump(obj1, obj2...) #== dump objects or you can use builtin dump()
Dump.dd(obj1, obj2...) #== dump objects and die raising a DumpException or you can use builtin dd()

Dump.get_dumps()  #== a list of Dump objects from newest to oldest
Dump.get_serialized_dumps() #== a serialized list of Dump objects from newest to oldest
Dump.last() #== last dumped object
Dump.clear() #== clear all dumps or you can use builtin clear_dumps()

@girardinsamuel girardinsamuel self-assigned this Jan 28, 2022
@josephmancuso josephmancuso merged commit 67fed63 into MasoniteFramework:4.0 Feb 3, 2022
@girardinsamuel girardinsamuel deleted the feat/dump branch February 3, 2022 08:22
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.

None yet

2 participants