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

[Controller] Adds Route Helper Methods to Controller #362

Merged
merged 4 commits into from Nov 8, 2017

Conversation

eliasjpr
Copy link
Contributor

@eliasjpr eliasjpr commented Nov 5, 2017

As a developer I want to have access to the current matched
route information such as the Action, Controller, Resource
and Scope accessed.

This adds a Route helper file

  • Includes the following methods route_action, route_controller,
    route_resource, route_scope in the controller

Alternate Design

I thought of using a different name such as action_name, controller_name
but it seemed more explicit to have route_ prefix to hint the user where is
this information is coming from.

> As a developer I want to have access to the current matched
route information such as the Action, Controller, Resource
and Scope accessed.

This adds a Route helper file
- Includes the following methods route_action, route_controller,
route_resource, route_scope in the controller

### Alternate Design

I thought of using a different name such as action_name, controller_name
but it seemed more explicit to have `route_` prefix to hint the user where is
this information is coming from.
@eliasjpr eliasjpr requested review from a team, drujensen, marksiemers, faustinoaq and veelenga and removed request for a team November 5, 2017 13:30
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.

Overall, looks good.
The regex should be changed, but all other comments are optional.

end

def controller_name
self.class.name.gsub(/Controller/i, "")
Copy link
Contributor

Choose a reason for hiding this comment

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

For this regex, I would anchor to the end. And does the i make it case-insensitive, is that necessary?

https://play.crystal-lang.org/#/r/31bu

Copy link
Contributor

Choose a reason for hiding this comment

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

Would people want the controller name downcased?

Copy link
Contributor

Choose a reason for hiding this comment

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

Yeah, I think we should use /Controller$/

Copy link
Contributor Author

Choose a reason for hiding this comment

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

You guys are correct I will also fix the regex. I looked at the rails implementation

https://apidock.com/rails/ActionController/Metal/controller_name/class

Copy link
Member

Choose a reason for hiding this comment

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

Use sub instead of gsub since we only want to replace once.

controller.responds_to?(:route_action).should eq true
controller.responds_to?(:route_resource).should eq true
controller.responds_to?(:route_scope).should eq true
controller.responds_to?(:route_controller).should eq true
Copy link
Contributor

Choose a reason for hiding this comment

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

Do all of these need to be prefixed with route_?

Copy link
Contributor Author

@eliasjpr eliasjpr Nov 5, 2017

Choose a reason for hiding this comment

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

I prefixed to avoid name collisions with methods define by the user. I am open to suggestions

@eliasjpr eliasjpr changed the title Adds Route Helper Methods to Controller [Controller] Adds Route Helper Methods to Controller Nov 7, 2017
@eliasjpr eliasjpr merged commit 8ba8c03 into master Nov 8, 2017
@eliasjpr eliasjpr deleted the ep/add-helpers branch November 8, 2017 12:23
elorest pushed a commit that referenced this pull request Nov 17, 2017
* Adds Route Helper Methods to Controller


> As a developer I want to have access to the current matched
route information such as the Action, Controller, Resource
and Scope accessed.

This adds a Route helper file
- Includes the following methods route_action, route_controller,
route_resource, route_scope in the controller

### Alternate Design

I thought of using a different name such as action_name, controller_name
but it seemed more explicit to have `route_` prefix to hint the user where is
this information is coming from.

* fixup! Adds Route Helper Methods to Controller
elorest pushed a commit that referenced this pull request Nov 17, 2017
* Adds Route Helper Methods to Controller


> As a developer I want to have access to the current matched
route information such as the Action, Controller, Resource
and Scope accessed.

This adds a Route helper file
- Includes the following methods route_action, route_controller,
route_resource, route_scope in the controller

### Alternate Design

I thought of using a different name such as action_name, controller_name
but it seemed more explicit to have `route_` prefix to hint the user where is
this information is coming from.

* fixup! Adds Route Helper Methods to Controller


Former-commit-id: 3df8c1e
@faustinoaq faustinoaq added this to Done in Framework 2018 May 5, 2018
@faustinoaq faustinoaq removed this from Done in Framework 2018 Jun 12, 2018
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
No open projects
Development

Successfully merging this pull request may close these issues.

None yet

4 participants