digest_notifier 0.0.6
Sign up to get free protection for your applications and to get access to all the features.
- data/.document +5 -0
- data/Gemfile +14 -0
- data/Gemfile.lock +41 -0
- data/LICENSE.txt +20 -0
- data/README.md +5 -0
- data/README.rdoc +19 -0
- data/Rakefile +53 -0
- data/VERSION +1 -0
- data/digest_notifier.gemspec +80 -0
- data/lib/app/mailer/digest_mailer.rb +29 -0
- data/lib/app/models/digest_email_delivery.rb +3 -0
- data/lib/app/models/digest_email_group.rb +47 -0
- data/lib/app/models/digest_email_item.rb +16 -0
- data/lib/app/views/digest_notifier/digest_mailer/digest_notification.slim +1 -0
- data/lib/digest_notifier/message_sending.rb +21 -0
- data/lib/digest_notifier/performable_digest.rb +20 -0
- data/lib/digest_notifier/railtie.rb +10 -0
- data/lib/digest_notifier/tasks.rb +25 -0
- data/lib/digest_notifier.rb +43 -0
- data/lib/generators/digest_notifier/install_generator.rb +48 -0
- data/lib/generators/digest_notifier/templates/README +1 -0
- data/lib/generators/digest_notifier/templates/create_digest_email_deliveries.rb +24 -0
- data/lib/generators/digest_notifier/templates/create_digest_email_groups.rb +22 -0
- data/lib/generators/digest_notifier/templates/create_digest_email_items.rb +14 -0
- data/lib/generators/digest_notifier/templates/digest_notifier_config.rb +19 -0
- metadata +181 -0
data/.document
ADDED
data/Gemfile
ADDED
@@ -0,0 +1,14 @@
|
|
1
|
+
source "http://rubygems.org"
|
2
|
+
# Add dependencies required to use your gem here.
|
3
|
+
# Example:
|
4
|
+
# gem "activesupport", ">= 2.3.5"
|
5
|
+
gem 'slim', '>= 1.0.4'
|
6
|
+
# Add dependencies to develop your gem here.
|
7
|
+
# Include everything needed to run rake, tests, features, etc.
|
8
|
+
group :development do
|
9
|
+
gem "shoulda", ">= 0"
|
10
|
+
gem "rdoc", "~> 3.12"
|
11
|
+
gem "bundler", ">= 1.0.0"
|
12
|
+
gem "jeweler", "~> 1.8.4"
|
13
|
+
gem "rcov", ">= 0"
|
14
|
+
end
|
data/Gemfile.lock
ADDED
@@ -0,0 +1,41 @@
|
|
1
|
+
GEM
|
2
|
+
remote: http://rubygems.org/
|
3
|
+
specs:
|
4
|
+
activesupport (3.2.9)
|
5
|
+
i18n (~> 0.6)
|
6
|
+
multi_json (~> 1.0)
|
7
|
+
git (1.2.5)
|
8
|
+
i18n (0.6.1)
|
9
|
+
jeweler (1.8.4)
|
10
|
+
bundler (~> 1.0)
|
11
|
+
git (>= 1.2.5)
|
12
|
+
rake
|
13
|
+
rdoc
|
14
|
+
json (1.7.5)
|
15
|
+
multi_json (1.3.7)
|
16
|
+
rake (10.0.2)
|
17
|
+
rcov (1.0.0)
|
18
|
+
rdoc (3.12)
|
19
|
+
json (~> 1.4)
|
20
|
+
shoulda (3.3.2)
|
21
|
+
shoulda-context (~> 1.0.1)
|
22
|
+
shoulda-matchers (~> 1.4.1)
|
23
|
+
shoulda-context (1.0.1)
|
24
|
+
shoulda-matchers (1.4.1)
|
25
|
+
activesupport (>= 3.0.0)
|
26
|
+
slim (1.3.5)
|
27
|
+
temple (~> 0.5.5)
|
28
|
+
tilt (~> 1.3.3)
|
29
|
+
temple (0.5.5)
|
30
|
+
tilt (1.3.3)
|
31
|
+
|
32
|
+
PLATFORMS
|
33
|
+
ruby
|
34
|
+
|
35
|
+
DEPENDENCIES
|
36
|
+
bundler (>= 1.0.0)
|
37
|
+
jeweler (~> 1.8.4)
|
38
|
+
rcov
|
39
|
+
rdoc (~> 3.12)
|
40
|
+
shoulda
|
41
|
+
slim (>= 1.0.4)
|
data/LICENSE.txt
ADDED
@@ -0,0 +1,20 @@
|
|
1
|
+
Copyright (c) 2012 Naveed Ahmad
|
2
|
+
|
3
|
+
Permission is hereby granted, free of charge, to any person obtaining
|
4
|
+
a copy of this software and associated documentation files (the
|
5
|
+
"Software"), to deal in the Software without restriction, including
|
6
|
+
without limitation the rights to use, copy, modify, merge, publish,
|
7
|
+
distribute, sublicense, and/or sell copies of the Software, and to
|
8
|
+
permit persons to whom the Software is furnished to do so, subject to
|
9
|
+
the following conditions:
|
10
|
+
|
11
|
+
The above copyright notice and this permission notice shall be
|
12
|
+
included in all copies or substantial portions of the Software.
|
13
|
+
|
14
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
15
|
+
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
16
|
+
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
17
|
+
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
|
18
|
+
LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
|
19
|
+
OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
20
|
+
WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
data/README.md
ADDED
data/README.rdoc
ADDED
@@ -0,0 +1,19 @@
|
|
1
|
+
= digest-email
|
2
|
+
|
3
|
+
Description goes here.
|
4
|
+
|
5
|
+
== Contributing to digest-email
|
6
|
+
|
7
|
+
* Check out the latest master to make sure the feature hasn't been implemented or the bug hasn't been fixed yet.
|
8
|
+
* Check out the issue tracker to make sure someone already hasn't requested it and/or contributed it.
|
9
|
+
* Fork the project.
|
10
|
+
* Start a feature/bugfix branch.
|
11
|
+
* Commit and push until you are happy with your contribution.
|
12
|
+
* Make sure to add tests for it. This is important so I don't break it in a future version unintentionally.
|
13
|
+
* Please try not to mess with the Rakefile, version, or history. If you want to have your own version, or is otherwise necessary, that is fine, but please isolate to its own commit so I can cherry-pick around it.
|
14
|
+
|
15
|
+
== Copyright
|
16
|
+
|
17
|
+
Copyright (c) 2012 Naveed Ahmad. See LICENSE.txt for
|
18
|
+
further details.
|
19
|
+
|
data/Rakefile
ADDED
@@ -0,0 +1,53 @@
|
|
1
|
+
# encoding: utf-8
|
2
|
+
|
3
|
+
require 'rubygems'
|
4
|
+
require 'bundler'
|
5
|
+
begin
|
6
|
+
Bundler.setup(:default, :development)
|
7
|
+
rescue Bundler::BundlerError => e
|
8
|
+
$stderr.puts e.message
|
9
|
+
$stderr.puts "Run `bundle install` to install missing gems"
|
10
|
+
exit e.status_code
|
11
|
+
end
|
12
|
+
require 'rake'
|
13
|
+
|
14
|
+
require 'jeweler'
|
15
|
+
Jeweler::Tasks.new do |gem|
|
16
|
+
# gem is a Gem::Specification... see http://docs.rubygems.org/read/chapter/20 for more options
|
17
|
+
gem.name = "digest_notifier"
|
18
|
+
gem.homepage = "http://github.com/naveed-ahmad/digest_notifier"
|
19
|
+
gem.license = "MIT"
|
20
|
+
gem.summary = %Q{Send notifications to user via one digest email.}
|
21
|
+
gem.description = %Q{pending}
|
22
|
+
gem.email = "naveedahmada036@gmail.com"
|
23
|
+
gem.authors = ["Naveed Ahmad"]
|
24
|
+
# dependencies defined in Gemfile
|
25
|
+
end
|
26
|
+
Jeweler::RubygemsDotOrgTasks.new
|
27
|
+
|
28
|
+
require 'rake/testtask'
|
29
|
+
Rake::TestTask.new(:test) do |test|
|
30
|
+
test.libs << 'lib' << 'test'
|
31
|
+
test.pattern = 'test/**/test_*.rb'
|
32
|
+
test.verbose = true
|
33
|
+
end
|
34
|
+
|
35
|
+
require 'rcov/rcovtask'
|
36
|
+
Rcov::RcovTask.new do |test|
|
37
|
+
test.libs << 'test'
|
38
|
+
test.pattern = 'test/**/test_*.rb'
|
39
|
+
test.verbose = true
|
40
|
+
test.rcov_opts << '--exclude "gems/*"'
|
41
|
+
end
|
42
|
+
|
43
|
+
task :default => :test
|
44
|
+
|
45
|
+
require 'rdoc/task'
|
46
|
+
Rake::RDocTask.new do |rdoc|
|
47
|
+
version = File.exist?('VERSION') ? File.read('VERSION') : ""
|
48
|
+
|
49
|
+
rdoc.rdoc_dir = 'rdoc'
|
50
|
+
rdoc.title = "digest_notifier #{version}"
|
51
|
+
rdoc.rdoc_files.include('README*')
|
52
|
+
rdoc.rdoc_files.include('lib/**/*.rb')
|
53
|
+
end
|
data/VERSION
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
0.0.6
|
@@ -0,0 +1,80 @@
|
|
1
|
+
# Generated by jeweler
|
2
|
+
# DO NOT EDIT THIS FILE DIRECTLY
|
3
|
+
# Instead, edit Jeweler::Tasks in Rakefile, and run 'rake gemspec'
|
4
|
+
# -*- encoding: utf-8 -*-
|
5
|
+
|
6
|
+
Gem::Specification.new do |s|
|
7
|
+
s.name = %q{digest_notifier}
|
8
|
+
s.version = "0.0.6"
|
9
|
+
|
10
|
+
s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
|
11
|
+
s.authors = [%q{Naveed Ahmad}]
|
12
|
+
s.date = %q{2013-01-04}
|
13
|
+
s.description = %q{pending}
|
14
|
+
s.email = %q{naveedahmada036@gmail.com}
|
15
|
+
s.extra_rdoc_files = [
|
16
|
+
"LICENSE.txt",
|
17
|
+
"README.md",
|
18
|
+
"README.rdoc"
|
19
|
+
]
|
20
|
+
s.files = [
|
21
|
+
".document",
|
22
|
+
"Gemfile",
|
23
|
+
"Gemfile.lock",
|
24
|
+
"LICENSE.txt",
|
25
|
+
"README.md",
|
26
|
+
"README.rdoc",
|
27
|
+
"Rakefile",
|
28
|
+
"VERSION",
|
29
|
+
"digest_notifier.gemspec",
|
30
|
+
"lib/app/mailer/digest_mailer.rb",
|
31
|
+
"lib/app/models/digest_email_delivery.rb",
|
32
|
+
"lib/app/models/digest_email_group.rb",
|
33
|
+
"lib/app/models/digest_email_item.rb",
|
34
|
+
"lib/app/views/digest_notifier/digest_mailer/digest_notification.slim",
|
35
|
+
"lib/digest_notifier.rb",
|
36
|
+
"lib/digest_notifier/message_sending.rb",
|
37
|
+
"lib/digest_notifier/performable_digest.rb",
|
38
|
+
"lib/digest_notifier/railtie.rb",
|
39
|
+
"lib/digest_notifier/tasks.rb",
|
40
|
+
"lib/generators/digest_notifier/install_generator.rb",
|
41
|
+
"lib/generators/digest_notifier/templates/README",
|
42
|
+
"lib/generators/digest_notifier/templates/create_digest_email_deliveries.rb",
|
43
|
+
"lib/generators/digest_notifier/templates/create_digest_email_groups.rb",
|
44
|
+
"lib/generators/digest_notifier/templates/create_digest_email_items.rb",
|
45
|
+
"lib/generators/digest_notifier/templates/digest_notifier_config.rb"
|
46
|
+
]
|
47
|
+
s.homepage = %q{http://github.com/naveed-ahmad/digest_notifier}
|
48
|
+
s.licenses = [%q{MIT}]
|
49
|
+
s.require_paths = [%q{lib}]
|
50
|
+
s.rubygems_version = %q{1.8.6}
|
51
|
+
s.summary = %q{Send notifications to user via one digest email.}
|
52
|
+
|
53
|
+
if s.respond_to? :specification_version then
|
54
|
+
s.specification_version = 3
|
55
|
+
|
56
|
+
if Gem::Version.new(Gem::VERSION) >= Gem::Version.new('1.2.0') then
|
57
|
+
s.add_runtime_dependency(%q<slim>, [">= 1.0.4"])
|
58
|
+
s.add_development_dependency(%q<shoulda>, [">= 0"])
|
59
|
+
s.add_development_dependency(%q<rdoc>, ["~> 3.12"])
|
60
|
+
s.add_development_dependency(%q<bundler>, [">= 1.0.0"])
|
61
|
+
s.add_development_dependency(%q<jeweler>, ["~> 1.8.4"])
|
62
|
+
s.add_development_dependency(%q<rcov>, [">= 0"])
|
63
|
+
else
|
64
|
+
s.add_dependency(%q<slim>, [">= 1.0.4"])
|
65
|
+
s.add_dependency(%q<shoulda>, [">= 0"])
|
66
|
+
s.add_dependency(%q<rdoc>, ["~> 3.12"])
|
67
|
+
s.add_dependency(%q<bundler>, [">= 1.0.0"])
|
68
|
+
s.add_dependency(%q<jeweler>, ["~> 1.8.4"])
|
69
|
+
s.add_dependency(%q<rcov>, [">= 0"])
|
70
|
+
end
|
71
|
+
else
|
72
|
+
s.add_dependency(%q<slim>, [">= 1.0.4"])
|
73
|
+
s.add_dependency(%q<shoulda>, [">= 0"])
|
74
|
+
s.add_dependency(%q<rdoc>, ["~> 3.12"])
|
75
|
+
s.add_dependency(%q<bundler>, [">= 1.0.0"])
|
76
|
+
s.add_dependency(%q<jeweler>, ["~> 1.8.4"])
|
77
|
+
s.add_dependency(%q<rcov>, [">= 0"])
|
78
|
+
end
|
79
|
+
end
|
80
|
+
|
@@ -0,0 +1,29 @@
|
|
1
|
+
module DigestNotifier
|
2
|
+
class DigestMailer < ActionMailer::Base
|
3
|
+
default :from => DigestNotifier.mailer_sender
|
4
|
+
|
5
|
+
def digest_notification(receiver_email, digest_items)
|
6
|
+
@digest_items = digest_items
|
7
|
+
@digest_groups = @digest_items.group(:digest_email_group_id).map &:digest_email_group
|
8
|
+
|
9
|
+
mail :to => receiver_email, :subject => digest_email_subject, :from => DigestNotifier.mailer_sender
|
10
|
+
end
|
11
|
+
|
12
|
+
# Used to send digest email for a single digest_group
|
13
|
+
def digest_group_notification(receiver_email, digest_group)
|
14
|
+
@digest_items = DigestEmailItem.joins(:digest_email_deliveries).where("digest_email_deliveries.receiver_email = ?", receiver_email).group(:digest_email_group_id)
|
15
|
+
end
|
16
|
+
|
17
|
+
protected
|
18
|
+
#TODO: need to refactor it!
|
19
|
+
# Get subject of a digest email
|
20
|
+
def digest_email_subject(digest_group = nil)
|
21
|
+
if digest_group
|
22
|
+
translate_path = "digest_notifier.#{digest_group.i18n_name_space}.email_subjsct"
|
23
|
+
"#{DigestNotifier.app_name} #{I18n::t(translate_path, :default => 'todays updates')}"
|
24
|
+
else
|
25
|
+
"#{DigestNotifier.app_name} #{I18n::t('digest_notifier.email_subject', :default => 'todays updates')}"
|
26
|
+
end
|
27
|
+
end
|
28
|
+
end
|
29
|
+
end
|
@@ -0,0 +1,47 @@
|
|
1
|
+
class DigestEmailGroup < ActiveRecord::Base
|
2
|
+
has_many :digest_email_items, :dependent => :destroy
|
3
|
+
|
4
|
+
scope :with_pending_emails, joins(:digest_email_items)
|
5
|
+
|
6
|
+
def email_header
|
7
|
+
I18n::t("digest_notifier.#{i18n_name_space}.header", :default => description)
|
8
|
+
end
|
9
|
+
|
10
|
+
def i18n_name_space
|
11
|
+
"#{mailer_name}.#{method_name}"
|
12
|
+
end
|
13
|
+
|
14
|
+
def mailer_name
|
15
|
+
mailer_class.to_s.split('::').last.underscore
|
16
|
+
end
|
17
|
+
|
18
|
+
def digest_recipients
|
19
|
+
I18n::t("digest_notifier.#{i18n_name_space}.recipient", :default => recipients).to_s.split(',')
|
20
|
+
end
|
21
|
+
|
22
|
+
def create_digest_items(performable)
|
23
|
+
digest_item = digest_email_items.build :payload => performable.payload
|
24
|
+
digest_recipients.each do |recipient|
|
25
|
+
digest_item.digest_email_deliveries.build :receiver_email => recipient.gsub(' ', '')
|
26
|
+
end
|
27
|
+
|
28
|
+
digest_item.save
|
29
|
+
end
|
30
|
+
|
31
|
+
class << self
|
32
|
+
def enqueue(performable)
|
33
|
+
digest_group = init_digest_group(performable)
|
34
|
+
digest_group.create_digest_items(performable)
|
35
|
+
end
|
36
|
+
|
37
|
+
def init_digest_group(performable)
|
38
|
+
group = DigestEmailGroup.find_or_initialize_by_method_name_and_mailer_class performable.method_name, performable.mailer
|
39
|
+
if group.new_record?
|
40
|
+
group.recipients = performable.options[:send_to]
|
41
|
+
group.save
|
42
|
+
end
|
43
|
+
|
44
|
+
group
|
45
|
+
end
|
46
|
+
end
|
47
|
+
end
|
@@ -0,0 +1,16 @@
|
|
1
|
+
class DigestEmailItem < ActiveRecord::Base
|
2
|
+
serialize :payload, Array
|
3
|
+
|
4
|
+
belongs_to :digest_email_group
|
5
|
+
has_many :digest_email_deliveries, :dependent => :destroy
|
6
|
+
|
7
|
+
class << self
|
8
|
+
def with_group(group)
|
9
|
+
where :digest_email_group_id => group.id
|
10
|
+
end
|
11
|
+
|
12
|
+
def pending_digest_items_for(receiver_email)
|
13
|
+
DigestEmailItem.joins(:digest_email_deliveries).where("digest_email_deliveries.sent_at IS NULL AND digest_email_deliveries.receiver_email = ?", receiver_email)
|
14
|
+
end
|
15
|
+
end
|
16
|
+
end
|
@@ -0,0 +1 @@
|
|
1
|
+
h2 hello there
|
@@ -0,0 +1,21 @@
|
|
1
|
+
Gem.find_files("app/models/digest_email_*.rb").each {|file| require file }
|
2
|
+
require 'digest_notifier/performable_digest'
|
3
|
+
|
4
|
+
module DigestNotifier
|
5
|
+
class DigestProxy < ActiveSupport::BasicObject
|
6
|
+
def initialize(target, options)
|
7
|
+
@target = target
|
8
|
+
@options = options
|
9
|
+
end
|
10
|
+
|
11
|
+
def method_missing(method, *args)
|
12
|
+
DigestEmailGroup.enqueue PerformableDigest.new(@target, method.to_sym, args, @options)
|
13
|
+
end
|
14
|
+
end
|
15
|
+
|
16
|
+
module MessageSending
|
17
|
+
def digest(options = {})
|
18
|
+
DigestProxy.new(self, options)
|
19
|
+
end
|
20
|
+
end
|
21
|
+
end
|
@@ -0,0 +1,20 @@
|
|
1
|
+
module DigestNotifier
|
2
|
+
class PerformableDigest
|
3
|
+
attr_accessor :mailer, :method_name, :args, :options, :digest_group
|
4
|
+
|
5
|
+
delegate :method, :to => :object
|
6
|
+
|
7
|
+
def initialize(mailer, method_name, method_args, options)
|
8
|
+
#raise NoMethodError, "undefined method `#{method_name}' for #{mailer.inspect}" unless mailer.respond_to?(method_name, true)
|
9
|
+
|
10
|
+
self.mailer = mailer.to_s
|
11
|
+
self.args = method_args
|
12
|
+
self.method_name = method_name.to_sym
|
13
|
+
self.options = options
|
14
|
+
end
|
15
|
+
|
16
|
+
def payload
|
17
|
+
args
|
18
|
+
end
|
19
|
+
end
|
20
|
+
end
|
@@ -0,0 +1,25 @@
|
|
1
|
+
require 'digest_notifier'
|
2
|
+
require 'app/mailer/digest_mailer'
|
3
|
+
|
4
|
+
namespace :digest_notifier do
|
5
|
+
desc "Send notification in one big digest email"
|
6
|
+
task :send_notification_digest => :environment do
|
7
|
+
receivers = DigestEmailDelivery.where(:sent_at => nil).group(:receiver_email).map &:receiver_email
|
8
|
+
|
9
|
+
receivers.each do |receiver|
|
10
|
+
digest_items = DigestEmailItem.pending_digest_items_for(receiver)
|
11
|
+
DigestNotifier::DigestMailer.digest_notification(receiver, digest_items).deliver
|
12
|
+
end
|
13
|
+
|
14
|
+
receivers.each do |receiver|
|
15
|
+
digest_items = DigestEmailItem.pending_digest_items_for(receiver)
|
16
|
+
if DigestNotifier.delete_digest_after_sending
|
17
|
+
digest_items.destroy_all
|
18
|
+
else
|
19
|
+
digest_items.each do |item|
|
20
|
+
item.digest_email_deliveries.update_all :sent_at => DateTime.now
|
21
|
+
end
|
22
|
+
end
|
23
|
+
end
|
24
|
+
end
|
25
|
+
end
|
@@ -0,0 +1,43 @@
|
|
1
|
+
require 'digest_notifier/message_sending'
|
2
|
+
|
3
|
+
module DigestNotifier
|
4
|
+
# Digest email sender
|
5
|
+
#
|
6
|
+
mattr_accessor :mailer_sender
|
7
|
+
|
8
|
+
#Delete digest enteries after sending email
|
9
|
+
#false by default
|
10
|
+
mattr_accessor :delete_digest_after_sending
|
11
|
+
@@delete_digest_after_sending = false
|
12
|
+
|
13
|
+
#Track count of email send per group
|
14
|
+
#true by default
|
15
|
+
mattr_accessor :track_email_count
|
16
|
+
@@track_email_count = true
|
17
|
+
|
18
|
+
#Send one digest per group, if set to false all email would be send in one Digest.
|
19
|
+
#false by default
|
20
|
+
mattr_accessor :digest_per_group
|
21
|
+
@@digest_per_group = false
|
22
|
+
|
23
|
+
#Name of your awesome application. this would be used in email subject
|
24
|
+
mattr_accessor :app_name
|
25
|
+
|
26
|
+
class << self
|
27
|
+
def configure
|
28
|
+
yield self
|
29
|
+
end
|
30
|
+
|
31
|
+
def app_name
|
32
|
+
@app_name ||= Rails.application.class.parent.to_s
|
33
|
+
end
|
34
|
+
end
|
35
|
+
|
36
|
+
ActionMailer::Base.class_eval do
|
37
|
+
extend DigestNotifier::MessageSending
|
38
|
+
end
|
39
|
+
end
|
40
|
+
|
41
|
+
require 'app/mailer/digest_mailer'
|
42
|
+
require 'digest_notifier/railtie' if defined?(Rails::Railtie)
|
43
|
+
|
@@ -0,0 +1,48 @@
|
|
1
|
+
module DigestNotifier
|
2
|
+
module Generators
|
3
|
+
class InstallGenerator < Rails::Generators::Base
|
4
|
+
include Rails::Generators::Migration
|
5
|
+
|
6
|
+
source_root File.expand_path("../templates", __FILE__)
|
7
|
+
class_option :m, :type => :boolean, :default => false, :description => "Place DigestEmail's model to models folder"
|
8
|
+
|
9
|
+
desc "copy migrations, models and configuration files of digest_email to your application."
|
10
|
+
|
11
|
+
def self.next_migration_number(dirname)
|
12
|
+
if ActiveRecord::Base.timestamped_migrations
|
13
|
+
unless @prev_migration_nr
|
14
|
+
@prev_migration_nr = Time.now.utc.strftime("%Y%m%d%H%M%S").to_i
|
15
|
+
else
|
16
|
+
@prev_migration_nr += 1
|
17
|
+
end
|
18
|
+
@prev_migration_nr.to_s
|
19
|
+
else
|
20
|
+
(current_migration_number(dirname) + 1)
|
21
|
+
end
|
22
|
+
end
|
23
|
+
|
24
|
+
def copy_model
|
25
|
+
if options.m?
|
26
|
+
Gem.find_files("digest_notifier/models/*.rb").each do |file|
|
27
|
+
model_name = file.slpit("/").last
|
28
|
+
template file, File.join("app", "models", model_name)
|
29
|
+
end
|
30
|
+
end
|
31
|
+
end
|
32
|
+
|
33
|
+
def copy_configuration
|
34
|
+
template "digest_notifier_config.rb", File.join("config", "initializers", "digest_notifier.rb")
|
35
|
+
end
|
36
|
+
|
37
|
+
def copy_migration
|
38
|
+
migration_template "create_digest_email_groups.rb", File.join("db", "migrate", "create_digest_email_groups.rb")
|
39
|
+
migration_template "create_digest_email_items.rb", File.join("db", "migrate", "create_digest_email_items.rb")
|
40
|
+
migration_template "create_digest_email_deliveries.rb", File.join("db", "migrate", "create_digest_email_deliveries.rb")
|
41
|
+
end
|
42
|
+
|
43
|
+
def show
|
44
|
+
readme "README"
|
45
|
+
end
|
46
|
+
end
|
47
|
+
end
|
48
|
+
end
|
@@ -0,0 +1 @@
|
|
1
|
+
DigestEmail is installed successfully.
|
@@ -0,0 +1,24 @@
|
|
1
|
+
class CreateDigestEmailDeliveries < ActiveRecord::Migration
|
2
|
+
def self.up
|
3
|
+
create_table :digest_email_deliveries do |t|
|
4
|
+
t.integer :digest_email_item_id
|
5
|
+
t.integer :receiver_id
|
6
|
+
t.string :receiver_email
|
7
|
+
t.datetime :sent_at
|
8
|
+
|
9
|
+
t.timestamps
|
10
|
+
end
|
11
|
+
|
12
|
+
add_index :digest_email_deliveries, :digest_email_item_id
|
13
|
+
add_index :digest_email_deliveries, :receiver_id
|
14
|
+
add_index :digest_email_deliveries, :sent_at
|
15
|
+
end
|
16
|
+
|
17
|
+
def self.down
|
18
|
+
remove_index :digest_email_deliveries, :digest_email_item_id
|
19
|
+
remove_index :digest_email_deliveries, :receiver_id
|
20
|
+
remove_index :digest_email_deliveries, :sent_at
|
21
|
+
|
22
|
+
drop_table :digest_email_deliveries
|
23
|
+
end
|
24
|
+
end
|
@@ -0,0 +1,22 @@
|
|
1
|
+
class CreateDigestEmailGroups < ActiveRecord::Migration
|
2
|
+
def self.up
|
3
|
+
create_table :digest_email_groups do |t|
|
4
|
+
t.string :method_name
|
5
|
+
t.string :mailer_class
|
6
|
+
t.integer :sent_email_count , :default => 0
|
7
|
+
t.integer :pending_email_count, :default => 0
|
8
|
+
t.datetime :last_run_at
|
9
|
+
t.string :recipients
|
10
|
+
t.string :description
|
11
|
+
|
12
|
+
t.timestamps
|
13
|
+
end
|
14
|
+
|
15
|
+
add_index :digest_email_groups, [:mailer_class, :method_name]
|
16
|
+
end
|
17
|
+
|
18
|
+
def self.down
|
19
|
+
remove_index :digest_email_groups, [:mailer_class, :method_name]
|
20
|
+
drop_table :digest_email_groups
|
21
|
+
end
|
22
|
+
end
|
@@ -0,0 +1,14 @@
|
|
1
|
+
class CreateDigestEmailItems < ActiveRecord::Migration
|
2
|
+
def self.up
|
3
|
+
create_table :digest_email_items do |t|
|
4
|
+
t.integer :digest_email_group_id
|
5
|
+
t.text :payload
|
6
|
+
|
7
|
+
t.timestamps
|
8
|
+
end
|
9
|
+
end
|
10
|
+
|
11
|
+
def self.down
|
12
|
+
drop_table :digest_email_items
|
13
|
+
end
|
14
|
+
end
|
@@ -0,0 +1,19 @@
|
|
1
|
+
require 'digest_notifier'
|
2
|
+
|
3
|
+
DigestNotifier.configure do |config|
|
4
|
+
# Configure the e-mail address which will be sender for DigestEmails
|
5
|
+
config.mailer_sender = "support@#{DigestNotifier.app_name.downcase}.com"
|
6
|
+
#Delete digest enteries after sending email
|
7
|
+
#false by default
|
8
|
+
#config.delete_digest_after_sending = false
|
9
|
+
|
10
|
+
|
11
|
+
#Track count of total sent email per group
|
12
|
+
#true by default
|
13
|
+
#config.track_email_count = true
|
14
|
+
|
15
|
+
|
16
|
+
#Send one digest per group, if set to false all email would be send in one Digest.
|
17
|
+
#false by default
|
18
|
+
#config.digest_per_group = false
|
19
|
+
end
|
metadata
ADDED
@@ -0,0 +1,181 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: digest_notifier
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
hash: 19
|
5
|
+
prerelease:
|
6
|
+
segments:
|
7
|
+
- 0
|
8
|
+
- 0
|
9
|
+
- 6
|
10
|
+
version: 0.0.6
|
11
|
+
platform: ruby
|
12
|
+
authors:
|
13
|
+
- Naveed Ahmad
|
14
|
+
autorequire:
|
15
|
+
bindir: bin
|
16
|
+
cert_chain: []
|
17
|
+
|
18
|
+
date: 2013-01-04 00:00:00 Z
|
19
|
+
dependencies:
|
20
|
+
- !ruby/object:Gem::Dependency
|
21
|
+
name: slim
|
22
|
+
version_requirements: &id001 !ruby/object:Gem::Requirement
|
23
|
+
none: false
|
24
|
+
requirements:
|
25
|
+
- - ">="
|
26
|
+
- !ruby/object:Gem::Version
|
27
|
+
hash: 31
|
28
|
+
segments:
|
29
|
+
- 1
|
30
|
+
- 0
|
31
|
+
- 4
|
32
|
+
version: 1.0.4
|
33
|
+
prerelease: false
|
34
|
+
requirement: *id001
|
35
|
+
type: :runtime
|
36
|
+
- !ruby/object:Gem::Dependency
|
37
|
+
name: shoulda
|
38
|
+
version_requirements: &id002 !ruby/object:Gem::Requirement
|
39
|
+
none: false
|
40
|
+
requirements:
|
41
|
+
- - ">="
|
42
|
+
- !ruby/object:Gem::Version
|
43
|
+
hash: 3
|
44
|
+
segments:
|
45
|
+
- 0
|
46
|
+
version: "0"
|
47
|
+
prerelease: false
|
48
|
+
requirement: *id002
|
49
|
+
type: :development
|
50
|
+
- !ruby/object:Gem::Dependency
|
51
|
+
name: rdoc
|
52
|
+
version_requirements: &id003 !ruby/object:Gem::Requirement
|
53
|
+
none: false
|
54
|
+
requirements:
|
55
|
+
- - ~>
|
56
|
+
- !ruby/object:Gem::Version
|
57
|
+
hash: 31
|
58
|
+
segments:
|
59
|
+
- 3
|
60
|
+
- 12
|
61
|
+
version: "3.12"
|
62
|
+
prerelease: false
|
63
|
+
requirement: *id003
|
64
|
+
type: :development
|
65
|
+
- !ruby/object:Gem::Dependency
|
66
|
+
name: bundler
|
67
|
+
version_requirements: &id004 !ruby/object:Gem::Requirement
|
68
|
+
none: false
|
69
|
+
requirements:
|
70
|
+
- - ">="
|
71
|
+
- !ruby/object:Gem::Version
|
72
|
+
hash: 23
|
73
|
+
segments:
|
74
|
+
- 1
|
75
|
+
- 0
|
76
|
+
- 0
|
77
|
+
version: 1.0.0
|
78
|
+
prerelease: false
|
79
|
+
requirement: *id004
|
80
|
+
type: :development
|
81
|
+
- !ruby/object:Gem::Dependency
|
82
|
+
name: jeweler
|
83
|
+
version_requirements: &id005 !ruby/object:Gem::Requirement
|
84
|
+
none: false
|
85
|
+
requirements:
|
86
|
+
- - ~>
|
87
|
+
- !ruby/object:Gem::Version
|
88
|
+
hash: 63
|
89
|
+
segments:
|
90
|
+
- 1
|
91
|
+
- 8
|
92
|
+
- 4
|
93
|
+
version: 1.8.4
|
94
|
+
prerelease: false
|
95
|
+
requirement: *id005
|
96
|
+
type: :development
|
97
|
+
- !ruby/object:Gem::Dependency
|
98
|
+
name: rcov
|
99
|
+
version_requirements: &id006 !ruby/object:Gem::Requirement
|
100
|
+
none: false
|
101
|
+
requirements:
|
102
|
+
- - ">="
|
103
|
+
- !ruby/object:Gem::Version
|
104
|
+
hash: 3
|
105
|
+
segments:
|
106
|
+
- 0
|
107
|
+
version: "0"
|
108
|
+
prerelease: false
|
109
|
+
requirement: *id006
|
110
|
+
type: :development
|
111
|
+
description: pending
|
112
|
+
email: naveedahmada036@gmail.com
|
113
|
+
executables: []
|
114
|
+
|
115
|
+
extensions: []
|
116
|
+
|
117
|
+
extra_rdoc_files:
|
118
|
+
- LICENSE.txt
|
119
|
+
- README.md
|
120
|
+
- README.rdoc
|
121
|
+
files:
|
122
|
+
- .document
|
123
|
+
- Gemfile
|
124
|
+
- Gemfile.lock
|
125
|
+
- LICENSE.txt
|
126
|
+
- README.md
|
127
|
+
- README.rdoc
|
128
|
+
- Rakefile
|
129
|
+
- VERSION
|
130
|
+
- digest_notifier.gemspec
|
131
|
+
- lib/app/mailer/digest_mailer.rb
|
132
|
+
- lib/app/models/digest_email_delivery.rb
|
133
|
+
- lib/app/models/digest_email_group.rb
|
134
|
+
- lib/app/models/digest_email_item.rb
|
135
|
+
- lib/app/views/digest_notifier/digest_mailer/digest_notification.slim
|
136
|
+
- lib/digest_notifier.rb
|
137
|
+
- lib/digest_notifier/message_sending.rb
|
138
|
+
- lib/digest_notifier/performable_digest.rb
|
139
|
+
- lib/digest_notifier/railtie.rb
|
140
|
+
- lib/digest_notifier/tasks.rb
|
141
|
+
- lib/generators/digest_notifier/install_generator.rb
|
142
|
+
- lib/generators/digest_notifier/templates/README
|
143
|
+
- lib/generators/digest_notifier/templates/create_digest_email_deliveries.rb
|
144
|
+
- lib/generators/digest_notifier/templates/create_digest_email_groups.rb
|
145
|
+
- lib/generators/digest_notifier/templates/create_digest_email_items.rb
|
146
|
+
- lib/generators/digest_notifier/templates/digest_notifier_config.rb
|
147
|
+
homepage: http://github.com/naveed-ahmad/digest_notifier
|
148
|
+
licenses:
|
149
|
+
- MIT
|
150
|
+
post_install_message:
|
151
|
+
rdoc_options: []
|
152
|
+
|
153
|
+
require_paths:
|
154
|
+
- lib
|
155
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
156
|
+
none: false
|
157
|
+
requirements:
|
158
|
+
- - ">="
|
159
|
+
- !ruby/object:Gem::Version
|
160
|
+
hash: 3
|
161
|
+
segments:
|
162
|
+
- 0
|
163
|
+
version: "0"
|
164
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
165
|
+
none: false
|
166
|
+
requirements:
|
167
|
+
- - ">="
|
168
|
+
- !ruby/object:Gem::Version
|
169
|
+
hash: 3
|
170
|
+
segments:
|
171
|
+
- 0
|
172
|
+
version: "0"
|
173
|
+
requirements: []
|
174
|
+
|
175
|
+
rubyforge_project:
|
176
|
+
rubygems_version: 1.8.6
|
177
|
+
signing_key:
|
178
|
+
specification_version: 3
|
179
|
+
summary: Send notifications to user via one digest email.
|
180
|
+
test_files: []
|
181
|
+
|