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

[WIP] Add nested get query parameter expandation #84

Closed
wants to merge 3 commits into from
Closed

[WIP] Add nested get query parameter expandation #84

wants to merge 3 commits into from

Conversation

iguchi1124
Copy link
Contributor

@iguchi1124 iguchi1124 commented Feb 23, 2018

I'm creating this issue #61 examples in this pull request!
What do you think about this approach?

pattern = Mustermann.new("/books/:id")
pattern.expand(:append, id: 5, include: ["foo"]) # => "/books/5?include[]=foo"
pattern.expand(:append, id: 5, foo: {bar: :baz}) # => "/books/5?foo[bar]=baz"
pattern.expand(:append, id: 5, foo: {bar: [1, 2]}) # => "/books/5?foo[bar][]=1&foo[bar][]=2"

@@ -14,4 +14,6 @@ Gem::Specification.new do |s|
s.files = `git ls-files`.split("\n")
s.test_files = `git ls-files -- {test,spec,features}/*`.split("\n")
s.executables = `git ls-files -- bin/*`.split("\n").map{ |f| File.basename(f) }

s.add_dependency 'query_string_builder'
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 can remove this dependency, it is my sample code

@namusyaka namusyaka self-requested a review February 23, 2018 20:28
Copy link
Member

@namusyaka namusyaka left a comment

Choose a reason for hiding this comment

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

First of all, please leave it dependent on your personal gem.
And this change doesn't seem to reach the essential part.
Could you elaborate?

@iguchi1124
Copy link
Contributor Author

inlin-ized and fixup this commit 1e5a12d

Copy link
Member

@namusyaka namusyaka left a comment

Choose a reason for hiding this comment

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

Did you read the source code?
Did you dig into the problem to understand the essence?
Your patch breaks expanding features.
By executing the following code, you can check the differences before and after applying your changes.

require 'mustermann'

pattern = Mustermann.new("/books/:id")
p pattern.expand(:append, id: "foo", bar: "&#?")

@@ -194,8 +194,7 @@ def slice(hash, keys)

def append(uri, values)
return uri unless values and values.any?
entries = values.map { |pair| pair.map { |e| @api_expander.escape(e, also_escape: /[\/\?#\&\=%]/) }.join(?=) }
"#{ uri }#{ uri[??]??&:?? }#{ entries.join(?&) }"
[uri, QueryStringBuilder.new(values).build].join('?')
Copy link
Member

Choose a reason for hiding this comment

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

I don't think QueryStringBuilder is necessary. Recursive processing looks fine, but QueryStringBuilder is really overkill.

@@ -194,8 +194,7 @@ def slice(hash, keys)

def append(uri, values)
return uri unless values and values.any?
entries = values.map { |pair| pair.map { |e| @api_expander.escape(e, also_escape: /[\/\?#\&\=%]/) }.join(?=) }
"#{ uri }#{ uri[??]??&:?? }#{ entries.join(?&) }"
Copy link
Member

Choose a reason for hiding this comment

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

Why did you delete these lines? Your patch doesn't cover these feature.

Copy link
Contributor Author

@iguchi1124 iguchi1124 Apr 29, 2018

Choose a reason for hiding this comment

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

Fixed 2addf75

@@ -70,6 +70,9 @@
subject(:expander) { Mustermann::Expander.new('/:a', additional_values: :append) }
example { expander.expand(a: ?a).should be == '/a' }
example { expander.expand(a: ?a, b: ?b).should be == '/a?b=b' }
example { expander.expand(a: ?a, b: [?b]).should be == '/a?b[]=b' }
example { expander.expand(a: ?a, b: {c: ?c}).should be == '/a?b[c]=c' }
example { expander.expand(a: ?a, b: {c: [1, 2]}).should be == '/a?b[c][]=1&b[c][]=2' }
Copy link
Member

Choose a reason for hiding this comment

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

The original test doesn't mention escape, but you need to add about it at least to add this change.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Fixed f17ecc3

@iguchi1124 iguchi1124 changed the title Add nested get query parameter expandation [WIP] Add nested get query parameter expandation Feb 26, 2018
@iguchi1124
Copy link
Contributor Author

iguchi1124 commented Feb 26, 2018

Thank you for reviews 😁I'll update this pull request soon.

@namusyaka
Copy link
Member

@iguchi1124 If you're going to include this fix in the 1.0.3 release, please write to that effect in the milestone issue.

@iguchi1124 iguchi1124 changed the title [WIP] Add nested get query parameter expandation Add nested get query parameter expandation Apr 29, 2018
@iguchi1124 iguchi1124 changed the title Add nested get query parameter expandation [WIP] Add nested get query parameter expandation Apr 30, 2018
@@ -2,6 +2,7 @@
require 'mustermann/ast/expander'
require 'mustermann/caster'
require 'mustermann'
require 'addressable/uri'
Copy link
Member

Choose a reason for hiding this comment

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

What is this?
I would not like to use the addressable gem. Mustermann has not been depended on external gems.
Is there a clear reason to add this gem?
If so, why do not you add this to gemspec.

@namusyaka
Copy link
Member

@iguchi1124 Hey, I'm going to release new version next week. So if you'd like to include this fix at the next version, please ping me.

@jkowens jkowens closed this Jul 17, 2022
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