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 type specs for address functions #164

Merged
merged 1 commit into from
May 24, 2016
Merged

Add type specs for address functions #164

merged 1 commit into from
May 24, 2016

Conversation

drapergeek
Copy link
Contributor

I recently ran into an issue where I was trying to figure out why a comma separated string wasn't working for the to and I needed to see what type was supported when calling the to function. I think by adding these it makes it easier for users to see what options are passed but also it means that users could perform static analysis to make sure they're calling it correctly.

@@ -68,11 +68,12 @@ defmodule Bamboo.Email do
"""

@type address :: String.t | {String.t, String.t}
@type address_list :: nil | address | [address]
Copy link
Contributor

Choose a reason for hiding this comment

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

or any because it can be anything that implements Bamboo.Formatter protocol

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Can you explain that more?

I don't like any if it can be avoided. That doesn't allow type checking anymore.

Copy link
Contributor

Choose a reason for hiding this comment

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

You can implement the Bamboo.Formatter protocol for anything. Maps, structs, atoms, boo leans, anything that protocols allow you to implement. So any value you want could be formatted. We could say that it accepts a map or list of maps, but that wouldn't really be technically correct :S

I suppose we could just say that anything other than a map/struct would be weird to format with a protocol and just add a type for that but I'm not totally sure about that.

Or maybe there a way to add a type for anything that implements a protocol? That would work best if possible.

Sent from my iPhone

On May 24, 2016, at 8:52 AM, Jason Draper notifications@github.com wrote:

In lib/bamboo/email.ex:

@@ -68,11 +68,12 @@ defmodule Bamboo.Email do
"""

@type address :: String.t | {String.t, String.t}

  • @type address_list :: nil | address | [address]
    Can you explain that more?

I don't like any if it can be avoided. That doesn't allow type checking anymore.


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

@paulcsmith
Copy link
Contributor

This is a great idea! Just left a couple comments :)

@drapergeek
Copy link
Contributor Author

@paulcsmith updated!


```
new_email
|> #{function_name}(["sally@example.com", "james@example.com"])
Copy link
Contributor

Choose a reason for hiding this comment

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

We've been indenting by 4 spaces instead of using ```. I think after that's changes this can be merged in :D

Copy link
Contributor

Choose a reason for hiding this comment

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

Also, what do you think of linking to the docs in Bamboo.Formatter? Something like

You can pass in a string, list of string, or anything that implements the `Bamboo.Formatter` protocol. See `Bamboo.Formatter` for more examples.

That might help people figure out what they can use for recipients. What do you think?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

We've been indenting by 4 spaces instead of using ```. I think after that's changes this can be merged in :D

Uh...you sure about that? https://github.com/thoughtbot/bamboo/blob/master/lib/bamboo/email.ex#L21-L34

https://github.com/thoughtbot/bamboo/blob/master/lib/bamboo/email.ex#L42-L67

Copy link
Contributor

Copy link
Contributor

Choose a reason for hiding this comment

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

Added a PR to change those examples: #165

Adding these makes it easier for users to see what options can be passed into
each of these functions.
@paulcsmith
Copy link
Contributor

LGTM! This will make it a lot easier for people to figure out what can be done with recipients. Thank you very much!

@drapergeek drapergeek merged commit 2e9f17f into master May 24, 2016
@drapergeek drapergeek deleted the jd-email-docs branch May 24, 2016 15:47
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.

2 participants