Skip to content
This repository has been archived by the owner on Jul 12, 2024. It is now read-only.

Commit

Permalink
Allowing user defined Email class to be used.
Browse files Browse the repository at this point in the history
  • Loading branch information
diego-aslz committed Oct 31, 2016
1 parent 8be1bb6 commit 6fba3a5
Show file tree
Hide file tree
Showing 4 changed files with 25 additions and 3 deletions.
2 changes: 2 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,7 @@ Defaults are shown below with sample overrides following. In
```ruby
Griddler.configure do |config|
config.processor_class = EmailProcessor # CommentViaEmail
config.email_class = Griddler::Email # MyEmail
config.processor_method = :process # :create_comment (A method on CommentViaEmail)
config.reply_delimiter = '-- REPLY ABOVE THIS LINE --'
config.email_service = :sendgrid # :cloudmailin, :postmark, :mandrill, :mailgun
Expand All @@ -62,6 +63,7 @@ end
| Option | Meaning
| ------ | -------
| `processor_class` | The class Griddler will use to handle your incoming emails.
| `email_class` | The class Griddler will use to represent an incoming e-mail. It must support an initializer that receives a hash as the only argument. We recommend inheriting it from Griddler::Email or checking this class to see all the methods it responds to.
| `processor_method` | The method Griddler will call on the processor class when handling your incoming emails.
| `reply_delimiter` | The string searched for that will split your body.
| `email_service` | Tells Griddler which email service you are using. The supported email service options are `:sendgrid` (the default), `:cloudmailin` (expects multipart format), `:postmark`, `:mandrill` and `:mailgun`. You will also need to have an appropriate [adapter] gem included in your Gemfile.
Expand Down
6 changes: 3 additions & 3 deletions app/controllers/griddler/emails_controller.rb
Original file line number Diff line number Diff line change
@@ -1,17 +1,17 @@
class Griddler::EmailsController < ActionController::Base
def create
normalized_params.each do |p|
process_email Griddler::Email.new(p)
process_email email_class.new(p)
end

head :ok
end

private

delegate :processor_class, :processor_method, :email_service, to: :griddler_configuration
delegate :processor_class, :email_class, :processor_method, :email_service, to: :griddler_configuration

private :processor_class, :processor_method, :email_service
private :processor_class, :email_class, :processor_method, :email_service

def normalized_params
Array.wrap(email_service.normalize_params(params))
Expand Down
8 changes: 8 additions & 0 deletions lib/griddler/configuration.rb
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,14 @@ def processor_class=(klass)
@processor_class = klass.to_s
end

def email_class
@email_class ||= Griddler::Email
end

def email_class=(klass)
@email_class = klass
end

def processor_method
@processor_method ||= :process
end
Expand Down
12 changes: 12 additions & 0 deletions spec/griddler/configuration_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@

it 'provides defaults' do
expect(Griddler.configuration.processor_class).to eq(EmailProcessor)
expect(Griddler.configuration.email_class).to eq(Griddler::Email)
expect(Griddler.configuration.reply_delimiter).to eq('-- REPLY ABOVE THIS LINE --')
expect(Griddler.configuration.email_service).to eq(:test_adapter)
expect(Griddler.configuration.processor_method).to eq(:process)
Expand Down Expand Up @@ -44,6 +45,17 @@ class DummyProcessor
expect(Griddler.configuration.processor_class).to eq DummyProcessor
end

it 'stores an email_class' do
class DummyEmail
end

Griddler.configure do |config|
config.email_class = DummyEmail
end

expect(Griddler.configuration.email_class).to eq DummyEmail
end

it 'stores a processor_method' do
Griddler.configure do |config|
config.processor_method = :perform
Expand Down

0 comments on commit 6fba3a5

Please sign in to comment.