active_delivery 0.3.0 → 0.4.3

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: b0f3637c02e517255d0d91c59b1dd3abf61f6ffd1aaf34f28723a3be0e3209cf
4
- data.tar.gz: 48bd825dab16b2937d6275ff21ec04868a5a97bd3b98cfcc9a297bfc6c064d76
3
+ metadata.gz: 5798b0d549774cc32295198d1f1ebcd155c07e0624ff8260b427d437cd0ac465
4
+ data.tar.gz: '086acc7c7080f9170663353740d462acbd065d4eb105a23193aa9150bdb84327'
5
5
  SHA512:
6
- metadata.gz: 5284e71b7e9e84747f71bf78476536c50e16e912959fd0c2f97c9a533f86e4a589c47766f09890324459003b36113f677461c8a1e406c58e1b4263c2fcf71f21
7
- data.tar.gz: 4d14d2914d4beec54d73cf9c08a4342b6775ee4941530394cd827d09ae4f7dfbd5f28c659e4c76be2dc193697e4d6ea3d86ca6956c2d7dfc241103b5558ff0fe
6
+ metadata.gz: b74b9673fd219caec608b4a20cfc0cd94eb55df0b4a52b95edd799d5aea9552e0913c9861d06412494cd160fa7fd6f77c27bae603e60659bf58ad5adda9b71f0
7
+ data.tar.gz: 3a0e73e048db14768401cc0f1406ad0aaa09888ef2c18c739d15b2daaf0199375eee437b229e60b8aab7af38659d2bd815a7cd8402620618def7498a6d1373ac
@@ -0,0 +1,3 @@
1
+ bump:
2
+ file: lib/active_delivery/version.rb
3
+ skip_ci: true
@@ -0,0 +1,24 @@
1
+ ---
2
+ name: Bug report
3
+ about: Create a report to help us improve
4
+ title: ''
5
+ labels: ''
6
+ assignees: palkan
7
+
8
+ ---
9
+
10
+ ## What did you do?
11
+
12
+ ## What did you expect to happen?
13
+
14
+ ## What actually happened?
15
+
16
+ ## Additional context
17
+
18
+ ## Environment
19
+
20
+ **Ruby Version:**
21
+
22
+ **Framework Version (Rails, whatever):**
23
+
24
+ **Active Delivery Version:**
@@ -0,0 +1,24 @@
1
+ ---
2
+ name: Feature request
3
+ about: Suggest an idea for this project
4
+ title: ''
5
+ labels: enhancement
6
+ assignees: palkan
7
+
8
+ ---
9
+
10
+ ## Is your feature request related to a problem? Please describe.
11
+
12
+ A clear and concise description of what the problem is. Ex. I'm always frustrated when [...]
13
+
14
+ ## Describe the solution you'd like
15
+
16
+ A clear and concise description of what you want to happen.
17
+
18
+ ## Describe alternatives you've considered
19
+
20
+ A clear and concise description of any alternative solutions or features you've considered.
21
+
22
+ ## Additional context
23
+
24
+ Add any other context or screenshots about the feature request here.
@@ -0,0 +1,23 @@
1
+ <!--
2
+ First of all, thanks for contributing!
3
+
4
+ If it's a typo fix or minor documentation update feel free to skip the rest of this template!
5
+ -->
6
+
7
+ ## What is the purpose of this pull request?
8
+
9
+ <!--
10
+ If it's a bug fix, then link it to the issue, for example:
11
+
12
+ Fixes #xxx
13
+ -->
14
+
15
+ ## What changes did you make? (overview)
16
+
17
+ ## Is there anything you'd like reviewers to focus on?
18
+
19
+ ## Checklist
20
+
21
+ - [ ] I've added tests for this change
22
+ - [ ] I've added a Changelog entry
23
+ - [ ] I've updated a documentation
@@ -0,0 +1,72 @@
1
+ name: Lint Docs
2
+
3
+ on:
4
+ push:
5
+ branches:
6
+ - master
7
+ paths:
8
+ - "*.md"
9
+ - "**/*.md"
10
+ pull_request:
11
+ paths:
12
+ - "*.md"
13
+ - "**/*.md"
14
+
15
+ jobs:
16
+ markdownlint:
17
+ runs-on: ubuntu-latest
18
+ steps:
19
+ - uses: actions/checkout@v2
20
+ - uses: ruby/setup-ruby@v1
21
+ with:
22
+ ruby-version: 2.7
23
+ - name: Run Markdown linter
24
+ run: |
25
+ gem install mdl
26
+ mdl *.md
27
+ rubocop:
28
+ runs-on: ubuntu-latest
29
+ steps:
30
+ - uses: actions/checkout@v2
31
+ - uses: ruby/setup-ruby@v1
32
+ with:
33
+ ruby-version: 2.7
34
+ - name: Lint Markdown files with RuboCop
35
+ run: |
36
+ gem install bundler
37
+ bundle install --gemfile gemfiles/rubocop.gemfile --jobs 4 --retry 3
38
+ bundle exec --gemfile gemfiles/rubocop.gemfile rubocop -c .rubocop-md.yml
39
+ forspell:
40
+ runs-on: ubuntu-latest
41
+ steps:
42
+ - uses: actions/checkout@v2
43
+ - name: Install Hunspell
44
+ run: |
45
+ sudo apt-get install hunspell
46
+ - uses: ruby/setup-ruby@v1
47
+ with:
48
+ ruby-version: 2.7
49
+ - name: Cache installed gems
50
+ uses: actions/cache@v1
51
+ with:
52
+ path: /home/runner/.rubies/ruby-2.7.0/lib/ruby/gems/2.7.0
53
+ key: gems-cache-${{ runner.os }}
54
+ - name: Install Forspell
55
+ run: gem install forspell
56
+ - name: Run Forspell
57
+ run: forspell *.md .github/**/*.md
58
+ liche:
59
+ runs-on: ubuntu-latest
60
+ env:
61
+ GO111MODULE: on
62
+ steps:
63
+ - uses: actions/checkout@v2
64
+ - name: Set up Go
65
+ uses: actions/setup-go@v1
66
+ with:
67
+ go-version: 1.13.x
68
+ - name: Run liche
69
+ run: |
70
+ export PATH=$PATH:$(go env GOPATH)/bin
71
+ go get -u github.com/raviqqe/liche
72
+ liche README.md CHANGELOG.md
@@ -0,0 +1,35 @@
1
+ name: JRuby Build
2
+
3
+ on:
4
+ push:
5
+ branches:
6
+ - master
7
+ pull_request:
8
+
9
+ jobs:
10
+ rspec:
11
+ runs-on: ubuntu-latest
12
+ env:
13
+ BUNDLE_JOBS: 4
14
+ BUNDLE_RETRY: 3
15
+ CI: true
16
+ steps:
17
+ - uses: actions/checkout@v2
18
+ - uses: actions/cache@v1
19
+ with:
20
+ path: /home/runner/bundle
21
+ key: bundle-${{ hashFiles('**/gemfiles/jruby.gemfile') }}-${{ hashFiles('**/*.gemspec') }}
22
+ restore-keys: |
23
+ bundle-
24
+ - uses: ruby/setup-ruby@v1
25
+ with:
26
+ ruby-version: jruby
27
+ - name: Bundle install
28
+ run: |
29
+ bundle config --global gemfile gemfiles/jruby.gemfile
30
+ bundle config path /home/runner/bundle
31
+ bundle install
32
+ bundle update
33
+ - name: Run RSpec
34
+ run: |
35
+ bundle exec rspec
@@ -0,0 +1,51 @@
1
+ name: Build
2
+
3
+ on:
4
+ push:
5
+ branches:
6
+ - master
7
+ pull_request:
8
+
9
+ jobs:
10
+ rspec:
11
+ runs-on: ubuntu-latest
12
+ env:
13
+ BUNDLE_JOBS: 4
14
+ BUNDLE_RETRY: 3
15
+ CI: true
16
+ strategy:
17
+ fail-fast: false
18
+ matrix:
19
+ ruby: ["2.7"]
20
+ gemfile: [
21
+ "gemfiles/rails6.gemfile"
22
+ ]
23
+ include:
24
+ - ruby: "2.5"
25
+ gemfile: "gemfiles/rails42.gemfile"
26
+ - ruby: "2.6"
27
+ gemfile: "gemfiles/rails50.gemfile"
28
+ - ruby: "2.6"
29
+ gemfile: "gemfiles/rails5.gemfile"
30
+ - ruby: "2.7"
31
+ gemfile: "gemfiles/railsmaster.gemfile"
32
+ steps:
33
+ - uses: actions/checkout@v2
34
+ - uses: actions/cache@v1
35
+ with:
36
+ path: /home/runner/bundle
37
+ key: bundle-${{ matrix.ruby }}-${{ matrix.gemfile }}-${{ hashFiles(matrix.gemfile) }}-${{ hashFiles('**/*.gemspec') }}
38
+ restore-keys: |
39
+ bundle-${{ matrix.ruby }}-${{ matrix.gemfile }}-
40
+ - uses: ruby/setup-ruby@v1
41
+ with:
42
+ ruby-version: ${{ matrix.ruby }}
43
+ - name: Bundle install
44
+ run: |
45
+ bundle config path /home/runner/bundle
46
+ bundle config --global gemfile ${{ matrix.gemfile }}
47
+ bundle install
48
+ bundle update
49
+ - name: Run RSpec
50
+ run: |
51
+ bundle exec rspec
@@ -0,0 +1,21 @@
1
+ name: Lint Ruby
2
+
3
+ on:
4
+ push:
5
+ branches:
6
+ - master
7
+ pull_request:
8
+
9
+ jobs:
10
+ rubocop:
11
+ runs-on: ubuntu-latest
12
+ steps:
13
+ - uses: actions/checkout@v2
14
+ - uses: ruby/setup-ruby@v1
15
+ with:
16
+ ruby-version: 2.7
17
+ - name: Lint Ruby code with RuboCop
18
+ run: |
19
+ gem install bundler
20
+ bundle install --gemfile gemfiles/rubocop.gemfile --jobs 4 --retry 3
21
+ bundle exec --gemfile gemfiles/rubocop.gemfile rubocop
data/.gitignore CHANGED
@@ -1,10 +1,43 @@
1
- /.bundle/
2
- /.yardoc
3
- /_yardoc/
4
- /coverage/
5
- /doc/
6
- /pkg/
7
- /spec/reports/
8
- /tmp/
1
+ # Numerous always-ignore extensions
2
+ *.diff
3
+ *.err
4
+ *.orig
5
+ *.log
6
+ *.rej
7
+ *.swo
8
+ *.swp
9
+ *.vi
10
+ *~
11
+ *.sass-cache
12
+ *.iml
13
+ .idea/
14
+
15
+ # Sublime
16
+ *.sublime-project
17
+ *.sublime-workspace
18
+
19
+ # OS or Editor folders
20
+ .DS_Store
21
+ .cache
22
+ .project
23
+ .settings
24
+ .tmproj
25
+ Thumbs.db
26
+
27
+ .bundle/
28
+ log/*.log
29
+ pkg/
30
+ spec/dummy/db/*.sqlite3
31
+ spec/dummy/db/*.sqlite3-journal
32
+ spec/dummy/tmp/
33
+
9
34
  Gemfile.lock
10
35
  Gemfile.local
36
+ .rspec
37
+ .ruby-version
38
+ *.gem
39
+
40
+ tmp/
41
+ .rbnext/
42
+
43
+ gemfiles/*.lock
data/.mdlrc ADDED
@@ -0,0 +1 @@
1
+ rules "~MD013", "~MD033", "~MD034", "~MD029", "~MD026", "~MD002"
data/.rspec CHANGED
@@ -1,2 +1,2 @@
1
- --format documentation
1
+ -f d
2
2
  --color
@@ -0,0 +1,16 @@
1
+ inherit_from: ".rubocop.yml"
2
+
3
+ require:
4
+ - rubocop-md
5
+
6
+ AllCops:
7
+ Include:
8
+ - '**/*.md'
9
+
10
+ Lint/Void:
11
+ Exclude:
12
+ - '**/*.md'
13
+
14
+ Lint/DuplicateMethods:
15
+ Exclude:
16
+ - '**/*.md'
@@ -13,7 +13,7 @@ AllCops:
13
13
  - 'vendor/**/*'
14
14
  - 'gemfiles/**/*'
15
15
  DisplayCopNames: true
16
- TargetRubyVersion: 2.4
16
+ TargetRubyVersion: 2.5
17
17
 
18
18
  Standard/SemanticBlocks:
19
19
  Enabled: false
@@ -26,6 +26,3 @@ Style/TrailingCommaInArrayLiteral:
26
26
 
27
27
  Style/TrailingCommaInHashLiteral:
28
28
  EnforcedStyleForMultiline: no_comma
29
-
30
- Layout/AlignParameters:
31
- EnforcedStyle: with_first_parameter
@@ -2,11 +2,35 @@
2
2
 
3
3
  ## master
4
4
 
5
+ ## 0.4.3 (2020-08-21)
6
+
7
+ - Fix parameterized mailers support in Rails >= 5.0, <5.2 ([@dmitryzuev][])
8
+
9
+ ## 0.4.2 (2020-04-28)
10
+
11
+ - Allow resolve mailer class with custom pattern ([@brovikov][])
12
+
13
+ ## 0.4.1 (2020-04-22)
14
+
15
+ - Fixed TestDelivery fiber support. ([@pauldub](https://github.com/pauldub))
16
+
17
+ ## 0.4.0 (2020-03-02)
18
+
19
+ - **Drop Ruby 2.4 support**. ([@palkan][])
20
+
21
+ - Allow passing keyword arguments to `notify`. ([@palkan][])
22
+
23
+ ## 0.3.1 (2020-02-21)
24
+
25
+ - Fixed RSpec detection. ([@palkan][])
26
+
27
+ - Add note about usage with Spring. ([@iBublik][])
28
+
5
29
  ## 0.3.0 (2019-12-25)
6
30
 
7
31
  - Add support of :only, :except params for callbacks. ([@curpeng][])
8
32
 
9
- - Add negation rspec matcher: `have_not_delivered_to`. ([@StanisLove][])
33
+ - Add negation rspec matcher: `have_not_delivered_to`. ([@StanisLove](https://github.com/stanislove))
10
34
 
11
35
  - Improve RSpec matcher's failure message. ([@iBublik][])
12
36
 
@@ -26,3 +50,6 @@ Initial version.
26
50
 
27
51
  [@palkan]: https://github.com/palkan
28
52
  [@curpeng]: https://github.com/curpeng
53
+ [@iBublik]: https://github.com/ibublik
54
+ [@brovikov]: https://github.com/brovikov
55
+ [@dmitryzuev]: https://github.com/dmitryzuev
data/Gemfile CHANGED
@@ -1,13 +1,17 @@
1
- source "https://rubygems.org"
1
+ # frozen_string_literal: true
2
+
3
+ source 'https://rubygems.org'
4
+
5
+ gem 'pry-byebug', platform: :mri
2
6
 
3
7
  gemspec
4
8
 
5
- gem "pry-byebug"
9
+ eval_gemfile "gemfiles/rubocop.gemfile"
6
10
 
7
- local_gemfile = File.join(__dir__, "Gemfile.local")
11
+ local_gemfile = "#{File.dirname(__FILE__)}/Gemfile.local"
8
12
 
9
13
  if File.exist?(local_gemfile)
10
14
  eval(File.read(local_gemfile)) # rubocop:disable Security/Eval
11
15
  else
12
- gem "rails", "~> 5.2"
16
+ gem "rails", "~> 6.0"
13
17
  end
data/README.md CHANGED
@@ -1,5 +1,6 @@
1
1
  [![Gem Version](https://badge.fury.io/rb/active_delivery.svg)](https://badge.fury.io/rb/active_delivery)
2
- [![Build Status](https://travis-ci.org/palkan/active_delivery.svg?branch=master)](https://travis-ci.org/palkan/active_delivery)
2
+ ![Build](https://github.com/palkan/active_delivery/workflows/Build/badge.svg)
3
+ ![JRuby Build](https://github.com/palkan/active_delivery/workflows/JRuby%20Build/badge.svg)
3
4
 
4
5
  # Active Delivery
5
6
 
@@ -11,7 +12,8 @@ Framework providing an entry point (single _interface_) for all types of notific
11
12
  <img src="https://evilmartians.com/badges/sponsored-by-evil-martians.svg" alt="Sponsored by Evil Martians" width="236" height="54"></a>
12
13
 
13
14
  Requirements:
14
- - Ruby ~> 2.4
15
+
16
+ - Ruby ~> 2.5
15
17
 
16
18
  **NOTE**: although most of the examples in this readme are Rails-specific, this gem could be used without Rails/ActiveSupport.
17
19
 
@@ -28,7 +30,8 @@ Here comes _Active Delivery_.
28
30
  In the simplest case when we have only mailers Active Delivery is just a wrapper for Mailer with (possibly) some additional logic provided (e.g., preventing emails to unsubscribed users).
29
31
 
30
32
  Motivations behind Active Delivery:
31
- - organize notifications related logic:
33
+
34
+ - Organize notifications related logic:
32
35
 
33
36
  ```ruby
34
37
  # Before
@@ -43,20 +46,20 @@ def after_some_action
43
46
  end
44
47
  ```
45
48
 
46
- - better testability (see [Testing](#testing)).
49
+ - Better testability (see [Testing](#testing)).
47
50
 
48
51
  ## Installation
49
52
 
50
53
  Add this line to your application's Gemfile:
51
54
 
52
55
  ```ruby
53
- gem 'active_delivery'
56
+ gem "active_delivery"
54
57
  ```
55
58
 
56
59
  And then execute:
57
60
 
58
61
  ```sh
59
- $ bundle
62
+ bundle
60
63
  ```
61
64
 
62
65
  ## Usage
@@ -84,15 +87,23 @@ PostsNotifier.published(user, post).notify_later
84
87
 
85
88
  P.S. Naming ("delivery") is inspired by Basecamp: https://www.youtube.com/watch?v=m1jOWu7woKM.
86
89
 
90
+ **NOTE**: You could specify Mailer class explicitly or by custom pattern, using resolver:
91
+
92
+ ```ruby
93
+ class PostsDelivery < ActiveDelivery::Base
94
+ register_line :custom_mailer, ActiveDelivery::Lines::Mailer, resolver: ->(name) { CustomMailer }
95
+ end
96
+ ```
97
+
87
98
  Delivery also supports _parameterized_ calling:
88
99
 
89
100
  ```ruby
90
- PostsDelivery.with(user: user).notify(:published, post)
101
+ PostsDelivery.with(user: user).notify(:published, post)
91
102
  ```
92
103
 
93
104
  The parameters could be accessed through the `params` instance method (e.g., to implement guard-like logic).
94
105
 
95
- **NOTE**: When params are presents the parametrized mailer is used, i.e.:
106
+ **NOTE**: When params are presents the parameterized mailer is used, i.e.:
96
107
 
97
108
  ```ruby
98
109
  PostsMailer.with(user: user).published(post)
@@ -149,14 +160,15 @@ Active Delivery provides an elegant way to test deliveries in your code (i.e., w
149
160
  it "delivers notification" do
150
161
  expect { subject }.to have_delivered_to(Community::EventsDelivery, :modified, event)
151
162
  .with(profile: profile)
163
+ end
152
164
  ```
153
165
 
154
166
  You can also use such RSpec features as [compound expectations](https://relishapp.com/rspec/rspec-expectations/docs/compound-expectations) and [composed matchers](https://relishapp.com/rspec/rspec-expectations/v/3-8/docs/composing-matchers):
155
167
 
156
168
  ```ruby
157
169
  it "delivers to RSVPed members via .notify" do
158
- expect { subject }.
159
- to have_delivered_to(Community::EventsDelivery, :canceled, an_instance_of(event)).with(
170
+ expect { subject }
171
+ .to have_delivered_to(Community::EventsDelivery, :canceled, an_instance_of(event)).with(
160
172
  a_hash_including(profile: another_profile)
161
173
  ).and have_delivered_to(Community::EventsDelivery, :canceled, event).with(
162
174
  profile: profile
@@ -184,7 +196,7 @@ specify "when event is not found" do
184
196
  end
185
197
  ```
186
198
 
187
- *NOTE:** test mode activated automatically if `RAILS_ENV` or `RACK_ENV` env variable is equal to "test". Otherwise add `require "active_delivery/testing"` to your `spec_helper.rb` / `rails_helper.rb` manually.
199
+ **NOTE:** test mode activated automatically if `RAILS_ENV` or `RACK_ENV` env variable is equal to "test". Otherwise add `require "active_delivery/testing/rspec"` to your `spec_helper.rb` / `rails_helper.rb` manually. This is also required if you're using Spring in test environment (e.g. with help of [spring-commands-rspec](https://github.com/jonleighton/spring-commands-rspec)).
188
200
 
189
201
  ## Custom "lines"
190
202
 
@@ -226,7 +238,6 @@ we call `EventDelivery.notify(:message_arrived, "ping-pong!")`.
226
238
  Line class has the following API:
227
239
 
228
240
  ```ruby
229
-
230
241
  class PigeonLine < ActiveDelivery::Lines::Base
231
242
  # This method is used to infer sender class
232
243
  # `name` is the name of the delivery class
@@ -243,17 +254,17 @@ class PigeonLine < ActiveDelivery::Lines::Base
243
254
  # Called when we want to send message synchronously
244
255
  # `sender` here either `sender_class` or `sender_class.with(params)`
245
256
  # if params passed.
246
- def notify_now(sender, delivery_action, *args)
257
+ def notify_now(sender, delivery_action, *args, **kwargs)
247
258
  # For example, our EventPigeon class returns some `Pigeon` object
248
- pigeon = sender.public_send(delivery_action, *args)
259
+ pigeon = sender.public_send(delivery_action, *args, **kwargs)
249
260
  # PigeonLaunchService do all the sending job
250
261
  PigeonService.launch pigeon
251
262
  end
252
263
 
253
264
  # Called when we want to send a message asynchronously.
254
265
  # For example, you can use a background job here.
255
- def notify_later(sender, delivery_action, *args)
256
- pigeon = sender.public_send(delivery_action, *args)
266
+ def notify_later(sender, delivery_action, *args, **kwargs)
267
+ pigeon = sender.public_send(delivery_action, *args, **kwargs)
257
268
  # PigeonLaunchService do all the sending job
258
269
  PigeonLaunchJob.perform_later pigeon
259
270
  end
@@ -0,0 +1,43 @@
1
+ # How to release a gem
2
+
3
+ This document describes a process of releasing a new version of a gem.
4
+
5
+ 1. Bump version.
6
+
7
+ ```sh
8
+ git commit -m "Bump 1.<x>.<y>"
9
+ ```
10
+
11
+ We're (kinda) using semantic versioning:
12
+
13
+ - Bugfixes should be released as fast as possible as patch versions.
14
+ - New features could be combined and released as minor or patch version upgrades (depending on the _size of the feature_—it's up to maintainers to decide).
15
+ - Breaking API changes should be avoided in minor and patch releases.
16
+ - Breaking dependencies changes (e.g., dropping older Ruby support) could be released in minor versions.
17
+
18
+ How to bump a version:
19
+
20
+ - Change the version number in `lib/active_delivery/version.rb` file.
21
+ - Update the changelog (add new heading with the version name and date).
22
+ - Update the installation documentation if necessary (e.g., during minor and major updates).
23
+
24
+ 2. Push code to GitHub and make sure CI passes.
25
+
26
+ ```sh
27
+ git push
28
+ ```
29
+
30
+ 3. Release a gem.
31
+
32
+ ```sh
33
+ gem release -t
34
+ git push --tags
35
+ ```
36
+
37
+ We use [gem-release](https://github.com/svenfuchs/gem-release) for publishing gems with a single command:
38
+
39
+ ```sh
40
+ gem release -t
41
+ ```
42
+
43
+ Don't forget to push tags and write release notes on GitHub (if necessary).
data/Rakefile CHANGED
@@ -2,9 +2,19 @@
2
2
 
3
3
  require "bundler/gem_tasks"
4
4
  require "rspec/core/rake_task"
5
- require "rubocop/rake_task"
6
5
 
7
- RuboCop::RakeTask.new
8
6
  RSpec::Core::RakeTask.new(:spec)
9
7
 
10
- task default: [:rubocop, :spec]
8
+ begin
9
+ require "rubocop/rake_task"
10
+ RuboCop::RakeTask.new
11
+
12
+ RuboCop::RakeTask.new("rubocop:md") do |task|
13
+ task.options << %w[-c .rubocop-md.yml]
14
+ end
15
+ rescue LoadError
16
+ task(:rubocop) {}
17
+ task("rubocop:md") {}
18
+ end
19
+
20
+ task default: %w[rubocop rubocop:md spec]
@@ -5,17 +5,17 @@ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
5
5
  require "active_delivery/version"
6
6
 
7
7
  Gem::Specification.new do |spec|
8
- spec.name = "active_delivery"
9
- spec.version = ActiveDelivery::VERSION
10
- spec.authors = ["Vladimir Dementyev"]
11
- spec.email = ["dementiev.vm@gmail.com"]
8
+ spec.name = "active_delivery"
9
+ spec.version = ActiveDelivery::VERSION
10
+ spec.authors = ["Vladimir Dementyev"]
11
+ spec.email = ["dementiev.vm@gmail.com"]
12
12
 
13
- spec.summary = "Rails framework for managing all types of notifications in one place"
14
- spec.description = "Rails framework for managing all types of notifications in one place"
15
- spec.homepage = "https://github.com/palkan/active_delivery"
16
- spec.license = "MIT"
13
+ spec.summary = "Rails framework for managing all types of notifications in one place"
14
+ spec.description = "Rails framework for managing all types of notifications in one place"
15
+ spec.homepage = "https://github.com/palkan/active_delivery"
16
+ spec.license = "MIT"
17
17
 
18
- spec.required_ruby_version = ">= 2.4"
18
+ spec.required_ruby_version = ">= 2.5"
19
19
 
20
20
  spec.metadata = {
21
21
  "bug_tracker_uri" => "http://github.com/palkan/active_delivery/issues",
@@ -25,11 +25,11 @@ Gem::Specification.new do |spec|
25
25
  "source_code_uri" => "http://github.com/palkan/active_delivery"
26
26
  }
27
27
 
28
- spec.files = `git ls-files -z`.split("\x0").reject { |f| f.match(%r{^(test|spec|features)/}) }
28
+ spec.files = `git ls-files -z`.split("\x0").reject { |f| f.match(%r{^(test|spec|features)/}) }
29
29
  spec.require_paths = ["lib"]
30
30
 
31
31
  spec.add_development_dependency "bundler", ">= 1.16"
32
- spec.add_development_dependency "rake", "~> 10.0"
32
+ spec.add_development_dependency "rake", "~> 13.0"
33
33
  spec.add_development_dependency "rspec", "~> 3.0"
34
- spec.add_development_dependency "standard", "~> 0.0.12"
34
+ spec.add_development_dependency "standard", "~> 0.2.0"
35
35
  end
@@ -0,0 +1,8 @@
1
+ # Format: one word per line. Empty lines and #-comments are supported too.
2
+ # If you want to add word with its forms, you can write 'word: example' (without quotes) on the line,
3
+ # where 'example' is existing word with the same possible forms (endings) as your word.
4
+ # Example: deduplicate: duplicate
5
+ assignees
6
+ matchers
7
+ palkan
8
+ testability
@@ -0,0 +1,5 @@
1
+ source 'https://rubygems.org'
2
+
3
+ gem 'rails', '~> 5.0'
4
+
5
+ gemspec path: '..'
@@ -0,0 +1,5 @@
1
+ source 'https://rubygems.org'
2
+
3
+ gem 'rails', '~> 5.0'
4
+
5
+ gemspec path: '..'
@@ -0,0 +1,8 @@
1
+ # frozen_string_literal: true
2
+
3
+ source "https://rubygems.org"
4
+
5
+ gem "activesupport", "~> 5.0.7"
6
+ gem "actionmailer", "~> 5.0.7"
7
+
8
+ gemspec path: ".."
@@ -0,0 +1,5 @@
1
+ source 'https://rubygems.org'
2
+
3
+ gem 'rails', '~> 6.0'
4
+
5
+ gemspec path: '..'
@@ -1,8 +1,6 @@
1
- # frozen_string_literal: true
1
+ source 'https://rubygems.org'
2
2
 
3
- source "https://rubygems.org"
3
+ gem 'arel', github: 'rails/arel'
4
+ gem 'rails', github: 'rails/rails'
4
5
 
5
- gem "rails", github: "rails/rails"
6
- gem "rubocop", github: "rubocop-hq/rubocop"
7
-
8
- gemspec path: ".."
6
+ gemspec path: '..'
@@ -0,0 +1,4 @@
1
+ source "https://rubygems.org" do
2
+ gem "rubocop-md", "~> 0.3"
3
+ gem "standard", "~> 0.2.0"
4
+ end
@@ -0,0 +1,18 @@
1
+ pre-commit:
2
+ commands:
3
+ mdl:
4
+ tags: style
5
+ glob: "**/*.md"
6
+ run: mdl {staged_files}
7
+ liche:
8
+ tags: links
9
+ glob: "docs/*.md"
10
+ run: liche -d docs/ -r docs/* && test {staged_files}
11
+ forspell:
12
+ tags: grammar
13
+ glob: "**/*.md"
14
+ run: forspell {staged_files}
15
+ rubocop:
16
+ tags: style
17
+ glob: "**/*.md"
18
+ run: BUNDLE_GEMFILE=gemfiles/rubocop.gemfile bundle exec rubocop {staged_files}
@@ -43,6 +43,8 @@ module ActionMailer
43
43
  class MessageDelivery < ActionMailer::MessageDelivery # :nodoc:
44
44
  def initialize(mailer_class, action, params, *args)
45
45
  super(mailer_class, action, *args)
46
+ @mailer ||= mailer_class
47
+ @mail_method ||= action
46
48
  @params = params
47
49
  end
48
50
 
@@ -57,12 +59,16 @@ module ActionMailer
57
59
  private
58
60
 
59
61
  def processed_mailer
60
- @processed_mailer ||= @mailer.send(:new, nil, *@args).tap do |m|
62
+ @processed_mailer ||= @mailer.send(*mailer_args).tap do |m|
61
63
  m.params = @params
62
64
  m.process @mail_method, *@args
63
65
  end
64
66
  end
65
67
 
68
+ def mailer_args
69
+ ActionMailer::VERSION::MAJOR < 5 ? [:new, nil, *@args] : [:new]
70
+ end
71
+
66
72
  def enqueue_delivery(delivery_method, options = {})
67
73
  if processed?
68
74
  super
@@ -37,8 +37,8 @@ module ActiveDelivery
37
37
  alias with new
38
38
 
39
39
  # Enqueues delivery (i.e. uses #deliver_later for mailers)
40
- def notify(*args)
41
- new.notify(*args)
40
+ def notify(*args, **kwargs)
41
+ new.notify(*args, **kwargs)
42
42
  end
43
43
 
44
44
  # The same as .notify but delivers synchronously
@@ -86,9 +86,9 @@ module ActiveDelivery
86
86
  end
87
87
 
88
88
  # Enqueues delivery (i.e. uses #deliver_later for mailers)
89
- def notify(mid, *args)
89
+ def notify(mid, *args, **kwargs)
90
90
  @notification_name = mid
91
- do_notify(*args)
91
+ do_notify(*args, **kwargs)
92
92
  end
93
93
 
94
94
  # The same as .notify but delivers synchronously
@@ -99,17 +99,17 @@ module ActiveDelivery
99
99
 
100
100
  private
101
101
 
102
- def do_notify(*args, sync: false)
102
+ def do_notify(*args, sync: false, **kwargs)
103
103
  delivery_lines.each do |type, line|
104
104
  next if line.handler_class.nil?
105
105
  next unless line.notify?(notification_name)
106
106
 
107
- notify_line(type, *args, params: params, sync: sync)
107
+ notify_line(type, *args, params: params, sync: sync, **kwargs)
108
108
  end
109
109
  end
110
110
 
111
- def notify_line(type, *args)
112
- delivery_lines[type].notify(notification_name, *args)
111
+ def notify_line(type, *args, **kwargs)
112
+ delivery_lines[type].notify(notification_name, *args, **kwargs)
113
113
  end
114
114
 
115
115
  def delivery_lines
@@ -41,17 +41,17 @@ module ActiveDelivery
41
41
  end
42
42
 
43
43
  module InstanceExt
44
- def do_notify(*)
45
- run_callbacks(:notify) { super }
44
+ def do_notify(*args, **kwargs)
45
+ run_callbacks(:notify) { super(*args, **kwargs) }
46
46
  end
47
47
 
48
- def notify_line(type, *)
49
- run_callbacks(type) { super }
48
+ def notify_line(*args, **kwargs)
49
+ run_callbacks(args.first) { super(*args, **kwargs) }
50
50
  end
51
51
  end
52
52
 
53
53
  module SingltonExt
54
- def register_line(line_id, *args)
54
+ def register_line(line_id, *args, **kwargs)
55
55
  super
56
56
  define_line_callbacks line_id
57
57
  end
@@ -73,24 +73,24 @@ module ActiveDelivery
73
73
 
74
74
  def define_line_callbacks(name)
75
75
  define_callbacks name,
76
- terminator: CALLBACK_TERMINATOR,
77
- skip_after_callbacks_if_terminated: true
76
+ terminator: CALLBACK_TERMINATOR,
77
+ skip_after_callbacks_if_terminated: true
78
78
  end
79
79
 
80
- def before_notify(method_or_block = nil, on: :notify, **options)
81
- method_or_block ||= Proc.new
80
+ def before_notify(method_or_block = nil, on: :notify, **options, &block)
81
+ method_or_block ||= block
82
82
  _normalize_callback_options(options)
83
83
  set_callback on, :before, method_or_block, options
84
84
  end
85
85
 
86
- def after_notify(method_or_block = nil, on: :notify, **options)
87
- method_or_block ||= Proc.new
86
+ def after_notify(method_or_block = nil, on: :notify, **options, &block)
87
+ method_or_block ||= block
88
88
  _normalize_callback_options(options)
89
89
  set_callback on, :after, method_or_block, options
90
90
  end
91
91
 
92
- def around_notify(method_or_block = nil, on: :notify, **options)
93
- method_or_block ||= Proc.new
92
+ def around_notify(method_or_block = nil, on: :notify, **options, &block)
93
+ method_or_block ||= block
94
94
  _normalize_callback_options(options)
95
95
  set_callback on, :around, method_or_block, options
96
96
  end
@@ -11,6 +11,7 @@ module ActiveDelivery
11
11
  @id = id
12
12
  @owner = owner
13
13
  @options = options.tap(&:freeze)
14
+ @resolver = options[:resolver]
14
15
  end
15
16
 
16
17
  def dup_for(new_owner)
@@ -18,21 +19,22 @@ module ActiveDelivery
18
19
  end
19
20
 
20
21
  def resolve_class(name)
22
+ resolver&.call(name)
21
23
  end
22
24
 
23
25
  def notify?(method_name)
24
26
  handler_class.respond_to?(method_name)
25
27
  end
26
28
 
27
- def notify_now(handler, mid, *args)
29
+ def notify_now(handler, mid, *args, **kwargs)
28
30
  end
29
31
 
30
- def notify_later(handler, mid, *args)
32
+ def notify_later(handler, mid, *args, **kwargs)
31
33
  end
32
34
 
33
- def notify(mid, *args, params:, sync:)
34
- clazz = params.empty? ? handler_class : handler_class.with(params)
35
- sync ? notify_now(clazz, mid, *args) : notify_later(clazz, mid, *args)
35
+ def notify(mid, *args, params:, sync:, **kwargs)
36
+ clazz = params.empty? ? handler_class : handler_class.with(**params)
37
+ sync ? notify_now(clazz, mid, *args, **kwargs) : notify_later(clazz, mid, *args, **kwargs)
36
38
  end
37
39
 
38
40
  def handler_class
@@ -54,6 +56,8 @@ module ActiveDelivery
54
56
 
55
57
  owner.superclass.public_send(handler_method)
56
58
  end
59
+
60
+ attr_reader :resolver
57
61
  end
58
62
  end
59
63
  end
@@ -1,6 +1,6 @@
1
1
  # frozen_string_literal: true
2
2
 
3
- if ActionMailer::VERSION::MAJOR < 5
3
+ if ActionMailer::VERSION::MAJOR < 5 || (ActionMailer::VERSION::MAJOR == 5 && ActionMailer::VERSION::MINOR < 2)
4
4
  require "active_delivery/action_mailer/parameterized"
5
5
  end
6
6
 
@@ -9,23 +9,29 @@ module ActiveDelivery
9
9
  class Mailer < Base
10
10
  alias mailer_class handler_class
11
11
 
12
- def resolve_class(name)
13
- name.gsub(/Delivery$/, "Mailer").safe_constantize
14
- end
12
+ DEFAULT_RESOLVER = ->(name) { name.gsub(/Delivery$/, "Mailer").safe_constantize }
15
13
 
16
14
  def notify?(method_name)
17
15
  mailer_class.action_methods.include?(method_name.to_s)
18
16
  end
19
17
 
20
- def notify_now(mailer, mid, *args)
21
- mailer.public_send(mid, *args).deliver_now
18
+ def notify_now(mailer, mid, *args, **kwargs)
19
+ if kwargs.empty?
20
+ mailer.public_send(mid, *args).deliver_now
21
+ else
22
+ mailer.public_send(mid, *args, **kwargs).deliver_now
23
+ end
22
24
  end
23
25
 
24
- def notify_later(mailer, mid, *args)
25
- mailer.public_send(mid, *args).deliver_later
26
+ def notify_later(mailer, mid, *args, **kwargs)
27
+ if kwargs.empty?
28
+ mailer.public_send(mid, *args).deliver_later
29
+ else
30
+ mailer.public_send(mid, *args, **kwargs).deliver_later
31
+ end
26
32
  end
27
33
  end
28
34
 
29
- ActiveDelivery::Base.register_line :mailer, Mailer
35
+ ActiveDelivery::Base.register_line :mailer, Mailer, resolver: Mailer::DEFAULT_RESOLVER
30
36
  end
31
37
  end
@@ -4,18 +4,18 @@ module ActiveDelivery
4
4
  module TestDelivery
5
5
  class << self
6
6
  def enable
7
- raise ArgumentError, "block is reauired" unless block_given?
7
+ raise ArgumentError, "block is required" unless block_given?
8
8
  begin
9
9
  clear
10
- Thread.current[:active_delivery_testing] = true
10
+ Thread.current.thread_variable_set(:active_delivery_testing, true)
11
11
  yield
12
12
  ensure
13
- Thread.current[:active_delivery_testing] = false
13
+ Thread.current.thread_variable_set(:active_delivery_testing, false)
14
14
  end
15
15
  end
16
16
 
17
17
  def enabled?
18
- Thread.current[:active_delivery_testing] == true
18
+ Thread.current.thread_variable_get(:active_delivery_testing) == true
19
19
  end
20
20
 
21
21
  def track(delivery, event, args, options)
@@ -45,4 +45,4 @@ end
45
45
 
46
46
  ActiveDelivery::Base.prepend ActiveDelivery::TestDelivery
47
47
 
48
- require "active_delivery/testing/rspec" if defined?(RSpec)
48
+ require "active_delivery/testing/rspec" if defined?(RSpec::Core)
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module ActiveDelivery
4
- VERSION = "0.3.0"
4
+ VERSION = "0.4.3"
5
5
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: active_delivery
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.3.0
4
+ version: 0.4.3
5
5
  platform: ruby
6
6
  authors:
7
7
  - Vladimir Dementyev
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2019-12-25 00:00:00.000000000 Z
11
+ date: 2020-08-21 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler
@@ -30,14 +30,14 @@ dependencies:
30
30
  requirements:
31
31
  - - "~>"
32
32
  - !ruby/object:Gem::Version
33
- version: '10.0'
33
+ version: '13.0'
34
34
  type: :development
35
35
  prerelease: false
36
36
  version_requirements: !ruby/object:Gem::Requirement
37
37
  requirements:
38
38
  - - "~>"
39
39
  - !ruby/object:Gem::Version
40
- version: '10.0'
40
+ version: '13.0'
41
41
  - !ruby/object:Gem::Dependency
42
42
  name: rspec
43
43
  requirement: !ruby/object:Gem::Requirement
@@ -58,14 +58,14 @@ dependencies:
58
58
  requirements:
59
59
  - - "~>"
60
60
  - !ruby/object:Gem::Version
61
- version: 0.0.12
61
+ version: 0.2.0
62
62
  type: :development
63
63
  prerelease: false
64
64
  version_requirements: !ruby/object:Gem::Requirement
65
65
  requirements:
66
66
  - - "~>"
67
67
  - !ruby/object:Gem::Version
68
- version: 0.0.12
68
+ version: 0.2.0
69
69
  description: Rails framework for managing all types of notifications in one place
70
70
  email:
71
71
  - dementiev.vm@gmail.com
@@ -73,20 +73,37 @@ executables: []
73
73
  extensions: []
74
74
  extra_rdoc_files: []
75
75
  files:
76
+ - ".gem_release.yml"
77
+ - ".github/ISSUE_TEMPLATE/bug_report.md"
78
+ - ".github/ISSUE_TEMPLATE/feature_request.md"
79
+ - ".github/PULL_REQUEST_TEMPLATE.md"
80
+ - ".github/workflows/docs-lint.yml"
81
+ - ".github/workflows/rspec-jruby.yml"
82
+ - ".github/workflows/rspec.yml"
83
+ - ".github/workflows/rubocop.yml"
76
84
  - ".gitignore"
85
+ - ".mdlrc"
77
86
  - ".rspec"
87
+ - ".rubocop-md.yml"
78
88
  - ".rubocop.yml"
79
- - ".travis.yml"
80
89
  - CHANGELOG.md
81
90
  - Gemfile
82
91
  - LICENSE.txt
83
92
  - README.md
93
+ - RELEASING.md
84
94
  - Rakefile
85
95
  - active_delivery.gemspec
86
96
  - bin/console
87
97
  - bin/setup
98
+ - forspell.dict
99
+ - gemfiles/jruby.gemfile
88
100
  - gemfiles/rails42.gemfile
101
+ - gemfiles/rails5.gemfile
102
+ - gemfiles/rails50.gemfile
103
+ - gemfiles/rails6.gemfile
89
104
  - gemfiles/railsmaster.gemfile
105
+ - gemfiles/rubocop.gemfile
106
+ - lefthook.yml
90
107
  - lib/active_delivery.rb
91
108
  - lib/active_delivery/action_mailer/parameterized.rb
92
109
  - lib/active_delivery/base.rb
@@ -113,14 +130,14 @@ required_ruby_version: !ruby/object:Gem::Requirement
113
130
  requirements:
114
131
  - - ">="
115
132
  - !ruby/object:Gem::Version
116
- version: '2.4'
133
+ version: '2.5'
117
134
  required_rubygems_version: !ruby/object:Gem::Requirement
118
135
  requirements:
119
136
  - - ">="
120
137
  - !ruby/object:Gem::Version
121
138
  version: '0'
122
139
  requirements: []
123
- rubygems_version: 3.0.3
140
+ rubygems_version: 3.0.6
124
141
  signing_key:
125
142
  specification_version: 4
126
143
  summary: Rails framework for managing all types of notifications in one place
@@ -1,31 +0,0 @@
1
- sudo: false
2
- language: ruby
3
- cache: bundler
4
-
5
- notifications:
6
- email: false
7
-
8
- before_install:
9
- - gem update --system
10
- - gem install bundler -v '< 2'
11
-
12
- matrix:
13
- fast_finish: true
14
- include:
15
- - rvm: ruby-head
16
- gemfile: gemfiles/railsmaster.gemfile
17
- - rvm: 2.5.3
18
- gemfile: Gemfile
19
- - rvm: 2.6.0
20
- gemfile: Gemfile
21
- - rvm: 2.5.3
22
- gemfile: Gemfile
23
- env:
24
- - NO_RAILS=1
25
- - rvm: 2.4.3
26
- gemfile: Gemfile
27
- - rvm: 2.4.3
28
- gemfile: gemfiles/rails42.gemfile
29
- allow_failures:
30
- - rvm: ruby-head
31
- gemfile: gemfiles/railsmaster.gemfile