ahoy_email 2.0.1 → 2.0.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 69eb9c77891a37c75ef7f7683211c90159cbb8aefd64fa14a0b1b35d2e16d0eb
4
- data.tar.gz: a937ba8e9362d1c2551f5c193b9a3bbf1b4132f3df9ddb77f3f838f633fb2f07
3
+ metadata.gz: 12cfd52040334d8582ee01785c46c290d9a8e125d79ea5a5cddabed3d26ed144
4
+ data.tar.gz: db924f04d522c4bb9fd488fb34533349b231148170de637fff11ca34c6c18b36
5
5
  SHA512:
6
- metadata.gz: 4b12c970be432d7db95fdb8eaade5766f69fc7826a94f41474ba5c2a35da1ea85b6317f83250cb1c8f41c7fe876028b1377958709d2c84ff9bd303926ac8ab5a
7
- data.tar.gz: 96dcc647ee3777e27b14d7628025d96ea92efce7160d36da0b066b72d9dc5aac8196008699a93673d81d0fdcb909aa69874b349dffdbaf0e32e4d7511a32df5a
6
+ metadata.gz: ba35f76f9d5bb2d52972ab648179e710c16eeda09bc51b4f91aff083bad354ec5dd6b8c98985b913efbf40c9e3215a3111e2a45978c647cf2fa8d9bd96519925
7
+ data.tar.gz: 1247bc81b9cc52a43ec480640c4c94989cfcf7ac4c0868c5c5cdeb0d85da013f93e9bc61993f78d94a8191819e6b7c76d6593f84d70203ed329793debbf7df2a
data/CHANGELOG.md CHANGED
@@ -1,3 +1,7 @@
1
+ ## 2.0.2 (2021-03-14)
2
+
3
+ - Added support for Mongoid to database subscriber
4
+
1
5
  ## 2.0.1 (2021-03-08)
2
6
 
3
7
  - Added database subscriber
@@ -10,9 +10,16 @@ module AhoyEmail
10
10
 
11
11
  def stats(campaign)
12
12
  sends = Ahoy::Message.where(campaign: campaign).count
13
- result = Ahoy::Click.where(campaign: campaign).select("COUNT(*) AS clicks, COUNT(DISTINCT token) AS unique_clicks").to_a[0]
14
- clicks = result.clicks
15
- unique_clicks = result.unique_clicks
13
+
14
+ if defined?(ActiveRecord) && Ahoy::Click < ActiveRecord::Base
15
+ result = Ahoy::Click.where(campaign: campaign).select("COUNT(*) AS clicks, COUNT(DISTINCT token) AS unique_clicks").to_a[0]
16
+ clicks = result.clicks
17
+ unique_clicks = result.unique_clicks
18
+ else
19
+ clicks = Ahoy::Click.where(campaign: campaign).count
20
+ # TODO use aggregation framework
21
+ unique_clicks = Ahoy::Click.where(campaign: campaign).distinct(:token).count
22
+ end
16
23
 
17
24
  if sends > 0 || clicks > 0
18
25
  {
@@ -25,7 +32,11 @@ module AhoyEmail
25
32
  end
26
33
 
27
34
  def campaigns
28
- Ahoy::Message.where.not(campaign: nil).distinct.pluck(:campaign)
35
+ if defined?(ActiveRecord) && Ahoy::Message < ActiveRecord::Base
36
+ Ahoy::Message.where.not(campaign: nil).distinct.pluck(:campaign)
37
+ else
38
+ Ahoy::Message.where(campaign: {"$ne" => nil}).distinct(:campaign)
39
+ end
29
40
  end
30
41
  end
31
42
  end
@@ -1,3 +1,3 @@
1
1
  module AhoyEmail
2
- VERSION = "2.0.1"
2
+ VERSION = "2.0.2"
3
3
  end
@@ -0,0 +1,15 @@
1
+ require "rails/generators"
2
+
3
+ module Ahoy
4
+ module Generators
5
+ module Clicks
6
+ class MongoidGenerator < Rails::Generators::Base
7
+ source_root File.join(__dir__, "templates")
8
+
9
+ def copy_templates
10
+ template "mongoid.rb", "app/models/ahoy/click.rb"
11
+ end
12
+ end
13
+ end
14
+ end
15
+ end
@@ -0,0 +1,8 @@
1
+ class Ahoy::Click
2
+ include Mongoid::Document
3
+
4
+ field :campaign, type: String
5
+ field :token, type: String
6
+
7
+ index({campaign: 1})
8
+ end
@@ -4,7 +4,33 @@ module Ahoy
4
4
  module Generators
5
5
  class ClicksGenerator < Rails::Generators::Base
6
6
  def copy_templates
7
- invoke "ahoy:clicks:activerecord"
7
+ activerecord = defined?(ActiveRecord)
8
+ mongoid = defined?(Mongoid)
9
+
10
+ selection =
11
+ if activerecord && mongoid
12
+ puts <<-MSG
13
+
14
+ Which data store would you like to use?
15
+ 1. Active Record (default)
16
+ 2. Mongoid
17
+ MSG
18
+
19
+ ask(">")
20
+ elsif activerecord
21
+ "1"
22
+ else
23
+ "2"
24
+ end
25
+
26
+ case selection
27
+ when "", "1"
28
+ invoke "ahoy:clicks:activerecord"
29
+ when "2"
30
+ invoke "ahoy:clicks:mongoid"
31
+ else
32
+ abort "Error: must enter a number [1-2]"
33
+ end
8
34
  end
9
35
  end
10
36
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: ahoy_email
3
3
  version: !ruby/object:Gem::Version
4
- version: 2.0.1
4
+ version: 2.0.2
5
5
  platform: ruby
6
6
  authors:
7
7
  - Andrew Kane
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2021-03-08 00:00:00.000000000 Z
11
+ date: 2021-03-15 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: actionmailer
@@ -92,7 +92,9 @@ files:
92
92
  - lib/ahoy_email/utils.rb
93
93
  - lib/ahoy_email/version.rb
94
94
  - lib/generators/ahoy/clicks/activerecord_generator.rb
95
+ - lib/generators/ahoy/clicks/mongoid_generator.rb
95
96
  - lib/generators/ahoy/clicks/templates/migration.rb.tt
97
+ - lib/generators/ahoy/clicks/templates/mongoid.rb.tt
96
98
  - lib/generators/ahoy/clicks_generator.rb
97
99
  - lib/generators/ahoy/messages/activerecord_generator.rb
98
100
  - lib/generators/ahoy/messages/mongoid_generator.rb