sauliusgrigaitis / Swifton

A Ruby on Rails inspired Web Framework for Swift that runs on Linux and OS X
MIT License
1.97k stars 70 forks source link

Add MimeType checking in Router #27

Closed califrench closed 8 years ago

califrench commented 8 years ago

This adds support for the mimeType() function on String? types. The previous implementation allowed to pass nil values to the internal MimeType(ext: String?) -> String function but .mimeType() could never be called on a nil String because that was an extension on the String type. This allows us to do this

let testString :String? = nil
testString.mimeType() //  -> "application/octet-stream"

Instead of this

let testString : String? = nil
(testString ?? "").mimeType() // -> "application/octet-stream"

Or worse

let testString : String? = nil
testString.extension?.mimeType ?? "application/octet-stream" // ->"application/octet-stream"

This new implementation is used in the router and fixes #25

sauliusgrigaitis commented 8 years ago

@califrench thanks, but I don't think that it's great idea. We should stick with Optional Chaining.

califrench commented 8 years ago

@sauliusgrigaitis Okay I'll update the code to use optional chaining instead just as in my second example

sauliusgrigaitis commented 8 years ago

@califrench probably we can go with this solution for now. Please make one commit. And add test :)

califrench commented 8 years ago

@sauliusgrigaitis Done! Hopefully the tests pass as I am not able to run them locally

sauliusgrigaitis commented 8 years ago

@califrench please squash into one commit every time :)

califrench commented 8 years ago

Is there a GIT way to merge many commits into one?

Best,

Scott Gauthreaux Developer www.scottgauthreaux.com

On Mar 23, 2016, at 12:42, Saulius Grigaitis notifications@github.com wrote:

@califrench please squash into one commit every time :)

— You are receiving this because you were mentioned. Reply to this email directly or view it on GitHub

califrench commented 8 years ago

The whole PR?

Best,

Scott Gauthreaux Developer www.scottgauthreaux.com

On Mar 23, 2016, at 12:42, Saulius Grigaitis notifications@github.com wrote:

@califrench please squash into one commit every time :)

— You are receiving this because you were mentioned. Reply to this email directly or view it on GitHub

sauliusgrigaitis commented 8 years ago

Yes

sauliusgrigaitis commented 8 years ago

@califrench please check latest code - you now can run tests on OSX!!!!!!!11!!!!!!!!1!!!!111 Please rebase your PR against latest master.

califrench commented 8 years ago

Hi @sauliusgrigaitis thanks for the link and I'll do ASAP. Stoked about the 2.2 release in XCode and our migration over to XCTest