new_data_notifier 0.0.3 → 0.1.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.
- data/Gemfile +23 -0
- data/Gemfile.lock +109 -0
- data/MIT-LICENSE +20 -0
- data/README.mkd +26 -0
- data/Rakefile +53 -0
- data/VERSION +1 -0
- data/app/.DS_Store +0 -0
- data/app/mailers/new_data_notifier/notifier.rb +97 -0
- data/app/views/new_data_notifier/notifier/notification.text.erb +8 -0
- data/lib/.DS_Store +0 -0
- data/lib/new_data_notifier/engine.rb +11 -0
- data/lib/new_data_notifier/generators/create_config.rb +10 -0
- data/lib/new_data_notifier/generators/templates/new_data_notifier.rb +3 -0
- data/lib/new_data_notifier/tasks/notifier.rake +6 -0
- data/lib/new_data_notifier.rb +1 -68
- data/new_data_notifier.gemspec +130 -0
- data/test/dummy/Rakefile +7 -0
- data/test/dummy/app/controllers/application_controller.rb +3 -0
- data/test/dummy/app/helpers/application_helper.rb +2 -0
- data/test/dummy/app/models/user.rb +2 -0
- data/test/dummy/app/views/layouts/application.html.erb +14 -0
- data/test/dummy/config/application.rb +45 -0
- data/test/dummy/config/boot.rb +10 -0
- data/test/dummy/config/database.yml +22 -0
- data/test/dummy/config/environment.rb +5 -0
- data/test/dummy/config/environments/development.rb +26 -0
- data/test/dummy/config/environments/production.rb +49 -0
- data/test/dummy/config/environments/test.rb +35 -0
- data/test/dummy/config/initializers/backtrace_silencers.rb +7 -0
- data/test/dummy/config/initializers/inflections.rb +10 -0
- data/test/dummy/config/initializers/mime_types.rb +5 -0
- data/test/dummy/config/initializers/new_data_notifier.rb +3 -0
- data/test/dummy/config/initializers/secret_token.rb +7 -0
- data/test/dummy/config/initializers/session_store.rb +8 -0
- data/test/dummy/config/locales/en.yml +5 -0
- data/test/dummy/config/routes.rb +58 -0
- data/test/dummy/config.ru +4 -0
- data/test/dummy/db/migrate/20110317034437_create_users.rb +13 -0
- data/test/dummy/db/schema.rb +21 -0
- data/test/dummy/public/404.html +26 -0
- data/test/dummy/public/422.html +26 -0
- data/test/dummy/public/500.html +26 -0
- data/test/dummy/public/favicon.ico +0 -0
- data/test/dummy/public/javascripts/application.js +2 -0
- data/test/dummy/public/javascripts/controls.js +965 -0
- data/test/dummy/public/javascripts/dragdrop.js +974 -0
- data/test/dummy/public/javascripts/effects.js +1123 -0
- data/test/dummy/public/javascripts/prototype.js +6001 -0
- data/test/dummy/public/javascripts/rails.js +191 -0
- data/test/dummy/public/stylesheets/.gitkeep +0 -0
- data/test/dummy/script/rails +6 -0
- data/test/integration/new_data_notifier_test.rb +10 -0
- data/test/support/integration_case.rb +4 -0
- data/test/test_helper.rb +18 -0
- metadata +180 -27
- data/README.rdoc +0 -19
- data/lib/railtie.rb +0 -7
- data/lib/tasks/notifier.rake +0 -30
@@ -0,0 +1,191 @@
|
|
1
|
+
(function() {
|
2
|
+
// Technique from Juriy Zaytsev
|
3
|
+
// http://thinkweb2.com/projects/prototype/detecting-event-support-without-browser-sniffing/
|
4
|
+
function isEventSupported(eventName) {
|
5
|
+
var el = document.createElement('div');
|
6
|
+
eventName = 'on' + eventName;
|
7
|
+
var isSupported = (eventName in el);
|
8
|
+
if (!isSupported) {
|
9
|
+
el.setAttribute(eventName, 'return;');
|
10
|
+
isSupported = typeof el[eventName] == 'function';
|
11
|
+
}
|
12
|
+
el = null;
|
13
|
+
return isSupported;
|
14
|
+
}
|
15
|
+
|
16
|
+
function isForm(element) {
|
17
|
+
return Object.isElement(element) && element.nodeName.toUpperCase() == 'FORM'
|
18
|
+
}
|
19
|
+
|
20
|
+
function isInput(element) {
|
21
|
+
if (Object.isElement(element)) {
|
22
|
+
var name = element.nodeName.toUpperCase()
|
23
|
+
return name == 'INPUT' || name == 'SELECT' || name == 'TEXTAREA'
|
24
|
+
}
|
25
|
+
else return false
|
26
|
+
}
|
27
|
+
|
28
|
+
var submitBubbles = isEventSupported('submit'),
|
29
|
+
changeBubbles = isEventSupported('change')
|
30
|
+
|
31
|
+
if (!submitBubbles || !changeBubbles) {
|
32
|
+
// augment the Event.Handler class to observe custom events when needed
|
33
|
+
Event.Handler.prototype.initialize = Event.Handler.prototype.initialize.wrap(
|
34
|
+
function(init, element, eventName, selector, callback) {
|
35
|
+
init(element, eventName, selector, callback)
|
36
|
+
// is the handler being attached to an element that doesn't support this event?
|
37
|
+
if ( (!submitBubbles && this.eventName == 'submit' && !isForm(this.element)) ||
|
38
|
+
(!changeBubbles && this.eventName == 'change' && !isInput(this.element)) ) {
|
39
|
+
// "submit" => "emulated:submit"
|
40
|
+
this.eventName = 'emulated:' + this.eventName
|
41
|
+
}
|
42
|
+
}
|
43
|
+
)
|
44
|
+
}
|
45
|
+
|
46
|
+
if (!submitBubbles) {
|
47
|
+
// discover forms on the page by observing focus events which always bubble
|
48
|
+
document.on('focusin', 'form', function(focusEvent, form) {
|
49
|
+
// special handler for the real "submit" event (one-time operation)
|
50
|
+
if (!form.retrieve('emulated:submit')) {
|
51
|
+
form.on('submit', function(submitEvent) {
|
52
|
+
var emulated = form.fire('emulated:submit', submitEvent, true)
|
53
|
+
// if custom event received preventDefault, cancel the real one too
|
54
|
+
if (emulated.returnValue === false) submitEvent.preventDefault()
|
55
|
+
})
|
56
|
+
form.store('emulated:submit', true)
|
57
|
+
}
|
58
|
+
})
|
59
|
+
}
|
60
|
+
|
61
|
+
if (!changeBubbles) {
|
62
|
+
// discover form inputs on the page
|
63
|
+
document.on('focusin', 'input, select, texarea', function(focusEvent, input) {
|
64
|
+
// special handler for real "change" events
|
65
|
+
if (!input.retrieve('emulated:change')) {
|
66
|
+
input.on('change', function(changeEvent) {
|
67
|
+
input.fire('emulated:change', changeEvent, true)
|
68
|
+
})
|
69
|
+
input.store('emulated:change', true)
|
70
|
+
}
|
71
|
+
})
|
72
|
+
}
|
73
|
+
|
74
|
+
function handleRemote(element) {
|
75
|
+
var method, url, params;
|
76
|
+
|
77
|
+
var event = element.fire("ajax:before");
|
78
|
+
if (event.stopped) return false;
|
79
|
+
|
80
|
+
if (element.tagName.toLowerCase() === 'form') {
|
81
|
+
method = element.readAttribute('method') || 'post';
|
82
|
+
url = element.readAttribute('action');
|
83
|
+
params = element.serialize();
|
84
|
+
} else {
|
85
|
+
method = element.readAttribute('data-method') || 'get';
|
86
|
+
url = element.readAttribute('href');
|
87
|
+
params = {};
|
88
|
+
}
|
89
|
+
|
90
|
+
new Ajax.Request(url, {
|
91
|
+
method: method,
|
92
|
+
parameters: params,
|
93
|
+
evalScripts: true,
|
94
|
+
|
95
|
+
onComplete: function(request) { element.fire("ajax:complete", request); },
|
96
|
+
onSuccess: function(request) { element.fire("ajax:success", request); },
|
97
|
+
onFailure: function(request) { element.fire("ajax:failure", request); }
|
98
|
+
});
|
99
|
+
|
100
|
+
element.fire("ajax:after");
|
101
|
+
}
|
102
|
+
|
103
|
+
function handleMethod(element) {
|
104
|
+
var method = element.readAttribute('data-method'),
|
105
|
+
url = element.readAttribute('href'),
|
106
|
+
csrf_param = $$('meta[name=csrf-param]')[0],
|
107
|
+
csrf_token = $$('meta[name=csrf-token]')[0];
|
108
|
+
|
109
|
+
var form = new Element('form', { method: "POST", action: url, style: "display: none;" });
|
110
|
+
element.parentNode.insert(form);
|
111
|
+
|
112
|
+
if (method !== 'post') {
|
113
|
+
var field = new Element('input', { type: 'hidden', name: '_method', value: method });
|
114
|
+
form.insert(field);
|
115
|
+
}
|
116
|
+
|
117
|
+
if (csrf_param) {
|
118
|
+
var param = csrf_param.readAttribute('content'),
|
119
|
+
token = csrf_token.readAttribute('content'),
|
120
|
+
field = new Element('input', { type: 'hidden', name: param, value: token });
|
121
|
+
form.insert(field);
|
122
|
+
}
|
123
|
+
|
124
|
+
form.submit();
|
125
|
+
}
|
126
|
+
|
127
|
+
|
128
|
+
document.on("click", "*[data-confirm]", function(event, element) {
|
129
|
+
var message = element.readAttribute('data-confirm');
|
130
|
+
if (!confirm(message)) event.stop();
|
131
|
+
});
|
132
|
+
|
133
|
+
document.on("click", "a[data-remote]", function(event, element) {
|
134
|
+
if (event.stopped) return;
|
135
|
+
handleRemote(element);
|
136
|
+
event.stop();
|
137
|
+
});
|
138
|
+
|
139
|
+
document.on("click", "a[data-method]", function(event, element) {
|
140
|
+
if (event.stopped) return;
|
141
|
+
handleMethod(element);
|
142
|
+
event.stop();
|
143
|
+
});
|
144
|
+
|
145
|
+
document.on("submit", function(event) {
|
146
|
+
var element = event.findElement(),
|
147
|
+
message = element.readAttribute('data-confirm');
|
148
|
+
if (message && !confirm(message)) {
|
149
|
+
event.stop();
|
150
|
+
return false;
|
151
|
+
}
|
152
|
+
|
153
|
+
var inputs = element.select("input[type=submit][data-disable-with]");
|
154
|
+
inputs.each(function(input) {
|
155
|
+
input.disabled = true;
|
156
|
+
input.writeAttribute('data-original-value', input.value);
|
157
|
+
input.value = input.readAttribute('data-disable-with');
|
158
|
+
});
|
159
|
+
|
160
|
+
var element = event.findElement("form[data-remote]");
|
161
|
+
if (element) {
|
162
|
+
handleRemote(element);
|
163
|
+
event.stop();
|
164
|
+
}
|
165
|
+
});
|
166
|
+
|
167
|
+
document.on("ajax:after", "form", function(event, element) {
|
168
|
+
var inputs = element.select("input[type=submit][disabled=true][data-disable-with]");
|
169
|
+
inputs.each(function(input) {
|
170
|
+
input.value = input.readAttribute('data-original-value');
|
171
|
+
input.removeAttribute('data-original-value');
|
172
|
+
input.disabled = false;
|
173
|
+
});
|
174
|
+
});
|
175
|
+
|
176
|
+
Ajax.Responders.register({
|
177
|
+
onCreate: function(request) {
|
178
|
+
var csrf_meta_tag = $$('meta[name=csrf-token]')[0];
|
179
|
+
|
180
|
+
if (csrf_meta_tag) {
|
181
|
+
var header = 'X-CSRF-Token',
|
182
|
+
token = csrf_meta_tag.readAttribute('content');
|
183
|
+
|
184
|
+
if (!request.options.requestHeaders) {
|
185
|
+
request.options.requestHeaders = {};
|
186
|
+
}
|
187
|
+
request.options.requestHeaders[header] = token;
|
188
|
+
}
|
189
|
+
}
|
190
|
+
});
|
191
|
+
})();
|
File without changes
|
@@ -0,0 +1,6 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
# This command will automatically be run when you run "rails" with Rails 3 gems installed from the root of your application.
|
3
|
+
|
4
|
+
APP_PATH = File.expand_path('../../config/application', __FILE__)
|
5
|
+
require File.expand_path('../../config/boot', __FILE__)
|
6
|
+
require 'rails/commands'
|
@@ -0,0 +1,10 @@
|
|
1
|
+
require 'test_helper'
|
2
|
+
|
3
|
+
class NewDataNotifierTest < ActiveSupport::IntegrationCase
|
4
|
+
test "should send mail when there is new users" do
|
5
|
+
assert Time.now >= NewDataNotifier::Notifier.get_last_sent_at
|
6
|
+
assert NewDataNotifier::Notifier.get_latest_added_data.blank?
|
7
|
+
User.create :email => "a@a.com"
|
8
|
+
assert !NewDataNotifier::Notifier.get_latest_added_data.blank?
|
9
|
+
end
|
10
|
+
end
|
data/test/test_helper.rb
ADDED
@@ -0,0 +1,18 @@
|
|
1
|
+
# Configure Rails Envinronment
|
2
|
+
ENV["RAILS_ENV"] = "test"
|
3
|
+
|
4
|
+
require File.expand_path("../dummy/config/environment.rb", __FILE__)
|
5
|
+
require "rails/test_help"
|
6
|
+
require 'pp'
|
7
|
+
|
8
|
+
ActionMailer::Base.delivery_method = :test
|
9
|
+
ActionMailer::Base.perform_deliveries = true
|
10
|
+
ActionMailer::Base.default_url_options[:host] = "test.com"
|
11
|
+
|
12
|
+
Rails.backtrace_cleaner.remove_silencers!
|
13
|
+
|
14
|
+
# Run any available migration
|
15
|
+
ActiveRecord::Migrator.migrate File.expand_path("../dummy/db/migrate/", __FILE__)
|
16
|
+
|
17
|
+
# Load support files
|
18
|
+
Dir["#{File.dirname(__FILE__)}/support/**/*.rb"].each { |f| require f }
|
metadata
CHANGED
@@ -1,41 +1,176 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: new_data_notifier
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
hash:
|
5
|
-
prerelease:
|
4
|
+
hash: 31
|
5
|
+
prerelease:
|
6
6
|
segments:
|
7
7
|
- 0
|
8
|
-
-
|
9
|
-
-
|
10
|
-
version: 0.
|
8
|
+
- 1
|
9
|
+
- 2
|
10
|
+
version: 0.1.2
|
11
11
|
platform: ruby
|
12
12
|
authors:
|
13
|
-
-
|
13
|
+
- michael he
|
14
14
|
autorequire:
|
15
15
|
bindir: bin
|
16
16
|
cert_chain: []
|
17
17
|
|
18
|
-
date:
|
18
|
+
date: 2011-03-17 00:00:00 +08:00
|
19
19
|
default_executable:
|
20
|
-
dependencies:
|
21
|
-
|
22
|
-
|
20
|
+
dependencies:
|
21
|
+
- !ruby/object:Gem::Dependency
|
22
|
+
version_requirements: &id001 !ruby/object:Gem::Requirement
|
23
|
+
none: false
|
24
|
+
requirements:
|
25
|
+
- - ">="
|
26
|
+
- !ruby/object:Gem::Version
|
27
|
+
hash: 7
|
28
|
+
segments:
|
29
|
+
- 3
|
30
|
+
- 0
|
31
|
+
- 0
|
32
|
+
version: 3.0.0
|
33
|
+
requirement: *id001
|
34
|
+
prerelease: false
|
35
|
+
name: rails
|
36
|
+
type: :runtime
|
37
|
+
- !ruby/object:Gem::Dependency
|
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
|
+
requirement: *id002
|
48
|
+
prerelease: false
|
49
|
+
name: sqlite3-ruby
|
50
|
+
type: :development
|
51
|
+
- !ruby/object:Gem::Dependency
|
52
|
+
version_requirements: &id003 !ruby/object:Gem::Requirement
|
53
|
+
none: false
|
54
|
+
requirements:
|
55
|
+
- - ">="
|
56
|
+
- !ruby/object:Gem::Version
|
57
|
+
hash: 3
|
58
|
+
segments:
|
59
|
+
- 0
|
60
|
+
version: "0"
|
61
|
+
requirement: *id003
|
62
|
+
prerelease: false
|
63
|
+
name: bundler
|
64
|
+
type: :development
|
65
|
+
- !ruby/object:Gem::Dependency
|
66
|
+
version_requirements: &id004 !ruby/object:Gem::Requirement
|
67
|
+
none: false
|
68
|
+
requirements:
|
69
|
+
- - ">="
|
70
|
+
- !ruby/object:Gem::Version
|
71
|
+
hash: 3
|
72
|
+
segments:
|
73
|
+
- 0
|
74
|
+
version: "0"
|
75
|
+
requirement: *id004
|
76
|
+
prerelease: false
|
77
|
+
name: jeweler
|
78
|
+
type: :development
|
79
|
+
- !ruby/object:Gem::Dependency
|
80
|
+
version_requirements: &id005 !ruby/object:Gem::Requirement
|
81
|
+
none: false
|
82
|
+
requirements:
|
83
|
+
- - ">="
|
84
|
+
- !ruby/object:Gem::Version
|
85
|
+
hash: 3
|
86
|
+
segments:
|
87
|
+
- 0
|
88
|
+
version: "0"
|
89
|
+
requirement: *id005
|
90
|
+
prerelease: false
|
91
|
+
name: rcov
|
92
|
+
type: :development
|
93
|
+
- !ruby/object:Gem::Dependency
|
94
|
+
version_requirements: &id006 !ruby/object:Gem::Requirement
|
95
|
+
none: false
|
96
|
+
requirements:
|
97
|
+
- - ">="
|
98
|
+
- !ruby/object:Gem::Version
|
99
|
+
hash: 3
|
100
|
+
segments:
|
101
|
+
- 0
|
102
|
+
version: "0"
|
103
|
+
requirement: *id006
|
104
|
+
prerelease: false
|
105
|
+
name: reek
|
106
|
+
type: :development
|
107
|
+
description: If there is some new users signed up on your site or some new articles been added by some other user, If you hope been notified, please execute "gem install new_data_notifier
|
23
108
|
email: hlxwell@gmail.com
|
24
109
|
executables: []
|
25
110
|
|
26
111
|
extensions: []
|
27
112
|
|
28
|
-
extra_rdoc_files:
|
29
|
-
|
113
|
+
extra_rdoc_files:
|
114
|
+
- README.mkd
|
30
115
|
files:
|
31
|
-
-
|
116
|
+
- Gemfile
|
117
|
+
- Gemfile.lock
|
118
|
+
- MIT-LICENSE
|
119
|
+
- README.mkd
|
120
|
+
- Rakefile
|
121
|
+
- VERSION
|
122
|
+
- app/.DS_Store
|
123
|
+
- app/mailers/new_data_notifier/notifier.rb
|
124
|
+
- app/views/new_data_notifier/notifier/notification.text.erb
|
125
|
+
- lib/.DS_Store
|
32
126
|
- lib/new_data_notifier.rb
|
33
|
-
- lib/
|
34
|
-
- lib/
|
127
|
+
- lib/new_data_notifier/engine.rb
|
128
|
+
- lib/new_data_notifier/generators/create_config.rb
|
129
|
+
- lib/new_data_notifier/generators/templates/new_data_notifier.rb
|
130
|
+
- lib/new_data_notifier/tasks/notifier.rake
|
131
|
+
- new_data_notifier.gemspec
|
132
|
+
- test/dummy/Rakefile
|
133
|
+
- test/dummy/app/controllers/application_controller.rb
|
134
|
+
- test/dummy/app/helpers/application_helper.rb
|
135
|
+
- test/dummy/app/models/user.rb
|
136
|
+
- test/dummy/app/views/layouts/application.html.erb
|
137
|
+
- test/dummy/config.ru
|
138
|
+
- test/dummy/config/application.rb
|
139
|
+
- test/dummy/config/boot.rb
|
140
|
+
- test/dummy/config/database.yml
|
141
|
+
- test/dummy/config/environment.rb
|
142
|
+
- test/dummy/config/environments/development.rb
|
143
|
+
- test/dummy/config/environments/production.rb
|
144
|
+
- test/dummy/config/environments/test.rb
|
145
|
+
- test/dummy/config/initializers/backtrace_silencers.rb
|
146
|
+
- test/dummy/config/initializers/inflections.rb
|
147
|
+
- test/dummy/config/initializers/mime_types.rb
|
148
|
+
- test/dummy/config/initializers/new_data_notifier.rb
|
149
|
+
- test/dummy/config/initializers/secret_token.rb
|
150
|
+
- test/dummy/config/initializers/session_store.rb
|
151
|
+
- test/dummy/config/locales/en.yml
|
152
|
+
- test/dummy/config/routes.rb
|
153
|
+
- test/dummy/db/migrate/20110317034437_create_users.rb
|
154
|
+
- test/dummy/db/schema.rb
|
155
|
+
- test/dummy/public/404.html
|
156
|
+
- test/dummy/public/422.html
|
157
|
+
- test/dummy/public/500.html
|
158
|
+
- test/dummy/public/favicon.ico
|
159
|
+
- test/dummy/public/javascripts/application.js
|
160
|
+
- test/dummy/public/javascripts/controls.js
|
161
|
+
- test/dummy/public/javascripts/dragdrop.js
|
162
|
+
- test/dummy/public/javascripts/effects.js
|
163
|
+
- test/dummy/public/javascripts/prototype.js
|
164
|
+
- test/dummy/public/javascripts/rails.js
|
165
|
+
- test/dummy/public/stylesheets/.gitkeep
|
166
|
+
- test/dummy/script/rails
|
167
|
+
- test/integration/new_data_notifier_test.rb
|
168
|
+
- test/support/integration_case.rb
|
169
|
+
- test/test_helper.rb
|
35
170
|
has_rdoc: true
|
36
|
-
homepage: http://
|
37
|
-
licenses:
|
38
|
-
|
171
|
+
homepage: http://github.com/hlxwell/new_data_notifier
|
172
|
+
licenses:
|
173
|
+
- MIT
|
39
174
|
post_install_message:
|
40
175
|
rdoc_options: []
|
41
176
|
|
@@ -46,12 +181,10 @@ required_ruby_version: !ruby/object:Gem::Requirement
|
|
46
181
|
requirements:
|
47
182
|
- - ">="
|
48
183
|
- !ruby/object:Gem::Version
|
49
|
-
hash:
|
184
|
+
hash: 3
|
50
185
|
segments:
|
51
|
-
-
|
52
|
-
|
53
|
-
- 7
|
54
|
-
version: 1.8.7
|
186
|
+
- 0
|
187
|
+
version: "0"
|
55
188
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
56
189
|
none: false
|
57
190
|
requirements:
|
@@ -64,9 +197,29 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
64
197
|
requirements: []
|
65
198
|
|
66
199
|
rubyforge_project:
|
67
|
-
rubygems_version: 1.
|
200
|
+
rubygems_version: 1.4.1
|
68
201
|
signing_key:
|
69
202
|
specification_version: 3
|
70
|
-
summary:
|
71
|
-
test_files:
|
72
|
-
|
203
|
+
summary: If there is some new users signed up on your site or some new articles been added by some other user, If you hope been notified, please execute "gem install new_data_notifier
|
204
|
+
test_files:
|
205
|
+
- test/dummy/app/controllers/application_controller.rb
|
206
|
+
- test/dummy/app/helpers/application_helper.rb
|
207
|
+
- test/dummy/app/models/user.rb
|
208
|
+
- test/dummy/config/application.rb
|
209
|
+
- test/dummy/config/boot.rb
|
210
|
+
- test/dummy/config/environment.rb
|
211
|
+
- test/dummy/config/environments/development.rb
|
212
|
+
- test/dummy/config/environments/production.rb
|
213
|
+
- test/dummy/config/environments/test.rb
|
214
|
+
- test/dummy/config/initializers/backtrace_silencers.rb
|
215
|
+
- test/dummy/config/initializers/inflections.rb
|
216
|
+
- test/dummy/config/initializers/mime_types.rb
|
217
|
+
- test/dummy/config/initializers/new_data_notifier.rb
|
218
|
+
- test/dummy/config/initializers/secret_token.rb
|
219
|
+
- test/dummy/config/initializers/session_store.rb
|
220
|
+
- test/dummy/config/routes.rb
|
221
|
+
- test/dummy/db/migrate/20110317034437_create_users.rb
|
222
|
+
- test/dummy/db/schema.rb
|
223
|
+
- test/integration/new_data_notifier_test.rb
|
224
|
+
- test/support/integration_case.rb
|
225
|
+
- test/test_helper.rb
|
data/README.rdoc
DELETED
@@ -1,19 +0,0 @@
|
|
1
|
-
New Data Notifier
|
2
|
-
===============
|
3
|
-
|
4
|
-
If there is some new user signed up on your site or some new article been added by some other user,
|
5
|
-
You hope been notified.
|
6
|
-
|
7
|
-
Example
|
8
|
-
=======
|
9
|
-
|
10
|
-
1.add a new_data_notifier.rb to initialiers dir, and copy below content:
|
11
|
-
NewDataNotifier.default_recipients = ["hlxwell@gmail.com"]
|
12
|
-
NewDataNotifier.be_monitored_models = ["Job", "Partner"]
|
13
|
-
NewDataNotifier.sender_address = ["new_data@gmail.com"]
|
14
|
-
|
15
|
-
2.Add cron task.
|
16
|
-
*/20 * * * * sh -c "cd /home/michael.he/app/current && rake send_latest_data RAILS_ENV=production"
|
17
|
-
|
18
|
-
|
19
|
-
Copyright (c) 2010 Michael He, released under the MIT license
|
data/lib/railtie.rb
DELETED
data/lib/tasks/notifier.rake
DELETED
@@ -1,30 +0,0 @@
|
|
1
|
-
desc "send latest data"
|
2
|
-
task :send_latest_data => :environment do
|
3
|
-
time_mark_file_path = File.join(Rails.root, 'tmp', 'last_notification_send_at')
|
4
|
-
|
5
|
-
# read last sent time, if blank, set current time.
|
6
|
-
begin
|
7
|
-
last_sent_at = File.read(time_mark_file_path).to_time
|
8
|
-
raise if last_sent_at.blank?
|
9
|
-
rescue
|
10
|
-
last_sent_at = Time.now
|
11
|
-
ensure
|
12
|
-
File.open(time_mark_file_path, "w") do |f|
|
13
|
-
f.write(Time.now)
|
14
|
-
end
|
15
|
-
end
|
16
|
-
|
17
|
-
# find data
|
18
|
-
data_hash = {}
|
19
|
-
|
20
|
-
NewDataNotifier.be_monitored_models.each do |model|
|
21
|
-
data_hash[model.downcase.to_sym] = model.constantize.all(:conditions => ["created_at > ?", last_sent_at], :order => "created_at DESC")
|
22
|
-
end
|
23
|
-
|
24
|
-
data_hash.delete_if { |key, value| value.blank? }
|
25
|
-
|
26
|
-
# send mail
|
27
|
-
unless data_hash.select { |key, value| value.size > 0 }.blank?
|
28
|
-
NewDataNotifier.notification(data_hash).deliver
|
29
|
-
end
|
30
|
-
end
|