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

issue #584: do not mutate route.path #585

Merged
merged 1 commit into from
Feb 27, 2017
Merged

Conversation

LeFnord
Copy link
Member

@LeFnord LeFnord commented Feb 27, 2017

No description provided.

@LeFnord LeFnord merged commit 26e6d93 into ruby-grape:master Feb 27, 2017
@@ -8,15 +8,15 @@ def can_be_moved?(params, http_verb)
move_methods.include?(http_verb) && includes_body_param?(params)
end

def to_definition(params, route, definitions)
def to_definition(path, params, route, definitions)
Copy link
Contributor

Choose a reason for hiding this comment

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

Wouldn't it be better to append the new param path instead of prepending it? This is a public method so the change could break other code.

specify 'The original route path is not mutated' do
route = Struct.new(:version, :path).new
route.path = '/foo/:dynamic/bar'
subject.build(route, add_version: true)

Choose a reason for hiding this comment

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

I would like to see an expectation here as well to see that the path was modified, but route.path was not.

version = GrapeSwagger::DocMethods::Version.get(route)
version = [version] unless version.is_a?(Array)
Array(
route.path.split('{')[0].split('/').reject(&:empty?).delete_if do |i|
path.split('{')[0].split('/').reject(&:empty?).delete_if do |i|
Copy link

Choose a reason for hiding this comment

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

I know you don't changed that, but please can we extract this split and reject into a separate method which explains, what it did? It's really hard to understand and a good method name would help with that.

Copy link

@ThomasMeisel ThomasMeisel left a comment

Choose a reason for hiding this comment

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

Looks still good to me... :)

version = GrapeSwagger::DocMethods::Version.get(route)
version = [version] unless version.is_a?(Array)
Array(
route.path.split('{')[0].split('/').reject(&:empty?).delete_if do |i|
path.split('{')[0].split('/').reject(&:empty?).delete_if do |i|
Copy link

Choose a reason for hiding this comment

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

This array initialisation is quite complex and worth abstracting away from Application logic.

LeFnord added a commit to LeFnord/grape-swagger that referenced this pull request Feb 9, 2019
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.

7 participants