hertz 0.1.0 → 1.0.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 0988dec23d3f623853e523c7fc2e6f530c6dcdc2
4
- data.tar.gz: fd300b90871a186b9068f6c94002631c21b928af
3
+ metadata.gz: 2eef5fc7cb19de80f84d964b0f2d6a537b9abd5b
4
+ data.tar.gz: 670e53a7387981df2a9bec8983f8e10b4660050a
5
5
  SHA512:
6
- metadata.gz: 6145eb3c0c8e18ec36dcbcc6901b4003e8d863ec11b60031ca4fe895a752fee78f96197f35c2b9282b8d75bf6c42d203e84797946608adbdeac3ff6e66fb33e1
7
- data.tar.gz: e1cfa1891739d7658eb1ad98089d4294f6491ed602ca4a349ba5e35e8ce84486686c329bd448f8331c61433dc6081c3efb34a51e618c163e21da5c296292ebab
6
+ metadata.gz: 59110519a6b34162d8a194bb4f17dec3c5eb1607c79d211f3ed3c0cb329a9c59a805424bbf9515dbc57e8cc7ae8149182414049a8aab58be7b393da6b66cbdf9
7
+ data.tar.gz: ae85c1e2303752f2f8414028cbb386894c8f84f41f82cf68177a8a854a908b69650d8563a964b25dd98b7cf0b305e172a5323370eff0eae988b2b9aa75cff360
data/README.md CHANGED
@@ -1,9 +1,10 @@
1
1
  # Hertz
2
2
 
3
+ [![Gem Version](https://badge.fury.io/rb/hertz.svg)](https://badge.fury.io/rb/hertz)
3
4
  [![Dependency Status](https://gemnasium.com/badges/github.com/alessandro1997/hertz.svg)](https://gemnasium.com/github.com/alessandro1997/hertz)
4
5
  [![Code Climate](https://codeclimate.com/github/alessandro1997/hertz/badges/gpa.svg)](https://codeclimate.com/github/alessandro1997/hertz)
5
6
 
6
- Hertz is a Ruby on Rails engine for sending in-app notification to your users.
7
+ Hertz is a Ruby on Rails engine for sending in-app notifications to your users.
7
8
 
8
9
  ## Installation
9
10
 
@@ -133,49 +134,12 @@ notification.mark_as_read
133
134
  notification.mark_as_unread
134
135
  ```
135
136
 
136
- ## Built-in couriers
137
+ ## Other couriers
137
138
 
138
- ### Email
139
-
140
- The email courier delivers your notifications by email. In order to use this
141
- courier, add `:email` to `deliver_by` in the notification model(s):
142
-
143
- ```ruby
144
- class CommentNotification < Hertz::Notification
145
- deliver_by :email
146
- end
147
- ```
148
-
149
- You will also need to expose the `hertz_email` method in your receiver class:
150
-
151
- ```ruby
152
- class User < ActiveRecord::Base
153
- def hertz_email
154
- email
155
- end
156
- end
157
- ```
158
-
159
- And the `email_subject` method in your notification class:
160
-
161
- ```ruby
162
- class CommentNotification < Hertz::Notification
163
- def email_subject
164
- 'You have a new comment!'
165
- end
166
- end
167
- ```
168
-
169
- Finally, you should create a template for every notification you send by email.
170
- For `CommentNotification` you'd create a template at
171
- `app/views/hertz/notification_mailer/comment_notification.html.erb`:
172
-
173
- ```erb
174
- <p>Hey <%= @notification.receiver.hertz_email %>,</p>
175
- <p>you've got a new comment!</p>
176
- ```
177
-
178
- As you can see, templates have access to the `@notification` instance variable.
139
+ - [hertz-courier-twilio](https://github.com/alessandro1997/hertz-courier-twilio):
140
+ delivers notifications by SMS with the Twilio API.
141
+ - [hertz-courier-email](https://github.com/alessandro1997/hertz-courier-email):
142
+ delivers notifications by email with ActionMailer.
179
143
 
180
144
  ## Contributing
181
145
 
@@ -186,3 +150,10 @@ https://github.com/alessandro1997/hertz.
186
150
 
187
151
  The gem is available as open source under the terms of the
188
152
  [MIT License](http://opensource.org/licenses/MIT).
153
+
154
+ ## To do
155
+
156
+ - [ ] Test `Hertz.configure`
157
+ - [ ] Allow setting common couriers for all notifications
158
+ - [ ] Validate couriers when calling `Hertz::Notifiable.deliver_by`
159
+ - [ ] Extract `Hertz::Courier::Email` into a separate gem
@@ -1,5 +1,3 @@
1
1
  # frozen_string_literal: true
2
2
  Hertz.configure do |config|
3
- # Your base mailer class, for delivering notifications by email.
4
- # config.base_mailer = '::ApplicationMailer'
5
3
  end
data/lib/hertz/version.rb CHANGED
@@ -1,4 +1,4 @@
1
1
  # frozen_string_literal: true
2
2
  module Hertz
3
- VERSION = '0.1.0'
3
+ VERSION = '1.0.0'
4
4
  end
data/lib/hertz.rb CHANGED
@@ -3,17 +3,9 @@ require 'hertz/engine'
3
3
 
4
4
  require 'hertz/notifiable'
5
5
  require 'hertz/notification_deliverer'
6
- require 'hertz/courier/base'
7
- require 'hertz/courier/email'
8
6
 
9
7
  module Hertz
10
- mattr_writer :base_mailer
11
-
12
8
  def self.configure(&block)
13
9
  block.call(self)
14
10
  end
15
-
16
- def self.base_mailer
17
- (@@base_mailer || '::ApplicationMailer').constantize
18
- end
19
11
  end
@@ -1,7 +1,2 @@
1
1
  class TestNotification < Hertz::Notification
2
- deliver_by :email
3
-
4
- def email_subject
5
- 'Test Notification'
6
- end
7
2
  end
@@ -1,14 +1,8 @@
1
- # SQLite version 3.x
2
- # gem install sqlite3
3
- #
4
- # Ensure the SQLite 3 gem is defined in your Gemfile
5
- # gem 'sqlite3'
6
- #
7
1
  default: &default
8
2
  adapter: postgresql
9
3
  host: localhost
10
4
  username: postgres
11
- password: alacritate
5
+ password: postgres
12
6
  pool: 5
13
7
  timeout: 5000
14
8
 
@@ -16,9 +10,6 @@ development:
16
10
  <<: *default
17
11
  database: hertz_development
18
12
 
19
- # Warning: The database defined as "test" will be erased and
20
- # re-generated from your development database when you run "rake".
21
- # Do not set this db to the same as development or production.
22
13
  test:
23
14
  <<: *default
24
15
  database: hertz_test
@@ -1,4 +1,2 @@
1
1
  Hertz.configure do |config|
2
- # Your base mailer class, for delivering notifications by email.
3
- # config.base_mailer = '::ApplicationMailer'
4
2
  end
@@ -0,0 +1,5 @@
1
+ class RemoveEmailFromUsers < ActiveRecord::Migration
2
+ def change
3
+ remove_column :users, :email, :string
4
+ end
5
+ end
@@ -11,7 +11,7 @@
11
11
  #
12
12
  # It's strongly recommended that you check this file into your version control system.
13
13
 
14
- ActiveRecord::Schema.define(version: 20160418122437) do
14
+ ActiveRecord::Schema.define(version: 20160508094342) do
15
15
 
16
16
  # These are extensions that must be enabled in order to support this database
17
17
  enable_extension "plpgsql"
@@ -29,7 +29,6 @@ ActiveRecord::Schema.define(version: 20160418122437) do
29
29
  create_table "users", force: :cascade do |t|
30
30
  t.datetime "created_at", null: false
31
31
  t.datetime "updated_at", null: false
32
- t.string "email", null: false
33
32
  end
34
33
 
35
34
  end
@@ -1,103 +1,32 @@
1
-  (4.6ms) CREATE TABLE "schema_migrations" ("version" character varying NOT NULL) 
2
-  (2.1ms) CREATE UNIQUE INDEX "unique_schema_migrations" ON "schema_migrations" ("version")
1
+ SQL (0.3ms) CREATE EXTENSION IF NOT EXISTS "plpgsql"
2
+ SQL (31.9ms) CREATE EXTENSION IF NOT EXISTS "hstore"
3
+  (21.0ms) CREATE TABLE "hertz_notifications" ("id" serial primary key, "type" character varying NOT NULL, "receiver_type" character varying NOT NULL, "receiver_id" integer NOT NULL, "meta" hstore DEFAULT '' NOT NULL, "read_at" timestamp, "created_at" timestamp NOT NULL) 
4
+  (6.6ms) CREATE TABLE "users" ("id" serial primary key, "created_at" timestamp NOT NULL, "updated_at" timestamp NOT NULL, "email" character varying NOT NULL)
5
+  (7.9ms) CREATE TABLE "schema_migrations" ("version" character varying NOT NULL) 
6
+  (8.2ms) CREATE UNIQUE INDEX "unique_schema_migrations" ON "schema_migrations" ("version")
7
+  (0.7ms) SELECT version FROM "schema_migrations"
8
+  (1.6ms) INSERT INTO "schema_migrations" (version) VALUES ('20160418122437')
9
+  (1.4ms) INSERT INTO "schema_migrations" (version) VALUES ('20160415175837')
10
+  (1.8ms) INSERT INTO "schema_migrations" (version) VALUES ('20160415175358')
11
+ SQL (0.5ms) CREATE EXTENSION IF NOT EXISTS "plpgsql"
12
+ SQL (24.4ms) CREATE EXTENSION IF NOT EXISTS "hstore"
13
+  (16.8ms) CREATE TABLE "hertz_notifications" ("id" serial primary key, "type" character varying NOT NULL, "receiver_type" character varying NOT NULL, "receiver_id" integer NOT NULL, "meta" hstore DEFAULT '' NOT NULL, "read_at" timestamp, "created_at" timestamp NOT NULL) 
14
+  (10.0ms) CREATE TABLE "users" ("id" serial primary key, "created_at" timestamp NOT NULL, "updated_at" timestamp NOT NULL, "email" character varying NOT NULL)
15
+  (9.3ms) CREATE TABLE "schema_migrations" ("version" character varying NOT NULL) 
16
+  (13.5ms) CREATE UNIQUE INDEX "unique_schema_migrations" ON "schema_migrations" ("version")
17
+  (1.0ms) SELECT version FROM "schema_migrations"
18
+  (1.2ms) INSERT INTO "schema_migrations" (version) VALUES ('20160418122437')
19
+  (1.1ms) INSERT INTO "schema_migrations" (version) VALUES ('20160415175837')
20
+  (1.2ms) INSERT INTO "schema_migrations" (version) VALUES ('20160415175358')
3
21
  ActiveRecord::SchemaMigration Load (0.4ms) SELECT "schema_migrations".* FROM "schema_migrations"
4
- SQL (0.4ms) CREATE EXTENSION IF NOT EXISTS "plpgsql"
5
-  (0.4ms) SELECT version FROM "schema_migrations"
6
-  (0.7ms) INSERT INTO "schema_migrations" (version) VALUES ('0')
7
- SQL (0.6ms) CREATE EXTENSION IF NOT EXISTS "plpgsql"
8
-  (4.8ms) CREATE TABLE "schema_migrations" ("version" character varying NOT NULL)
9
-  (2.2ms) CREATE UNIQUE INDEX "unique_schema_migrations" ON "schema_migrations" ("version")
10
-  (0.3ms) SELECT version FROM "schema_migrations"
11
-  (0.5ms) INSERT INTO "schema_migrations" (version) VALUES ('0')
12
- ActiveRecord::SchemaMigration Load (0.5ms) SELECT "schema_migrations".* FROM "schema_migrations"
13
- ActiveRecord::SchemaMigration Load (0.5ms) SELECT "schema_migrations".* FROM "schema_migrations"
14
- Migrating to CreateHertzNotifications (20160415175229)
15
-  (0.3ms) BEGIN
16
-  (6.6ms) CREATE TABLE "hertz_notifications" ("id" serial primary key, "type" character varying NOT NULL, "receiver_type" character varying NOT NULL, "receiver_id" integer NOT NULL, "meta" json NOT NULL, "read_at" timestamp, "created_at" timestamp NOT NULL) 
17
- SQL (0.4ms) INSERT INTO "schema_migrations" ("version") VALUES ($1) [["version", "20160415175229"]]
18
-  (1.3ms) COMMIT
19
- ActiveRecord::SchemaMigration Load (1.1ms) SELECT "schema_migrations".* FROM "schema_migrations"
20
-  (5.1ms) SELECT t2.oid::regclass::text AS to_table, a1.attname AS column, a2.attname AS primary_key, c.conname AS name, c.confupdtype AS on_update, c.confdeltype AS on_delete
21
- FROM pg_constraint c
22
- JOIN pg_class t1 ON c.conrelid = t1.oid
23
- JOIN pg_class t2 ON c.confrelid = t2.oid
24
- JOIN pg_attribute a1 ON a1.attnum = c.conkey[1] AND a1.attrelid = t1.oid
25
- JOIN pg_attribute a2 ON a2.attnum = c.confkey[1] AND a2.attrelid = t2.oid
26
- JOIN pg_namespace t3 ON c.connamespace = t3.oid
27
- WHERE c.contype = 'f'
28
- AND t1.relname = 'hertz_notifications'
29
- AND t3.nspname = ANY (current_schemas(false))
30
- ORDER BY c.conname
31
- 
32
- ActiveRecord::SchemaMigration Load (0.5ms) SELECT "schema_migrations".* FROM "schema_migrations"
22
+ ActiveRecord::SchemaMigration Load (0.6ms) SELECT "schema_migrations".* FROM "schema_migrations"
23
+ Migrating to RemoveEmailFromUsers (20160508094342)
24
+  (0.4ms) BEGIN
25
+  (0.8ms) ALTER TABLE "users" DROP "email"
26
+ SQL (0.5ms) INSERT INTO "schema_migrations" ("version") VALUES ($1) [["version", "20160508094342"]]
27
+  (2.8ms) COMMIT
33
28
  ActiveRecord::SchemaMigration Load (0.3ms) SELECT "schema_migrations".* FROM "schema_migrations"
34
- Migrating to CreateHertzNotifications (20160415175229)
35
-  (0.2ms) BEGIN
36
-  (1.6ms) DROP TABLE "hertz_notifications"
37
- SQL (0.5ms) DELETE FROM "schema_migrations" WHERE "schema_migrations"."version" = $1 [["version", "20160415175229"]]
38
-  (1.2ms) COMMIT
39
- ActiveRecord::SchemaMigration Load (0.7ms) SELECT "schema_migrations".* FROM "schema_migrations"
40
- ActiveRecord::SchemaMigration Load (0.5ms) SELECT "schema_migrations".* FROM "schema_migrations"
41
- Migrating to CreateHertzNotifications (20160415175358)
42
-  (0.2ms) BEGIN
43
- SQL (19.0ms) CREATE EXTENSION IF NOT EXISTS "hstore"
44
-  (9.6ms) CREATE TABLE "hertz_notifications" ("id" serial primary key, "type" character varying NOT NULL, "receiver_type" character varying NOT NULL, "receiver_id" integer NOT NULL, "meta" hstore DEFAULT '' NOT NULL, "read_at" timestamp, "created_at" timestamp NOT NULL)
45
- SQL (0.5ms) INSERT INTO "schema_migrations" ("version") VALUES ($1) [["version", "20160415175358"]]
46
-  (3.4ms) COMMIT
47
- ActiveRecord::SchemaMigration Load (0.5ms) SELECT "schema_migrations".* FROM "schema_migrations"
48
-  (2.0ms) SELECT t2.oid::regclass::text AS to_table, a1.attname AS column, a2.attname AS primary_key, c.conname AS name, c.confupdtype AS on_update, c.confdeltype AS on_delete
49
- FROM pg_constraint c
50
- JOIN pg_class t1 ON c.conrelid = t1.oid
51
- JOIN pg_class t2 ON c.confrelid = t2.oid
52
- JOIN pg_attribute a1 ON a1.attnum = c.conkey[1] AND a1.attrelid = t1.oid
53
- JOIN pg_attribute a2 ON a2.attnum = c.confkey[1] AND a2.attrelid = t2.oid
54
- JOIN pg_namespace t3 ON c.connamespace = t3.oid
55
- WHERE c.contype = 'f'
56
- AND t1.relname = 'hertz_notifications'
57
- AND t3.nspname = ANY (current_schemas(false))
58
- ORDER BY c.conname
59
-
60
- ActiveRecord::SchemaMigration Load (0.8ms) SELECT "schema_migrations".* FROM "schema_migrations"
61
- Migrating to CreateUsers (20160415175837)
62
-  (0.2ms) BEGIN
63
-  (3.4ms) CREATE TABLE "users" ("id" serial primary key, "created_at" timestamp NOT NULL, "updated_at" timestamp NOT NULL) 
64
- SQL (0.6ms) INSERT INTO "schema_migrations" ("version") VALUES ($1) [["version", "20160415175837"]]
65
-  (1.8ms) COMMIT
66
- ActiveRecord::SchemaMigration Load (0.7ms) SELECT "schema_migrations".* FROM "schema_migrations"
67
-  (2.1ms) SELECT t2.oid::regclass::text AS to_table, a1.attname AS column, a2.attname AS primary_key, c.conname AS name, c.confupdtype AS on_update, c.confdeltype AS on_delete
68
- FROM pg_constraint c
69
- JOIN pg_class t1 ON c.conrelid = t1.oid
70
- JOIN pg_class t2 ON c.confrelid = t2.oid
71
- JOIN pg_attribute a1 ON a1.attnum = c.conkey[1] AND a1.attrelid = t1.oid
72
- JOIN pg_attribute a2 ON a2.attnum = c.confkey[1] AND a2.attrelid = t2.oid
73
- JOIN pg_namespace t3 ON c.connamespace = t3.oid
74
- WHERE c.contype = 'f'
75
- AND t1.relname = 'hertz_notifications'
76
- AND t3.nspname = ANY (current_schemas(false))
77
- ORDER BY c.conname
78
- 
79
-  (4.0ms) SELECT t2.oid::regclass::text AS to_table, a1.attname AS column, a2.attname AS primary_key, c.conname AS name, c.confupdtype AS on_update, c.confdeltype AS on_delete
80
- FROM pg_constraint c
81
- JOIN pg_class t1 ON c.conrelid = t1.oid
82
- JOIN pg_class t2 ON c.confrelid = t2.oid
83
- JOIN pg_attribute a1 ON a1.attnum = c.conkey[1] AND a1.attrelid = t1.oid
84
- JOIN pg_attribute a2 ON a2.attnum = c.confkey[1] AND a2.attrelid = t2.oid
85
- JOIN pg_namespace t3 ON c.connamespace = t3.oid
86
- WHERE c.contype = 'f'
87
- AND t1.relname = 'users'
88
- AND t3.nspname = ANY (current_schemas(false))
89
- ORDER BY c.conname
90
-
91
-
92
- Hertz::NotificationMailer#notification_email: processed outbound mail in 5.9ms
93
- ActiveRecord::SchemaMigration Load (2.7ms) SELECT "schema_migrations".* FROM "schema_migrations"
94
- Migrating to AddEmailToUsers (20160418122437)
95
-  (0.6ms) BEGIN
96
-  (25.4ms) ALTER TABLE "users" ADD "email" character varying NOT NULL
97
- SQL (4.6ms) INSERT INTO "schema_migrations" ("version") VALUES ($1) [["version", "20160418122437"]]
98
-  (5.0ms) COMMIT
99
- ActiveRecord::SchemaMigration Load (0.4ms) SELECT "schema_migrations".* FROM "schema_migrations"
100
-  (9.6ms) SELECT t2.oid::regclass::text AS to_table, a1.attname AS column, a2.attname AS primary_key, c.conname AS name, c.confupdtype AS on_update, c.confdeltype AS on_delete
29
+  (2.8ms) SELECT t2.oid::regclass::text AS to_table, a1.attname AS column, a2.attname AS primary_key, c.conname AS name, c.confupdtype AS on_update, c.confdeltype AS on_delete
101
30
  FROM pg_constraint c
102
31
  JOIN pg_class t1 ON c.conrelid = t1.oid
103
32
  JOIN pg_class t2 ON c.confrelid = t2.oid
@@ -109,7 +38,7 @@ WHERE c.contype = 'f'
109
38
  AND t3.nspname = ANY (current_schemas(false))
110
39
  ORDER BY c.conname
111
40
  
112
-  (9.2ms) SELECT t2.oid::regclass::text AS to_table, a1.attname AS column, a2.attname AS primary_key, c.conname AS name, c.confupdtype AS on_update, c.confdeltype AS on_delete
41
+  (2.5ms) SELECT t2.oid::regclass::text AS to_table, a1.attname AS column, a2.attname AS primary_key, c.conname AS name, c.confupdtype AS on_update, c.confdeltype AS on_delete
113
42
  FROM pg_constraint c
114
43
  JOIN pg_class t1 ON c.conrelid = t1.oid
115
44
  JOIN pg_class t2 ON c.confrelid = t2.oid
@@ -121,16 +50,3 @@ WHERE c.contype = 'f'
121
50
  AND t3.nspname = ANY (current_schemas(false))
122
51
  ORDER BY c.conname
123
52
 
124
-  (1.0ms) BEGIN
125
- SQL (2.1ms) INSERT INTO "users" ("email", "created_at", "updated_at") VALUES ($1, $2, $3) RETURNING "id" [["email", "foo@bar.com"], ["created_at", "2016-04-18 15:52:39.396262"], ["updated_at", "2016-04-18 15:52:39.396262"]]
126
-  (1.4ms) COMMIT
127
-  (0.8ms) BEGIN
128
- SQL (1.9ms) INSERT INTO "hertz_notifications" ("receiver_id", "receiver_type", "meta", "created_at") VALUES ($1, $2, $3, $4) RETURNING "id" [["receiver_id", 1], ["receiver_type", "User"], ["meta", "\"foo\"=>\"bar\""], ["created_at", "2016-04-18 15:52:39.426606"]]
129
-  (0.2ms) ROLLBACK
130
-  (0.3ms) BEGIN
131
- SQL (0.4ms) INSERT INTO "users" ("email", "created_at", "updated_at") VALUES ($1, $2, $3) RETURNING "id" [["email", "foo@bar.com"], ["created_at", "2016-04-18 15:52:50.303993"], ["updated_at", "2016-04-18 15:52:50.303993"]]
132
-  (0.7ms) COMMIT
133
-  (0.2ms) BEGIN
134
- SQL (0.9ms) INSERT INTO "hertz_notifications" ("type", "receiver_id", "receiver_type", "meta", "created_at") VALUES ($1, $2, $3, $4, $5) RETURNING "id" [["type", "Hertz::Notification"], ["receiver_id", 2], ["receiver_type", "User"], ["meta", "\"foo\"=>\"bar\""], ["created_at", "2016-04-18 15:52:50.307752"]]
135
-  (0.5ms) COMMIT
136
- Hertz::Notification Load (0.9ms) SELECT "hertz_notifications".* FROM "hertz_notifications" ORDER BY "hertz_notifications"."id" DESC LIMIT 1