Skip to content

Refactor Router#5177

Merged
varyonic merged 15 commits intoactiveadmin:masterfrom
activeadmin-rails:refactor-router
Sep 22, 2017
Merged

Refactor Router#5177
varyonic merged 15 commits intoactiveadmin:masterfrom
activeadmin-rails:refactor-router

Conversation

@varyonic
Copy link
Contributor

@varyonic varyonic commented Sep 15, 2017

This series of refactorings, heavily inspired by #3170, replaces all use of proc (x5) and instance_exec (x6) in Router with vanilla method calls, making it easier to understand and maintain.

@varyonic
Copy link
Contributor Author

I don't understand why codecov/patch failed here.

@deivid-rodriguez
Copy link
Member

I think it's been a big coincidence that the coverage of your patch matches the global coverage of the project 😲. Probably your patch loses at the third decimal digit.

I normally use a more relaxed configuration for this in codecov.yml, such as

    patch:
      default:
        target: 50%

@deivid-rodriguez
Copy link
Member

Yeah, getting the patch 100% covered is another option 😃.

@deivid-rodriguez
Copy link
Member

By the way, codeclimate just rolled out their out code coverage status checks in PR, and they chose 80% as a default for this setting: https://codeclimate.com/changelog/59baa212ced24c026c0017b8.

@varyonic varyonic requested a review from Fivell September 18, 2017 12:14
Copy link
Member

@Fivell Fivell left a comment

Choose a reason for hiding this comment

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

I started review commit by commit , but in the end looks like all my comments were fixed

end

# Deals with +ControllerAction+ instances
# Builds one route for each HTTP verb passed in
Copy link
Member

Choose a reason for hiding this comment

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

@varyonic , I think this methods should be tested or defined as private

router.collection do
config.collection_actions.each { |action| build_action(router, action) }
router.post :batch_action if config.batch_actions_enabled?
end
Copy link
Member

Choose a reason for hiding this comment

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

@varyonic , is this big diff necessary?

router.member do
config.member_actions.each { |action| build_action(router, action) }
end

Copy link
Member

Choose a reason for hiding this comment

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

these might be not public too ?

#
# @param router [ActionDispatch::Routing::Mapper]
def apply(router)
def apply(router = @router)
Copy link
Member

Choose a reason for hiding this comment

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

@varyonic, not sure this commit makes code more cleaner, I don't understand now if there there are cases when different routers can be used for initialize and apply method ? in other words after router passed to constructor, why this method needs argument

Copy link
Member

Choose a reason for hiding this comment

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

@varyonic ignore this since it was fixed by next commit

Copy link
Member

@deivid-rodriguez deivid-rodriguez left a comment

Choose a reason for hiding this comment

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

@varyonic This refactoring is absolutely fantastic! Just made a couple of comments on naming, but I'm super happy seeing this land into master anyways!


instance_exec &routes
end
def define_routes(config)
Copy link
Member

@deivid-rodriguez deivid-rodriguez Sep 22, 2017

Choose a reason for hiding this comment

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

All of these methods are defining routes, could this method name be more clear?

if config.belongs_to?
define_belongs_to_routes(config)
else
page_or_resource_routes(config)
Copy link
Member

Choose a reason for hiding this comment

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

For consistency, should these methods be named either define_belongs_to_routes & define_page_or_resource_routes, or belongs_to_routes & page_or_resource_routes?

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 agree the method naming is not great, I was focusing on unfolding the code and followed the examples of #3170. Renaming methods retroactively with an interactive rebase can get tricky so I'll look at a final commit to do this.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

On second thoughts reviewing method names just left me wanting to refactor even further. I'ld rather close this technical excision of proc/exec and leave further improvements to a separate PR.

@varyonic varyonic merged commit 084ebef into activeadmin:master Sep 22, 2017
@varyonic
Copy link
Contributor Author

Thanks to @dmitry for showing this could be done.

@varyonic varyonic deleted the refactor-router branch September 22, 2017 19:42
varyonic added a commit to activeadmin-rails/activeadmin-rails that referenced this pull request Oct 8, 2018
@varyonic varyonic mentioned this pull request Oct 8, 2018
@varyonic varyonic added this to the 1.4.0 milestone Oct 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.

3 participants