dripper_mail 0.0.1

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.
Files changed (83) hide show
  1. checksums.yaml +7 -0
  2. data/MIT-LICENSE +20 -0
  3. data/Rakefile +37 -0
  4. data/app/assets/javascripts/dripper/application.js +13 -0
  5. data/app/assets/stylesheets/dripper/application.css +15 -0
  6. data/app/controllers/dripper/application_controller.rb +5 -0
  7. data/app/helpers/dripper/application_helper.rb +4 -0
  8. data/app/models/dripper/action.rb +6 -0
  9. data/app/models/dripper/message.rb +8 -0
  10. data/app/views/layouts/dripper/application.html.erb +14 -0
  11. data/config/routes.rb +2 -0
  12. data/db/migrate/20160331213900_create_dripper_messages.rb +17 -0
  13. data/lib/dripper.rb +108 -0
  14. data/lib/dripper/drippable.rb +16 -0
  15. data/lib/dripper/dripper_job.rb +11 -0
  16. data/lib/dripper/engine.rb +5 -0
  17. data/lib/dripper/version.rb +3 -0
  18. data/lib/tasks/dripper_tasks.rake +4 -0
  19. data/test/dripper_test.rb +7 -0
  20. data/test/dummy/README.rdoc +28 -0
  21. data/test/dummy/Rakefile +6 -0
  22. data/test/dummy/app/assets/javascripts/application.js +13 -0
  23. data/test/dummy/app/assets/stylesheets/application.css +15 -0
  24. data/test/dummy/app/controllers/application_controller.rb +5 -0
  25. data/test/dummy/app/helpers/application_helper.rb +2 -0
  26. data/test/dummy/app/mailers/application_mailer.rb +4 -0
  27. data/test/dummy/app/mailers/user_mailer.rb +57 -0
  28. data/test/dummy/app/models/newsletter.rb +4 -0
  29. data/test/dummy/app/models/user.rb +3 -0
  30. data/test/dummy/app/views/layouts/application.html.erb +14 -0
  31. data/test/dummy/app/views/layouts/mailer.html.erb +5 -0
  32. data/test/dummy/app/views/layouts/mailer.text.erb +1 -0
  33. data/test/dummy/app/views/user_mailer/day1.html.erb +5 -0
  34. data/test/dummy/app/views/user_mailer/day1.text.erb +3 -0
  35. data/test/dummy/app/views/user_mailer/day3.html.erb +5 -0
  36. data/test/dummy/app/views/user_mailer/day3.text.erb +3 -0
  37. data/test/dummy/app/views/user_mailer/day7.html.erb +5 -0
  38. data/test/dummy/app/views/user_mailer/day7.text.erb +3 -0
  39. data/test/dummy/app/views/user_mailer/newsletter.html.erb +5 -0
  40. data/test/dummy/app/views/user_mailer/newsletter.text.erb +3 -0
  41. data/test/dummy/app/views/user_mailer/welcome.html.erb +5 -0
  42. data/test/dummy/app/views/user_mailer/welcome.text.erb +3 -0
  43. data/test/dummy/bin/bundle +3 -0
  44. data/test/dummy/bin/rails +4 -0
  45. data/test/dummy/bin/rake +4 -0
  46. data/test/dummy/bin/setup +29 -0
  47. data/test/dummy/config.ru +4 -0
  48. data/test/dummy/config/application.rb +26 -0
  49. data/test/dummy/config/boot.rb +5 -0
  50. data/test/dummy/config/database.yml +25 -0
  51. data/test/dummy/config/environment.rb +6 -0
  52. data/test/dummy/config/environments/development.rb +41 -0
  53. data/test/dummy/config/environments/production.rb +79 -0
  54. data/test/dummy/config/environments/test.rb +42 -0
  55. data/test/dummy/config/initializers/assets.rb +11 -0
  56. data/test/dummy/config/initializers/backtrace_silencers.rb +7 -0
  57. data/test/dummy/config/initializers/cookies_serializer.rb +3 -0
  58. data/test/dummy/config/initializers/filter_parameter_logging.rb +4 -0
  59. data/test/dummy/config/initializers/inflections.rb +16 -0
  60. data/test/dummy/config/initializers/mime_types.rb +4 -0
  61. data/test/dummy/config/initializers/session_store.rb +3 -0
  62. data/test/dummy/config/initializers/wrap_parameters.rb +14 -0
  63. data/test/dummy/config/locales/en.yml +23 -0
  64. data/test/dummy/config/routes.rb +4 -0
  65. data/test/dummy/config/secrets.yml +22 -0
  66. data/test/dummy/db/development.sqlite3 +0 -0
  67. data/test/dummy/db/schema.rb +51 -0
  68. data/test/dummy/db/test.sqlite3 +0 -0
  69. data/test/dummy/log/RAILS_ENV=test.log +0 -0
  70. data/test/dummy/log/development.log +424 -0
  71. data/test/dummy/log/test.log +24512 -0
  72. data/test/dummy/public/404.html +67 -0
  73. data/test/dummy/public/422.html +67 -0
  74. data/test/dummy/public/500.html +66 -0
  75. data/test/dummy/public/favicon.ico +0 -0
  76. data/test/integration/navigation_test.rb +8 -0
  77. data/test/models/dripper/action_test.rb +9 -0
  78. data/test/models/dripper/concern_test.rb +40 -0
  79. data/test/models/dripper/dripper_action_test.rb +9 -0
  80. data/test/models/dripper/message_test.rb +55 -0
  81. data/test/models/dripper/run_twice_test.rb +52 -0
  82. data/test/test_helper.rb +22 -0
  83. metadata +219 -0
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: 9eb1b72d754f83cabfd1ad6258b15bccb05f12e1
4
+ data.tar.gz: 5d905d38a821dbe0e2e1514a9beba7ee8d1a6662
5
+ SHA512:
6
+ metadata.gz: deec8d17374ea0cb8b5016cdfe0450cdcfdaf3a0e78cd94647a41c4b5b7024c6853c2c626337e1a14898beefe2cec42704e51629de9780cf693d36b536406021
7
+ data.tar.gz: 64a3c80aa37cfd2930a74efe60616280b0720d4fea21eef31a8a2adb8ab83f3fcaf36c744ee397216736203bd40d7ab2a5fb5e51bd7ec37f0d9028094bbc4ec2
data/MIT-LICENSE ADDED
@@ -0,0 +1,20 @@
1
+ Copyright 2016 Douglas Tarr
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/Rakefile ADDED
@@ -0,0 +1,37 @@
1
+ begin
2
+ require 'bundler/setup'
3
+ rescue LoadError
4
+ puts 'You must `gem install bundler` and `bundle install` to run rake tasks'
5
+ end
6
+
7
+ require 'rdoc/task'
8
+
9
+ RDoc::Task.new(:rdoc) do |rdoc|
10
+ rdoc.rdoc_dir = 'rdoc'
11
+ rdoc.title = 'Dripper'
12
+ rdoc.options << '--line-numbers'
13
+ rdoc.rdoc_files.include('README.rdoc')
14
+ rdoc.rdoc_files.include('lib/**/*.rb')
15
+ end
16
+
17
+ APP_RAKEFILE = File.expand_path("../test/dummy/Rakefile", __FILE__)
18
+ load 'rails/tasks/engine.rake'
19
+
20
+
21
+ load 'rails/tasks/statistics.rake'
22
+
23
+
24
+
25
+ Bundler::GemHelper.install_tasks
26
+
27
+ require 'rake/testtask'
28
+
29
+ Rake::TestTask.new(:test) do |t|
30
+ t.libs << 'lib'
31
+ t.libs << 'test'
32
+ t.pattern = 'test/**/*_test.rb'
33
+ t.verbose = false
34
+ end
35
+
36
+
37
+ task default: :test
@@ -0,0 +1,13 @@
1
+ // This is a manifest file that'll be compiled into application.js, which will include all the files
2
+ // listed below.
3
+ //
4
+ // Any JavaScript/Coffee file within this directory, lib/assets/javascripts, vendor/assets/javascripts,
5
+ // or any plugin's vendor/assets/javascripts directory can be referenced here using a relative path.
6
+ //
7
+ // It's not advisable to add code directly here, but if you do, it'll appear at the bottom of the
8
+ // compiled file.
9
+ //
10
+ // Read Sprockets README (https://github.com/rails/sprockets#sprockets-directives) for details
11
+ // about supported directives.
12
+ //
13
+ //= require_tree .
@@ -0,0 +1,15 @@
1
+ /*
2
+ * This is a manifest file that'll be compiled into application.css, which will include all the files
3
+ * listed below.
4
+ *
5
+ * Any CSS and SCSS file within this directory, lib/assets/stylesheets, vendor/assets/stylesheets,
6
+ * or any plugin's vendor/assets/stylesheets directory can be referenced here using a relative path.
7
+ *
8
+ * You're free to add application-wide styles to this file and they'll appear at the bottom of the
9
+ * compiled file so the styles you add here take precedence over styles defined in any styles
10
+ * defined in the other CSS/SCSS files in this directory. It is generally better to create a new
11
+ * file per style scope.
12
+ *
13
+ *= require_tree .
14
+ *= require_self
15
+ */
@@ -0,0 +1,5 @@
1
+ module Dripper
2
+ class ApplicationController < ActionController::Base
3
+ protect_from_forgery with: :exception
4
+ end
5
+ end
@@ -0,0 +1,4 @@
1
+ module Dripper
2
+ module ApplicationHelper
3
+ end
4
+ end
@@ -0,0 +1,6 @@
1
+ module Dripper
2
+ class Action < ActiveRecord::Base
3
+ validates :action, presence: true
4
+ validates :mailer, presence: true
5
+ end
6
+ end
@@ -0,0 +1,8 @@
1
+ module Dripper
2
+ class Message < ActiveRecord::Base
3
+ validates :drippable, presence: true
4
+ belongs_to :drippable, polymorphic: true
5
+
6
+ belongs_to :action
7
+ end
8
+ end
@@ -0,0 +1,14 @@
1
+ <!DOCTYPE html>
2
+ <html>
3
+ <head>
4
+ <title>Dripper</title>
5
+ <%= stylesheet_link_tag "dripper/application", media: "all" %>
6
+ <%= javascript_include_tag "dripper/application" %>
7
+ <%= csrf_meta_tags %>
8
+ </head>
9
+ <body>
10
+
11
+ <%= yield %>
12
+
13
+ </body>
14
+ </html>
data/config/routes.rb ADDED
@@ -0,0 +1,2 @@
1
+ Dripper::Engine.routes.draw do
2
+ end
@@ -0,0 +1,17 @@
1
+ class CreateDripperMessages < ActiveRecord::Migration
2
+ def change
3
+ create_table :dripper_messages do |t|
4
+ t.references :drippable, polymorphic: true, index: true, null: false
5
+
6
+ t.timestamps null: false
7
+ end
8
+ create_table :dripper_actions do |t|
9
+ t.string :mailer, null: false
10
+ t.string :action, null: false
11
+
12
+ t.timestamps null: false
13
+ end
14
+
15
+ add_reference :dripper_messages, :dripper_action, index: true, foreign_key: true
16
+ end
17
+ end
data/lib/dripper.rb ADDED
@@ -0,0 +1,108 @@
1
+ require "dripper/engine"
2
+ require "dripper/drippable"
3
+ require "dripper/dripper_job"
4
+
5
+ module Dripper
6
+ @registry = []
7
+
8
+ def self.registry
9
+ @registry
10
+ end
11
+
12
+ def self.config(opts={}, &block)
13
+ DripperProxy.new(opts, &block)
14
+ @registry.each do |r|
15
+ r.register
16
+ end
17
+ end
18
+
19
+ def self.execute
20
+ @registry.each do |d|
21
+ d.execute
22
+ end
23
+ end
24
+
25
+ end
26
+
27
+ class DripperProxy
28
+ attr_accessor :model
29
+ attr_accessor :mailer
30
+ attr_accessor :action
31
+ attr_accessor :scope
32
+ attr_accessor :parent
33
+ attr_accessor :children
34
+
35
+ def initialize(opts={}, &block)
36
+ # if there's a parent, initialize all values to the parent values first
37
+ # then override with children
38
+ [:model, :mailer, :action].each do |method|
39
+ parent = opts[:parent]
40
+ if parent
41
+ instance_variable_set "@#{method}", parent.send(method)
42
+ end
43
+ end
44
+
45
+ #overwrite any defined options
46
+ opts.each { |k,v| instance_variable_set("@#{k}", v) }
47
+
48
+ # merge the parent scopes if they exist
49
+ if self.parent && self.parent.scope
50
+ if opts[:scope]
51
+ instance_variable_set "@scope", self.parent.scope.merge(opts[:scope])
52
+ else
53
+ instance_variable_ste "@scope", self.parent.scope
54
+ end
55
+ end
56
+
57
+
58
+ @children = []
59
+ instance_eval(&block) if block
60
+ # only include complete ones in the registry
61
+ if self.action && self.mailer && self.model
62
+ Dripper.registry << self
63
+ end
64
+ end
65
+
66
+ def dripper(opts={}, &block)
67
+ proxy = DripperProxy.new opts.merge(parent: self), &block
68
+ @children << proxy
69
+ end
70
+
71
+ def register
72
+ Dripper::Action.where(action: self.action.to_s, mailer: self.mailer.to_s).first_or_create
73
+ end
74
+
75
+ def execute(item = nil)
76
+ dripper_action = Dripper::Action.find_by(action: self.action.to_s, mailer: self.mailer.to_s)
77
+
78
+ all_recs = self.model.to_s.classify.constantize.send(:all)
79
+
80
+ # only send if we haven't already
81
+ already_sent = Dripper::Message
82
+ .where(drippable_type: self.model.to_s.classify.to_s, dripper_action_id: dripper_action.id)
83
+ .select(:drippable_id)
84
+
85
+ scoped_recs = all_recs
86
+ .merge(self.scope)
87
+ .where.not(id: already_sent)
88
+ .where("#{self.model.to_s.classify.constantize.table_name}.created_at >= ?", dripper_action.created_at.change(usec: 0))
89
+
90
+ if item
91
+ scoped_recs = scoped_recs.where(id: item.id)
92
+ end
93
+
94
+
95
+ scoped_recs.each do |obj|
96
+
97
+ # instantiate the mailer and run the code
98
+ mailer_obj = self.mailer.to_s.classify.constantize
99
+ mail_obj = mailer_obj.send self.action, obj
100
+ mail_obj.deliver_now
101
+
102
+ # insert a row
103
+ Dripper::Message.create!(dripper_action_id: dripper_action.id, drippable: obj)
104
+ end
105
+
106
+
107
+ end
108
+ end
@@ -0,0 +1,16 @@
1
+ # yaffle/lib/yaffle/acts_as_yaffle.rb
2
+ module Dripper
3
+ module Drippable
4
+ extend ActiveSupport::Concern
5
+
6
+ included do
7
+ after_create :execute_drippers
8
+
9
+ def execute_drippers
10
+ DripperJob.perform_later self
11
+ end
12
+ end
13
+
14
+ end
15
+ end
16
+
@@ -0,0 +1,11 @@
1
+ class DripperJob < ActiveJob::Base
2
+ queue_as :default
3
+
4
+ def perform(obj)
5
+ # find any drippers for this class and try to execute them
6
+ Dripper.registry.select{|r| r.model == obj.class.table_name.underscore.to_sym}.each do |r|
7
+ r.execute obj
8
+ end
9
+ end
10
+
11
+ end
@@ -0,0 +1,5 @@
1
+ module Dripper
2
+ class Engine < ::Rails::Engine
3
+ isolate_namespace Dripper
4
+ end
5
+ end
@@ -0,0 +1,3 @@
1
+ module Dripper
2
+ VERSION = "0.0.1"
3
+ end
@@ -0,0 +1,4 @@
1
+ # desc "Explaining what the task does"
2
+ # task :dripper do
3
+ # # Task goes here
4
+ # end
@@ -0,0 +1,7 @@
1
+ require 'test_helper'
2
+
3
+ class DripperTest < ActiveSupport::TestCase
4
+ test "truth" do
5
+ assert_kind_of Module, Dripper
6
+ end
7
+ end
@@ -0,0 +1,28 @@
1
+ == README
2
+
3
+ This README would normally document whatever steps are necessary to get the
4
+ application up and running.
5
+
6
+ Things you may want to cover:
7
+
8
+ * Ruby version
9
+
10
+ * System dependencies
11
+
12
+ * Configuration
13
+
14
+ * Database creation
15
+
16
+ * Database initialization
17
+
18
+ * How to run the test suite
19
+
20
+ * Services (job queues, cache servers, search engines, etc.)
21
+
22
+ * Deployment instructions
23
+
24
+ * ...
25
+
26
+
27
+ Please feel free to use a different markup language if you do not plan to run
28
+ <tt>rake doc:app</tt>.
@@ -0,0 +1,6 @@
1
+ # Add your own tasks in files placed in lib/tasks ending in .rake,
2
+ # for example lib/tasks/capistrano.rake, and they will automatically be available to Rake.
3
+
4
+ require File.expand_path('../config/application', __FILE__)
5
+
6
+ Rails.application.load_tasks
@@ -0,0 +1,13 @@
1
+ // This is a manifest file that'll be compiled into application.js, which will include all the files
2
+ // listed below.
3
+ //
4
+ // Any JavaScript/Coffee file within this directory, lib/assets/javascripts, vendor/assets/javascripts,
5
+ // or any plugin's vendor/assets/javascripts directory can be referenced here using a relative path.
6
+ //
7
+ // It's not advisable to add code directly here, but if you do, it'll appear at the bottom of the
8
+ // compiled file.
9
+ //
10
+ // Read Sprockets README (https://github.com/rails/sprockets#sprockets-directives) for details
11
+ // about supported directives.
12
+ //
13
+ //= require_tree .
@@ -0,0 +1,15 @@
1
+ /*
2
+ * This is a manifest file that'll be compiled into application.css, which will include all the files
3
+ * listed below.
4
+ *
5
+ * Any CSS and SCSS file within this directory, lib/assets/stylesheets, vendor/assets/stylesheets,
6
+ * or any plugin's vendor/assets/stylesheets directory can be referenced here using a relative path.
7
+ *
8
+ * You're free to add application-wide styles to this file and they'll appear at the bottom of the
9
+ * compiled file so the styles you add here take precedence over styles defined in any styles
10
+ * defined in the other CSS/SCSS files in this directory. It is generally better to create a new
11
+ * file per style scope.
12
+ *
13
+ *= require_tree .
14
+ *= require_self
15
+ */
@@ -0,0 +1,5 @@
1
+ class ApplicationController < ActionController::Base
2
+ # Prevent CSRF attacks by raising an exception.
3
+ # For APIs, you may want to use :null_session instead.
4
+ protect_from_forgery with: :exception
5
+ end
@@ -0,0 +1,2 @@
1
+ module ApplicationHelper
2
+ end
@@ -0,0 +1,4 @@
1
+ class ApplicationMailer < ActionMailer::Base
2
+ default from: "from@example.com"
3
+ layout 'mailer'
4
+ end
@@ -0,0 +1,57 @@
1
+ class UserMailer < ApplicationMailer
2
+
3
+ # Subject can be set in your I18n file at config/locales/en.yml
4
+ # with the following lookup:
5
+ #
6
+ # en.user_mailer.welcome.subject
7
+ #
8
+ def welcome(user)
9
+ @greeting = "Hi"
10
+
11
+ mail to: "to@example.org"
12
+ end
13
+
14
+ # Subject can be set in your I18n file at config/locales/en.yml
15
+ # with the following lookup:
16
+ #
17
+ # en.user_mailer.newsletter.subject
18
+ #
19
+ def newsletter(user)
20
+ @greeting = "Hi"
21
+
22
+ mail to: "to@example.org"
23
+ end
24
+
25
+ # Subject can be set in your I18n file at config/locales/en.yml
26
+ # with the following lookup:
27
+ #
28
+ # en.user_mailer.day1.subject
29
+ #
30
+ def day1(user)
31
+ @greeting = "Hi"
32
+
33
+ mail to: "to@example.org"
34
+ end
35
+
36
+ # Subject can be set in your I18n file at config/locales/en.yml
37
+ # with the following lookup:
38
+ #
39
+ # en.user_mailer.day3.subject
40
+ #
41
+ def day3(user)
42
+ @greeting = "Hi"
43
+
44
+ mail to: "to@example.org"
45
+ end
46
+
47
+ # Subject can be set in your I18n file at config/locales/en.yml
48
+ # with the following lookup:
49
+ #
50
+ # en.user_mailer.day7.subject
51
+ #
52
+ def day7(user)
53
+ @greeting = "Hi"
54
+
55
+ mail to: "to@example.org"
56
+ end
57
+ end