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 websocket routes to 'amber routes' output (#295) #492

Closed
wants to merge 1 commit into from
Closed

Add websocket routes to 'amber routes' output (#295) #492

wants to merge 1 commit into from

Conversation

docelic
Copy link
Contributor

@docelic docelic commented Jan 9, 2018

  • Show websocket routes in 'amber routes'
  • Avoid string "[Time] Class |" that used to be printed in the first line
    of output
  • Fix general issue where in case of Con::Troller, only "Con" would be printed
    in Controller column

- Show websocket routes in 'amber routes'
- Avoid string "<Time> Class |" that used to be printed in first line
  of output
- Fix issue where in case of Con::Troller, only "Con" would be printed
  in Controller column
Copy link
Contributor

@marksiemers marksiemers left a comment

Choose a reason for hiding this comment

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

Looks like a good approach.

I'll look into writing some specs. See inline comments.

@@ -120,8 +128,7 @@ module Amber::CLI
row.add_column route[l].to_s
end
end
puts table
exit
Copy link
Contributor

Choose a reason for hiding this comment

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

Any reason to remove exit?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Yes, there is no reason for the function named "print" to also exit automatically. I've moved "exit" to the run() method, where it properly exits after printing the table.

@@ -5,9 +5,10 @@ require "../helpers/sentry"
module Amber::CLI
class MainCommand < ::Cli::Supercommand
class Routes < Command
RESOURCE_ROUTE_REGEX = /(\w+)\s+\"([^\"]+)\",\s*(\w+)(?:,\s*(\w+)\:\s*\[([^\]]+)\])?/
VERB_ROUTE_REGEX = /(\w+)\s+\"([^\"]+)\",\s*(\w+),\s*:(\w+)/
PIPE_SCOPE_REGEX = /routes\s+\:(\w+)(?:,\s+\"([^\"]+)\")?/
Copy link
Contributor

Choose a reason for hiding this comment

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

Did any of these actually change? Or is this a whitespace diff?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

They changed. Two changes are made:

  1. A ":" is added inside the regex so that controllers containing ":" in the name would work properly
  2. And () were added around 'routes' and 'websockets' words even though not strictly necessary technically. (I've added them for consistency with other regexes and future expansion to cover multiple words)

@current_pipe = route_match[1]?
@current_scope = route_match[2]?
@current_pipe = route_match[2]?
@current_scope = route_match[3]?
Copy link
Contributor

Choose a reason for hiding this comment

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

Now I'm guessing those Regexs did change. Is there an extra capture group now?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Changed due to your #1 question above (my answer #2 there), so that's why the number increased.

verb: route_match[1]?, controller: route_match[3]?,
action: "", pipeline: current_pipe,
scope: current_scope, uri_pattern: route_match[2]?
)
Copy link
Contributor

Choose a reason for hiding this comment

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

It looks like there is only one difference here:

build_route(
  verb: route_match[1]?, controller: route_match[3]?,
  action: "", pipeline: current_pipe,
  scope: current_scope, uri_pattern: route_match[2]?
)

The action is an empty string when it is a websocket. Can this be DRYed up?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I was thinking this would be here for future more detailed separation/improvements to HTTP and websocket code paths which wouldn't be shared between both. But sure, can simplify for now, and the () around regexes that I've added at the top make this trivial. Will add a commit soon.

Copy link
Contributor Author

@docelic docelic Jan 9, 2018

Choose a reason for hiding this comment

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

Actually, not simple to DRY. If you find a way, please improve upon my patch. Thanks.

@marksiemers
Copy link
Contributor

@docelic - I added some tests in #494
I didn't have write access to your repo (I don't think) so I included your commit in another branch.

@docelic
Copy link
Contributor Author

docelic commented Jan 9, 2018

Great, I will close this PR and assume you'll handle #494. Thanks!

@docelic docelic closed this Jan 9, 2018
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.

2 participants