caffeinate 0.7.0 → 0.8.4

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: 93135cbbdb419e6d7eccd587c9b10447c3c7247cc425ff86057a328b27761baa
4
- data.tar.gz: 5b7993dff3ccb1e3e468438c5b50f73f525d2a03418e0ceaaa03f751c097f010
3
+ metadata.gz: 3a1b112ae3aa4c5c0d6f5d0754dffe6fc720c025739d3b78487b78754b4bd8fb
4
+ data.tar.gz: a7ede18dbf114ebf23c3c6eba347b60524963574a921687ffba1943885055777
5
5
  SHA512:
6
- metadata.gz: 504b0123a7628ff97fda131c0ddb55ccc76d1ddc63b9a75afb799170ad3e10bbdc4598860848045eb6ac5976a44575bbb0287bf0bcb33744c29e12c551feb8e0
7
- data.tar.gz: 48f9293fdbe4f34ed6a0d46bdfce4278783a8e49fde0c740a5f988572790570209e6e06db559bdfc7acaf0a15ab00718af14e8e43d69d30332b9a8a578d3410b
6
+ metadata.gz: 83efe161d7aa1885ebd1080b1fe640ea87e21b9dd1dbf494998b361a4ae6f1188a23a4aa509766edec90eabea2fbc9b08d6f8b305592cbaeeaf38343737e16ef
7
+ data.tar.gz: 4c42564577a0321ad57cf7a052645a2ea3fe2670e701789dfb123a1801e95a98dc3754602d318b9d341921b1f41c47cc03d8bfd1a678d4ef3e3b0317d32e29c6
@@ -35,10 +35,8 @@ module Caffeinate
35
35
  end
36
36
 
37
37
  # Checks to see if the subscriber exists.
38
- #
39
- # Use `find_by` so that we don't have to load the record twice. Often used with `subscribes?`
40
38
  def subscriber(record, **args)
41
- @subscriber ||= caffeinate_campaign_subscriptions.find_by(subscriber: record, **args)
39
+ caffeinate_campaign_subscriptions.find_by(subscriber: record, **args)
42
40
  end
43
41
 
44
42
  # Check if the subscriber exists
@@ -58,7 +56,7 @@ module Caffeinate
58
56
  def unsubscribe(subscriber, **args)
59
57
  reason = args.delete(:reason)
60
58
  subscription = subscriber(subscriber, **args)
61
- raise ActiveRecord::RecordInvalid, subscription if subscription.nil?
59
+ raise ::ActiveRecord::RecordInvalid, subscription if subscription.nil?
62
60
 
63
61
  subscription.unsubscribe!(reason)
64
62
  end
@@ -1,7 +1,7 @@
1
1
  <!DOCTYPE html>
2
2
  <html>
3
3
  <head>
4
- <title><%= Rails.application.class.module_parent_name %></title>
4
+ <title></title>
5
5
  </head>
6
6
  <body>
7
7
 
@@ -1,6 +1,16 @@
1
1
  # frozen_string_literal: true
2
2
 
3
- require 'rails/all'
3
+ require 'active_support'
4
+
5
+ %w(
6
+ active_record/railtie
7
+ action_controller/railtie
8
+ action_view/railtie
9
+ action_mailer/railtie
10
+ ).each do |railtie|
11
+ require railtie
12
+ end
13
+
4
14
  require 'caffeinate/mail_ext'
5
15
  require 'caffeinate/engine'
6
16
  require 'caffeinate/drip'
@@ -25,6 +25,8 @@ module Caffeinate
25
25
  start = mailing.instance_exec(&options[:start])
26
26
  start += options[:every] if mailing.caffeinate_campaign_subscription.caffeinate_mailings.count.positive?
27
27
  date = start.from_now
28
+ elsif options[:on]
29
+ date = mailing.instance_exec(&options[:on])
28
30
  else
29
31
  date = options[:delay].from_now
30
32
  end
@@ -16,14 +16,14 @@ module Caffeinate
16
16
  end
17
17
 
18
18
  # Ends the CampaignSubscription
19
- def end!
20
- mailing.caffeinate_campaign_subscription.end!
19
+ def end!(**args)
20
+ mailing.caffeinate_campaign_subscription.end!(**args)
21
21
  false
22
22
  end
23
23
 
24
24
  # Unsubscribes the CampaignSubscription
25
- def unsubscribe!
26
- mailing.caffeinate_campaign_subscription.unsubscribe!
25
+ def unsubscribe!(**args)
26
+ mailing.caffeinate_campaign_subscription.unsubscribe!(**args)
27
27
  false
28
28
  end
29
29
 
@@ -42,7 +42,7 @@ module Caffeinate
42
42
 
43
43
  def validate_drip_options(action, options)
44
44
  options.symbolize_keys!
45
- options.assert_valid_keys(:mailer_class, :step, :delay, :every, :start, :using, :mailer, :at)
45
+ options.assert_valid_keys(:mailer_class, :step, :delay, :every, :start, :using, :mailer, :at, :on)
46
46
  options[:mailer_class] ||= options[:mailer] || @dripper.defaults[:mailer_class]
47
47
  options[:using] ||= @dripper.defaults[:using]
48
48
  options[:step] ||= @dripper.drips.size + 1
@@ -51,8 +51,8 @@ module Caffeinate
51
51
  raise ArgumentError, "You must define :mailer_class or :mailer in the options for #{action.inspect} on #{@dripper.inspect}"
52
52
  end
53
53
 
54
- if options[:every].nil? && options[:delay].nil?
55
- raise ArgumentError, "You must define :delay in the options for #{action.inspect} on #{@dripper.inspect}"
54
+ if options[:every].nil? && options[:delay].nil? && options[:on].nil?
55
+ raise ArgumentError, "You must define :delay or :on or :every in the options for #{action.inspect} on #{@dripper.inspect}"
56
56
  end
57
57
 
58
58
  options
@@ -20,7 +20,7 @@ module Caffeinate
20
20
  .upcoming
21
21
  .unsent
22
22
  .joins(:caffeinate_campaign_subscription)
23
- .merge(Caffeinate::CampaignSubscription.active)
23
+ .merge(Caffeinate::CampaignSubscription.active.where(caffeinate_campaign: self.campaign))
24
24
  .in_batches(of: self.class.batch_size)
25
25
  .each do |batch|
26
26
  run_callbacks(:on_perform, self, batch)
@@ -1,6 +1,10 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module Mail
4
+ def self.from_source(source)
5
+ Mail.new Mail::Utilities.binary_unsafe_to_crlf(source.to_s)
6
+ end
7
+
4
8
  # Extend Mail::Message to account for a Caffeinate::Mailing
5
9
  class Message
6
10
  attr_accessor :caffeinate_mailing
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module Caffeinate
4
- VERSION = '0.7.0'
4
+ VERSION = '0.8.4'
5
5
  end
@@ -0,0 +1,44 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'rails/generators/base'
4
+
5
+ module Caffeinate
6
+ module Generators
7
+ module ViewPathTemplates #:nodoc:
8
+ extend ActiveSupport::Concern
9
+
10
+ included do
11
+ public_task :copy_views
12
+ end
13
+
14
+ def copy_views
15
+ view_directory :campaign_subscriptions
16
+ end
17
+
18
+ protected
19
+
20
+ def view_directory(name, _target_path = nil)
21
+ directory name.to_s, _target_path || "#{target_path}/#{name}" do |content|
22
+ content
23
+ end
24
+ end
25
+
26
+ def target_path
27
+ @target_path ||= "app/views/caffeinate"
28
+ end
29
+ end
30
+
31
+ class SharedViewsGenerator < Rails::Generators::Base #:nodoc:
32
+ include ViewPathTemplates
33
+ source_root File.expand_path("../../../../app/views/caffeinate", __FILE__)
34
+ desc "Copies shared Caffeinate views to your application."
35
+ hide!
36
+ end
37
+
38
+ class ViewsGenerator < Rails::Generators::Base
39
+ desc "Copies Caffeinate views to your application."
40
+
41
+ invoke SharedViewsGenerator
42
+ end
43
+ end
44
+ end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: caffeinate
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.7.0
4
+ version: 0.8.4
5
5
  platform: ruby
6
6
  authors:
7
7
  - Josh Brody
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2020-12-15 00:00:00.000000000 Z
11
+ date: 2020-12-23 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: rails
@@ -177,6 +177,7 @@ files:
177
177
  - lib/generators/caffeinate/install_generator.rb
178
178
  - lib/generators/caffeinate/templates/application_dripper.rb
179
179
  - lib/generators/caffeinate/templates/caffeinate.rb
180
+ - lib/generators/caffeinate/views_generator.rb
180
181
  homepage: https://github.com/joshmn/caffeinate
181
182
  licenses:
182
183
  - MIT