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 types and specs #150

Merged
merged 7 commits into from
May 15, 2016
Merged

Conversation

cloud8421
Copy link
Contributor

Hello, I've added some initial types and specs (excluding the Plug/Phoenix side of things).

Incidentally, I've been using the library for a few weeks now (just a to generate a daily digest to myself) and it works very nicely, I'm really happy about it! Nice job.

@@ -58,6 +58,8 @@ defprotocol Bamboo.Formatter do
`:from`, `:to`, `:cc` or `:bcc`. You can pattern match on this to customize
the address.
"""
@type opts :: %{type: :from | :to | :cc | :bcc}
Copy link
Contributor

Choose a reason for hiding this comment

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

a newline after this, maybe, for readability?

Copy link
Contributor

Choose a reason for hiding this comment

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

Yes I think this would make it read a bit better

@princemaple
Copy link
Contributor

@paulcsmith have you missed this goodie?

@princemaple
Copy link
Contributor

@cloud8421 out of curiosity, how did you generate your daily digest? did you use any task queue / cron?

@paulcsmith
Copy link
Contributor

Did not miss it, just been busy in client work :D

Thanks so much for this @cloud8421. I'm glad you're liking it so far! I'll have more time to review this later on in the week :)

@princemaple FWIW, we do a daily digest and use Heroku Scheduler with a mix task and it works wonderfully, but you need to be on Heroku. Not sure if that helps, but hopefully it does!

@princemaple
Copy link
Contributor

@paulcsmith thanks for the information :)
I've been searching for a elixir/erlang solution. Reason being it would be much easier to deploy as docker images, as I wouldn't have to touch any lower-level system tools, e.g. cron, or break basic principles like one process/command per container. I also have this requirement that the solution needs to be able to run as the unique process across an Elixir / Phoenix cluster, so the jobs created by it wouldn't repeat. Since I haven't found one, I've started looking into :global and writing one of my own...

@paulcsmith
Copy link
Contributor

With those requirements you Kay be interested in using a package called Quantum

It's basically cron, but pure elixir. We have used it on a client project and it is working well so far. You can even set schedules with human readable language which is nice, e.g. "@hourly"

On phone so don't have a link but it's on hex :)

On May 4, 2016, at 8:23 AM, Po Chen notifications@github.com wrote:

@paulcsmith thanks for the information :)
I've been searching for a elixir/erlang solution. Reason being it would be much easier to deploy as docker images, as I wouldn't have to touch any lower-level system tools, e.g. cron, or break basic principles like one process/command per container. I also have this requirement that the solution needs to be able to run as the unique process across an Elixir / Phoenix cluster, so the jobs created by it wouldn't repeat. Since I haven't found one, I've started looking into :global and writing one of my own...


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

@princemaple
Copy link
Contributor

Thanks, that one is interesting.

@cloud8421
Copy link
Contributor Author

@paulcsmith: sounds great!

@princemaple:

The project I’m working on is a system that gathers information in the background and reacts to certain events.

  • a clock process ticks every second
  • a scheduler consumer/producer processes every tick, generating minute, hour and day events
  • a notification consumer listens to all “hour” events, discarding all except 7am, where it fires the email (this is done via simply pattern matching on the events coming in)

Both consumer and producers are GenServer processes that bind themselves to a Phoenix.PubSub instance.

Everything runs in the same application. Hope it's clear!

@princemaple
Copy link
Contributor

@cloud8421 yep, that's clear enough :) thank you!

@type t :: %__MODULE__{
to: nil | address | [address],
cc: nil | address | [address],
bcc: 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.

I think this should be nil | any because the email address can technically be whatever you want as long as it defines the 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.

Of course, that's true.

@paulcsmith
Copy link
Contributor

A few comments and then this will be ready to merge. Thanks @cloud8421

@cloud8421
Copy link
Contributor Author

@paulcsmith will make the changes and push. Is there a policy around squashing/rebasing?

@paulcsmith
Copy link
Contributor

@cloud8421 I typically squash the commits before merging, but I can't easily rebase it from the web. So if you can rebase I can manage squashing/merging. Does that work for you?

@paulcsmith
Copy link
Contributor

@cloud8421 Just checking in to see if you need any help with this :)

@cloud8421
Copy link
Contributor Author

Yes I think I'll be able to make those changes later today

Claudio


Sent from iPhone

On 12 May 2016, at 23:10, Paul Smith notifications@github.com wrote:

@cloud8421 Just checking in to see if you need any help with this :)


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

- All address types can be `any`, as they depend on the
`Bamboo.Formatter` protocol
- `Email.put_private/3` can accept `any` as a value
Methods are generated by a macro, however their specs are different.
@cloud8421
Copy link
Contributor Author

@paulcsmith rebased, made needed changes and left a question :)

@paulcsmith
Copy link
Contributor

This looks great. Thanks @cloud8421!

@paulcsmith paulcsmith merged commit 34bc93a into beam-community:master May 15, 2016
@cloud8421 cloud8421 deleted the add-types-and-specs branch May 15, 2016 09:34
germsvel added a commit that referenced this pull request Dec 23, 2020
What changed?
============

In #386, evuez pointed out that
the `Bamboo.Email.address()` typespec shows `String.t() | {String.t(),
String.t()}`. But no adapter actually supports the `String.t()` type.

Given that the code was introduced [before the
typespecs](#150) (and thus we
can treat the code as the source of truth when in doubt), and since
`Bamboo.Email.get_address/1`'s explicit intent is to abstract the
internal representation of email addresses in case Bamboo changes how it
stores them:

> Gets just the email address from a normalized email address.
> Normalized email addresses are 2 item tuples {name, address}. This
gets the address part of the tuple. Use this instead of calling
elem(address, 1) so that if Bamboo changes how email addresses are
represented your code will still work

I think the correct change here is to remove the `String.t()` portion of
the typespec rather than update the code to handle that typespec. In
other words, I think we made a typo when introducing the typespec. So
this PR would be merged instead of #386.
germsvel added a commit that referenced this pull request Dec 24, 2020
What changed?
============

In #386, evuez pointed out that
the `Bamboo.Email.address()` typespec shows `String.t() | {String.t(),
String.t()}`. But no adapter actually supports the `String.t()` type.

Given that the code was introduced [before the
typespecs](#150) (and thus we
can treat the code as the source of truth when in doubt), and since
`Bamboo.Email.get_address/1`'s explicit intent is to abstract the
internal representation of email addresses in case Bamboo changes how it
stores them:

> Gets just the email address from a normalized email address.
> Normalized email addresses are 2 item tuples {name, address}. This
gets the address part of the tuple. Use this instead of calling
elem(address, 1) so that if Bamboo changes how email addresses are
represented your code will still work

I think the correct change here is to remove the `String.t()` portion of
the typespec rather than update the code to handle that typespec. In
other words, I think we made a typo when introducing the typespec. So
this PR would be merged instead of #386.
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