Skip to content

Commit

Permalink
General cleanup (#41)
Browse files Browse the repository at this point in the history
* move the test script to script folder to match other lucky projects

* no longer using travis

* removed an extra space from the shard.yml

* Adding in ameba to the CI. Also working out a way we can run the integration specs when needed, but turned off by default to match current setup

* Fixing a few things in README plus adding another adapter I found. Also documented the delayed strategy stuff

* The integration specs should not run
  • Loading branch information
jwoertink committed Nov 17, 2020
1 parent 76c0e1a commit fe797c9
Show file tree
Hide file tree
Showing 5 changed files with 46 additions and 18 deletions.
12 changes: 10 additions & 2 deletions .github/workflows/ci.yml
@@ -1,4 +1,4 @@
name: Lucky Flow CI
name: Lucky Carbon CI

on:
push:
Expand All @@ -13,8 +13,12 @@ jobs:
image: crystallang/crystal:0.35.0
steps:
- uses: actions/checkout@v1
- name: Install shards
run: shards install
- name: Format
run: crystal tool format --check
- name: Lint
run: ./bin/ameba
specs:
runs-on: ubuntu-latest
container:
Expand All @@ -30,5 +34,9 @@ jobs:
key: ${{ runner.os }}-crystal
- name: Create .env file
run: touch .env
- name: Run tests
- if: env.RUN_INTEGRATION_SPECS == true
name: Run tests with integration
run: crystal spec
- if: env.RUN_INTEGRATION_SPECS != true
name: Run tests without integration
run: crystal spec -D skip-integration
10 changes: 0 additions & 10 deletions .travis.yml

This file was deleted.

41 changes: 36 additions & 5 deletions README.md
Expand Up @@ -21,6 +21,7 @@ dependencies:
- `Carbon::SendGridAdapter`- Ships with Carbon.
- `Carbon::AwsSesAdapter` - See [keizo3/carbon_aws_ses_adapter](https://github.com/keizo3/carbon_aws_ses_adapter).
- `Carbon::SendInBlueAdapter` - See [atnos/carbon_send_in_blue_adapter](https://github.com/atnos/carbon_send_in_blue_adapter).
- `Carbon::SmtpAdapter` - See [oneiros/carbon_smtp_adapter](https://github.com/oneiros/carbon_smtp_adapter).

## Usage

Expand All @@ -41,7 +42,7 @@ end
### Configure the mailer class

```crystal
BaseEmail.configure do
BaseEmail.configure do |settings|
settings.adapter = Carbon::SendGridAdapter.new(api_key: "SEND_GRID_API_KEY")
end
```
Expand Down Expand Up @@ -96,6 +97,36 @@ WelcomeEmail.new("Kate", "kate@example.com").deliver
WelcomeEmail.new("Kate", "kate@example.com").deliver_later
```

### Delay email delivery

The built-in delay uses the `deliver_later_strategy` setting set to `Carbon::SpawnStrategy`. You can create your own custom delayed strategy
that inherits from `Carbon::DeliverLaterStrategy` and defines a `run` method that takes a `Carbon::Email` and a block.

One example might be a job processor:

```crystal
# Define your new delayed strategy
class SendEmailInJobStrategy < Carbon::DeliverLaterStrategy
# `block.call` will run `deliver`, but you can call
# `deliver` yourself on the `email` when you need.
def run(email : Carbon::Email, &block)
EmailJob.perform_later(email)
end
end
class EmailJob < JobProcessor
def perform(email : Carbon::Email)
email.deliver
end
end
# configure to use your new delayed strategy
BaseEmail.configure do |settings|
settings.deliver_later_strategy = SendEmailInJobStrategy.new
end
```

## Testing

### Change the adapter
Expand Down Expand Up @@ -177,16 +208,16 @@ end
SEND_GRID_API_KEY=get_from_send_grid
```

> Note: When you open a PR, Travis CI will run the test suite and try sending
> a sandboxed email through SendGrid. Feel free to open a PR to run integration
> tests if you don't want to get an API key from SendGrid.
> Note: When you open a PR, Github Actions will not run the integration suite.
> If you need the integeration suite to run, the `RUN_INTEGRATION_SPECS` env var must
> be set to `true`.
## Contributing

1. Fork it ( https://github.com/luckyframework/carbon/fork )
2. Create your feature branch (git checkout -b my-new-feature)
3. Make your changes
4. Run `./bin/test` to run the specs, build shards, and check formatting
4. Run `./script/test` to run the specs, build shards, and check formatting
5. Commit your changes (git commit -am 'Add some feature')
6. Push to the branch (git push origin my-new-feature)
7. Create a new Pull Request
Expand Down
File renamed without changes.
1 change: 0 additions & 1 deletion shard.yml
Expand Up @@ -21,4 +21,3 @@ development_dependencies:
ameba:
github: veelenga/ameba
version: 0.13.1

0 comments on commit fe797c9

Please sign in to comment.