digest-email 0.0.1

Sign up to get free protection for your applications and to get access to all the features.
data/.document ADDED
@@ -0,0 +1,5 @@
1
+ lib/**/*.rb
2
+ bin/*
3
+ -
4
+ features/**/*.feature
5
+ LICENSE.txt
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
+
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,35 @@
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
+
27
+ PLATFORMS
28
+ ruby
29
+
30
+ DEPENDENCIES
31
+ bundler (>= 1.0.0)
32
+ jeweler (~> 1.8.4)
33
+ rcov
34
+ rdoc (~> 3.12)
35
+ shoulda
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
@@ -0,0 +1,4 @@
1
+ digest-email
2
+ ============
3
+
4
+ A Ruby Gem for Sending Digest Email
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-email"
18
+ gem.homepage = "http://github.com/naveed-ahmad/digest-email"
19
+ gem.license = "MIT"
20
+ gem.summary = %Q{Send Digest email to your customer.}
21
+ gem.description = %Q{Send Digest email to your customer.}
22
+ gem.email = "naveed.ahmad@7vals.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-email #{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.1
@@ -0,0 +1,12 @@
1
+ class DigestEmailGroup < ActiveRecord::Base
2
+ has_many :digest_email_items
3
+
4
+ class << self
5
+ def enqueue(args = {})
6
+ performable = args.delete :performable
7
+ digest_group = performable.ensure_digest_group
8
+ digest_group.create_digest_email_item :payload => performable.payload, :object => performable.object
9
+ digest_group.save
10
+ end
11
+ end
12
+ end
@@ -0,0 +1,5 @@
1
+ class DigestEmailItem < ActiveRecord::Base
2
+ serialize :object
3
+ serialize :payload
4
+ belongs_to :digest_email_group
5
+ end
@@ -0,0 +1,76 @@
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-email}
8
+ s.version = "0.0.1"
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{2012-11-29}
13
+ s.description = %q{Send Digest email to your customer.}
14
+ s.email = %q{naveed.ahmad@7vals.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
+ "app/models/digest_email_group_model.rb",
30
+ "app/models/digest_email_item_model.rb",
31
+ "digest-email.gemspec",
32
+ "lib/digest_email.rb",
33
+ "lib/digest_email/backend.rb",
34
+ "lib/digest_email/message_sending.rb",
35
+ "lib/digest_email/performable_digest.rb",
36
+ "lib/generators/digest_email/templates/README",
37
+ "lib/generators/digest_email/templates/create_digest_email_groups.rb",
38
+ "lib/generators/digest_email/templates/create_digest_email_items.rb",
39
+ "lib/generators/digest_email/templates/digest_email_config.rb",
40
+ "lib/generators/digest_email/templates/digest_email_group_model.rb",
41
+ "lib/generators/digest_email/templates/digest_email_item_model.rb",
42
+ "lib/generators/digest_email/templates/install_generator.rb",
43
+ "test/helper.rb",
44
+ "test/test_digest-email.rb"
45
+ ]
46
+ s.homepage = %q{http://github.com/naveed-ahmad/digest-email}
47
+ s.licenses = [%q{MIT}]
48
+ s.require_paths = [%q{lib}]
49
+ s.rubygems_version = %q{1.8.6}
50
+ s.summary = %q{Send Digest email to your customer.}
51
+
52
+ if s.respond_to? :specification_version then
53
+ s.specification_version = 3
54
+
55
+ if Gem::Version.new(Gem::VERSION) >= Gem::Version.new('1.2.0') then
56
+ s.add_development_dependency(%q<shoulda>, [">= 0"])
57
+ s.add_development_dependency(%q<rdoc>, ["~> 3.12"])
58
+ s.add_development_dependency(%q<bundler>, [">= 1.0.0"])
59
+ s.add_development_dependency(%q<jeweler>, ["~> 1.8.4"])
60
+ s.add_development_dependency(%q<rcov>, [">= 0"])
61
+ else
62
+ s.add_dependency(%q<shoulda>, [">= 0"])
63
+ s.add_dependency(%q<rdoc>, ["~> 3.12"])
64
+ s.add_dependency(%q<bundler>, [">= 1.0.0"])
65
+ s.add_dependency(%q<jeweler>, ["~> 1.8.4"])
66
+ s.add_dependency(%q<rcov>, [">= 0"])
67
+ end
68
+ else
69
+ s.add_dependency(%q<shoulda>, [">= 0"])
70
+ s.add_dependency(%q<rdoc>, ["~> 3.12"])
71
+ s.add_dependency(%q<bundler>, [">= 1.0.0"])
72
+ s.add_dependency(%q<jeweler>, ["~> 1.8.4"])
73
+ s.add_dependency(%q<rcov>, [">= 0"])
74
+ end
75
+ end
76
+
@@ -0,0 +1,20 @@
1
+ require 'digest_email/message_sending'
2
+ require 'digest_email/backend'
3
+
4
+ module DigestEmail
5
+ mattr_accessor :delete_digest_after_sending
6
+ @@delete_digest_after_sending = true
7
+
8
+ mattr_accessor :track_email_count
9
+ @@track_email_count = true
10
+
11
+ class << self
12
+ def configure
13
+ yield self
14
+ end
15
+ end
16
+
17
+ ActionMailer::Base.class_eval do
18
+ extend DigestEmail::MessageSending
19
+ end
20
+ end
@@ -0,0 +1,15 @@
1
+ require 'active_record'
2
+
3
+ module Digest
4
+ module Backend
5
+ module ActiveRecord
6
+ class DigestEmail < ::ActiveRecord::Base
7
+ has_many :digest_email_items
8
+ end
9
+
10
+ class DigestEmailItem < ::ActiveRecord::Base
11
+
12
+ end
13
+ end
14
+ end
15
+ end
@@ -0,0 +1,18 @@
1
+ module DigestEmail
2
+ class DigestProxy < ActiveSupport::BasicObject
3
+ def initialize(target, options)
4
+ @target = target
5
+ @options = options
6
+ end
7
+
8
+ def method_missing(method, *args)
9
+ DigestEmailGroup.enqueue({:performable => PerformableDigest.new(@target, method.to_sym, args)}.merge(@options))
10
+ end
11
+ end
12
+
13
+ module MessageSending
14
+ def digest(options = {})
15
+ DigestProxy.new(self, options)
16
+ end
17
+ end
18
+ end
@@ -0,0 +1,31 @@
1
+ module DigestEmail
2
+ class PerformableDigest
3
+ attr_accessor :object, :method_name, :args
4
+
5
+ delegate :method, :to => :object
6
+
7
+ def initialize(object, method_name, args)
8
+ raise NoMethodError, "undefined method `#{method_name}' for #{object.inspect}" unless object.respond_to?(method_name, true)
9
+
10
+ if object.respond_to?(:new_record?) && object.new_record?
11
+ raise(ArgumentError, 'Digest cannot be created for records before they\'ve been persisted')
12
+ end
13
+
14
+ self.object = object
15
+ self.args = args
16
+ self.method_name = method_name.to_sym
17
+ end
18
+
19
+ def mailer_name
20
+ object.class.to_s
21
+ end
22
+
23
+ def mailer_name
24
+ args
25
+ end
26
+
27
+ def ensure_digest_group
28
+ DigestEmailGroup.find_or_create_by_mailer_name_and_method_name mailer_name, method_name
29
+ end
30
+ end
31
+ end
@@ -0,0 +1 @@
1
+ DigestEmail is installed successfully.
@@ -0,0 +1,20 @@
1
+ class CreateDigestEmailGroupss < ActiveRecord::Migration
2
+ def self.up
3
+ create_table :digest_email_groups do |t|
4
+ t.string :method_name
5
+ t.string :mailer_name
6
+ t.integer :sent_email_count , :default => 0
7
+ t.integer :pending_email_count, :default => 0
8
+ t.datetime :last_run_at
9
+
10
+ t.timestamps
11
+ end
12
+
13
+ add_index :digest_email_groups, [:mailer_name, :method_name]
14
+ end
15
+
16
+ def self.down
17
+ remove_index :digest_email_groups, [:mailer_name, :method_name]
18
+ drop_table :digest_email_groups
19
+ end
20
+ end
@@ -0,0 +1,17 @@
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
+ t.text :object
7
+ t.datetime :sent_at
8
+ t.string :send_to
9
+
10
+ t.timestamps
11
+ end
12
+ end
13
+
14
+ def self.down
15
+ drop_table :digest_email_items
16
+ end
17
+ end
@@ -0,0 +1,7 @@
1
+ DigestEmail.configure do |config|
2
+ # Delete digest email after sending. default is true
3
+ #config.delete_digest_after_sending = true
4
+
5
+ # Get track of how many email are sent for each type of digest. Default true
6
+ #config.track_email_count = true
7
+ end
@@ -0,0 +1,2 @@
1
+ class DigestEmailGroup < ActiveRecord::Base
2
+ end
@@ -0,0 +1,2 @@
1
+ class DigestEmailItem < ActiveRecord::Base
2
+ end
@@ -0,0 +1,34 @@
1
+ module DigestEmail
2
+ module Generators
3
+ class InstallGenerator < Rails::Generators::Base
4
+ source_root File.expand_path("../templates", __FILE__)
5
+ class_option :m, :type => :boolean, :default => false, :description => "Place DigestEmail's model to models folder"
6
+
7
+ desc "copy migrations,models and configuration files of digest_email to your application."
8
+
9
+ def self.next_migration_number(dirname)
10
+ Time.now.strftime("%Y%m%d%H%M%S")
11
+ end
12
+
13
+ def copy_model
14
+ if options.m?
15
+ template "digest_email_group_model.rb", File.join("app", "models", "digest_email_group.rb")
16
+ template "digest_email_item_model.rb", File.join("app", "models", "digest_email_item.rb")
17
+ end
18
+ end
19
+
20
+ def copy_configuration
21
+ template "config.rb", File.join("config", "initializers", "digest_email.rb")
22
+ end
23
+
24
+ def copy_migration
25
+ migration_template "create_digest_email_groups.rb", File.join("db", "migrate", "create_digest_email_groups.rb")
26
+ migration_template "create_digest_email_items.rb", File.join("db", "migrate", "create_digest_email_items.rb")
27
+ end
28
+
29
+ def show
30
+ readme "README"
31
+ end
32
+ end
33
+ end
34
+ end
data/test/helper.rb ADDED
@@ -0,0 +1,18 @@
1
+ require 'rubygems'
2
+ require 'bundler'
3
+ begin
4
+ Bundler.setup(:default, :development)
5
+ rescue Bundler::BundlerError => e
6
+ $stderr.puts e.message
7
+ $stderr.puts "Run `bundle install` to install missing gems"
8
+ exit e.status_code
9
+ end
10
+ require 'test/unit'
11
+ require 'shoulda'
12
+
13
+ $LOAD_PATH.unshift(File.join(File.dirname(__FILE__), '..', 'lib'))
14
+ $LOAD_PATH.unshift(File.dirname(__FILE__))
15
+ require 'digest-email'
16
+
17
+ class Test::Unit::TestCase
18
+ end
@@ -0,0 +1,7 @@
1
+ require 'helper'
2
+
3
+ class TestDigestEmail < Test::Unit::TestCase
4
+ should "probably rename this file and start testing for real" do
5
+ flunk "hey buddy, you should probably rename this file and start testing for real"
6
+ end
7
+ end
metadata ADDED
@@ -0,0 +1,164 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: digest-email
3
+ version: !ruby/object:Gem::Version
4
+ hash: 29
5
+ prerelease:
6
+ segments:
7
+ - 0
8
+ - 0
9
+ - 1
10
+ version: 0.0.1
11
+ platform: ruby
12
+ authors:
13
+ - Naveed Ahmad
14
+ autorequire:
15
+ bindir: bin
16
+ cert_chain: []
17
+
18
+ date: 2012-11-29 00:00:00 Z
19
+ dependencies:
20
+ - !ruby/object:Gem::Dependency
21
+ name: shoulda
22
+ version_requirements: &id001 !ruby/object:Gem::Requirement
23
+ none: false
24
+ requirements:
25
+ - - ">="
26
+ - !ruby/object:Gem::Version
27
+ hash: 3
28
+ segments:
29
+ - 0
30
+ version: "0"
31
+ prerelease: false
32
+ requirement: *id001
33
+ type: :development
34
+ - !ruby/object:Gem::Dependency
35
+ name: rdoc
36
+ version_requirements: &id002 !ruby/object:Gem::Requirement
37
+ none: false
38
+ requirements:
39
+ - - ~>
40
+ - !ruby/object:Gem::Version
41
+ hash: 31
42
+ segments:
43
+ - 3
44
+ - 12
45
+ version: "3.12"
46
+ prerelease: false
47
+ requirement: *id002
48
+ type: :development
49
+ - !ruby/object:Gem::Dependency
50
+ name: bundler
51
+ version_requirements: &id003 !ruby/object:Gem::Requirement
52
+ none: false
53
+ requirements:
54
+ - - ">="
55
+ - !ruby/object:Gem::Version
56
+ hash: 23
57
+ segments:
58
+ - 1
59
+ - 0
60
+ - 0
61
+ version: 1.0.0
62
+ prerelease: false
63
+ requirement: *id003
64
+ type: :development
65
+ - !ruby/object:Gem::Dependency
66
+ name: jeweler
67
+ version_requirements: &id004 !ruby/object:Gem::Requirement
68
+ none: false
69
+ requirements:
70
+ - - ~>
71
+ - !ruby/object:Gem::Version
72
+ hash: 63
73
+ segments:
74
+ - 1
75
+ - 8
76
+ - 4
77
+ version: 1.8.4
78
+ prerelease: false
79
+ requirement: *id004
80
+ type: :development
81
+ - !ruby/object:Gem::Dependency
82
+ name: rcov
83
+ version_requirements: &id005 !ruby/object:Gem::Requirement
84
+ none: false
85
+ requirements:
86
+ - - ">="
87
+ - !ruby/object:Gem::Version
88
+ hash: 3
89
+ segments:
90
+ - 0
91
+ version: "0"
92
+ prerelease: false
93
+ requirement: *id005
94
+ type: :development
95
+ description: Send Digest email to your customer.
96
+ email: naveed.ahmad@7vals.com
97
+ executables: []
98
+
99
+ extensions: []
100
+
101
+ extra_rdoc_files:
102
+ - LICENSE.txt
103
+ - README.md
104
+ - README.rdoc
105
+ files:
106
+ - .document
107
+ - Gemfile
108
+ - Gemfile.lock
109
+ - LICENSE.txt
110
+ - README.md
111
+ - README.rdoc
112
+ - Rakefile
113
+ - VERSION
114
+ - app/models/digest_email_group_model.rb
115
+ - app/models/digest_email_item_model.rb
116
+ - digest-email.gemspec
117
+ - lib/digest_email.rb
118
+ - lib/digest_email/backend.rb
119
+ - lib/digest_email/message_sending.rb
120
+ - lib/digest_email/performable_digest.rb
121
+ - lib/generators/digest_email/templates/README
122
+ - lib/generators/digest_email/templates/create_digest_email_groups.rb
123
+ - lib/generators/digest_email/templates/create_digest_email_items.rb
124
+ - lib/generators/digest_email/templates/digest_email_config.rb
125
+ - lib/generators/digest_email/templates/digest_email_group_model.rb
126
+ - lib/generators/digest_email/templates/digest_email_item_model.rb
127
+ - lib/generators/digest_email/templates/install_generator.rb
128
+ - test/helper.rb
129
+ - test/test_digest-email.rb
130
+ homepage: http://github.com/naveed-ahmad/digest-email
131
+ licenses:
132
+ - MIT
133
+ post_install_message:
134
+ rdoc_options: []
135
+
136
+ require_paths:
137
+ - lib
138
+ required_ruby_version: !ruby/object:Gem::Requirement
139
+ none: false
140
+ requirements:
141
+ - - ">="
142
+ - !ruby/object:Gem::Version
143
+ hash: 3
144
+ segments:
145
+ - 0
146
+ version: "0"
147
+ required_rubygems_version: !ruby/object:Gem::Requirement
148
+ none: false
149
+ requirements:
150
+ - - ">="
151
+ - !ruby/object:Gem::Version
152
+ hash: 3
153
+ segments:
154
+ - 0
155
+ version: "0"
156
+ requirements: []
157
+
158
+ rubyforge_project:
159
+ rubygems_version: 1.8.6
160
+ signing_key:
161
+ specification_version: 3
162
+ summary: Send Digest email to your customer.
163
+ test_files: []
164
+