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 .new and .empty? to HTTP::Params #6241

Merged
merged 1 commit into from Jul 3, 2018

Conversation

icyleaf
Copy link
Contributor

@icyleaf icyleaf commented Jun 22, 2018

Add two new methods to HTTP::Params:

self.new

params = HTTP::Params.new # return same HTTP::Params.parse("") but faster

empty?

Here is no simple way to check if not empty.

params = HTTP::Params.new
params.empty?

@@ -291,6 +296,11 @@ module HTTP
raw_params.delete(name)
end

# Whether the collection contains any params.
def empty?
raw_params.empty?
Copy link
Contributor

@j8r j8r Jun 22, 2018

Choose a reason for hiding this comment

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

You can use delegate empty?, to: @raw_params
Sorry for edits, I confuse myself :|

Copy link
Contributor

Choose a reason for hiding this comment

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

Copy link
Contributor

Choose a reason for hiding this comment

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

In fact #delegate is the right thing, and doesn't change the value.
In the API example, the delegate empty?, capitalize, to: @string changes the string to a capitalized one because a method was specified.

So here, delegate emtpy?, to: @raw_params

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 knew that and i use it much in my project. use this because other methods not use delegate. so...i made a mistake 🤣

icyleaf added a commit to icyleaf/crystal that referenced this pull request Jun 22, 2018
@j8r
Copy link
Contributor

j8r commented Jun 22, 2018

forward_missing_to @raw_params fits also, but therefore are tests really needed? There are already some for String.

@icyleaf
Copy link
Contributor Author

icyleaf commented Jun 22, 2018

I rebase the commit, i think it is better use delegate with empty?.

@bcardiff
Copy link
Member

CI says

Error: formatting './src/http/params.cr' produced changes

@icyleaf
Copy link
Contributor Author

icyleaf commented Jun 23, 2018

@bcardiff i found format check error in comments, is that must be formatted?

@asterite
Copy link
Member

Yes, the formatter also formats code in comments.

@@ -76,6 +76,11 @@ module HTTP
end
end

# Returns the empty `HTTP::Params`.
def self.new
Params.new({} of String => Array(String))
Copy link
Contributor

Choose a reason for hiding this comment

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

Why not simply add a default to def initialize, then document that?

Doc should be

Returns an empty HTTP::Params.

@icyleaf
Copy link
Contributor Author

icyleaf commented Jul 3, 2018

@RX14 Code update, please review again, thanks.

@RX14 RX14 added this to the Next milestone Jul 3, 2018
@RX14 RX14 merged commit 75b46ac into crystal-lang:master Jul 3, 2018
@icyleaf icyleaf deleted the feature-http-params branch July 4, 2018 01:31
@RX14 RX14 modified the milestones: Next, 0.26.0 Jul 30, 2018
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

6 participants