gossiper 0.3.5 → 0.3.6

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.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: bc1480aab310d0621df06090ef44c953c3422cc6
4
- data.tar.gz: f0bf08f5a7c011c1110435016dde51829bb1d53b
3
+ metadata.gz: b5e5493e9a195fc89dc083b63e0276640d275436
4
+ data.tar.gz: 9f85d158a7f555f84816d697be1f3286df8ca170
5
5
  SHA512:
6
- metadata.gz: f033f5024be39161393719659a7408a3c4b4cea217a1457f2dcbfb1193f7ae95cc78cd51ab8f1d334a2fb9e83868bdaa8af3a18537d1a2d72fb617236a1a8e33
7
- data.tar.gz: b3cc4b64668113a7fe3f7c7caad4010a550d02b51fca04a5fcbd3217ca6a3b526f4fa4b58b3a6211d89d1689c7e2d65a2c44e02f1b257fa6dfa5415e95de78c7
6
+ metadata.gz: 58002ec759059e07d2d59e72558aad85c795ccb495791bdf4ca2275b8c116bcd2533ac542719d436abbc5b75a081330c69ea7744877857fe19d183c03fd7042c
7
+ data.tar.gz: f6fcdb924c76e49f0152a83f38d1b5d30cd740a513c26d74787dc0a74bfb303cb2c74d402a43da0916c1a48526dca25b91a9b4187c94552a01d279867de9f0a6
@@ -1,64 +1,5 @@
1
1
  module Gossiper
2
2
  class Notification < ActiveRecord::Base
3
-
4
- STATUSES = %w(pending delivered)
5
-
6
- serialize :data, JSON
7
-
8
- validates :kind, presence: true
9
- belongs_to :user, polymorphic: true
10
-
11
- def status
12
- read_attribute(:status).presence || STATUSES.first
13
- end
14
-
15
- def data
16
- read_attribute(:data).presence || {}
17
- end
18
-
19
- def deliver
20
- mail.deliver
21
- update_delivered_at!
22
- end
23
-
24
- def deliver!
25
- mail.deliver!
26
- update_delivered_at!
27
- end
28
-
29
- def kind=(value)
30
- value = value.present? ? value.parameterize.underscore : nil
31
- write_attribute(:kind, value)
32
- end
33
-
34
- def config
35
- begin
36
- klass = "Notifications::#{kind.classify}Notification"
37
- klass.constantize.new(self)
38
- rescue NameError
39
- klass = Gossiper.configuration.default_notification_config_class
40
- klass.constantize.new(self)
41
- end
42
- end
43
-
44
- def method_missing(method, *args, &block)
45
- STATUSES.each do |status|
46
- if method.to_s == "#{status}?"
47
- return self.status == status
48
- end
49
- end
50
- super(method, *args, &block)
51
- end
52
-
53
- protected
54
- def mail
55
- Gossiper::Mailer.mail_for(self)
56
- end
57
-
58
- def update_delivered_at!
59
- self.delivered_at = Time.now
60
- save!
61
- end
62
-
3
+ include Gossiper::Concerns::Models::Notification
63
4
  end
64
5
  end
@@ -1,5 +1,5 @@
1
1
  class AddDataToNotifications < ActiveRecord::Migration
2
2
  def change
3
- add_column :gossiper_notifications, :data, :test
3
+ add_column :gossiper_notifications, :data, :text
4
4
  end
5
5
  end
@@ -0,0 +1,76 @@
1
+ module Gossiper
2
+ module Concerns
3
+ module Decorators
4
+ module Notification
5
+ extend ActiveSupport::Concern
6
+
7
+ included do
8
+ attr_reader :notification
9
+ end
10
+
11
+ def initialize(notification)
12
+ @notification = notification
13
+ end
14
+
15
+ def method_missing(method, *args, &block)
16
+ notification.send(method, *args, &block)
17
+ end
18
+
19
+ def respond_to?(method)
20
+ notification.respond_to?(method)
21
+ end
22
+
23
+ def kind
24
+ t("gossiper.notifications.#{notification.kind}.title",
25
+ default: notification.kind.titleize
26
+ )
27
+ end
28
+
29
+ def subject
30
+ t("gossiper.notifications.#{notification.kind}.subject",
31
+ default: kind
32
+ )
33
+ end
34
+
35
+ def status
36
+ t("gossiper.notifications.status.#{notification.status}")
37
+ end
38
+
39
+ def read?
40
+ t(notification.read?.to_s)
41
+ end
42
+
43
+ def email
44
+ notification.user.email
45
+ end
46
+ alias_method :to, :email
47
+
48
+ def delivered_at
49
+ decorate_date(notification.delivered_at)
50
+ end
51
+
52
+ def created_at
53
+ decorate_date(notification.created_at)
54
+ end
55
+
56
+ def updated_at
57
+ decorate_date(notification.updated_at)
58
+ end
59
+
60
+ def email_object
61
+ @email_object ||= Mailer.mail_for(notification)
62
+ end
63
+
64
+ private
65
+
66
+ def t(*args)
67
+ I18n.t(*args)
68
+ end
69
+
70
+ def decorate_date(date)
71
+ I18n.l(date, format: :short) if date
72
+ end
73
+ end
74
+ end
75
+ end
76
+ end
@@ -0,0 +1,73 @@
1
+ module Gossiper
2
+ module Concerns
3
+ module Models
4
+ module Notification
5
+ extend ActiveSupport::Concern
6
+
7
+ STATUSES = %w(pending delivered)
8
+
9
+ included do
10
+ serialize :data, JSON
11
+ validates :kind, presence: true
12
+ belongs_to :user, polymorphic: true
13
+ end
14
+
15
+ def status
16
+ read_attribute(:status).presence || STATUSES.first
17
+ end
18
+
19
+ def data
20
+ read_attribute(:data).presence || {}
21
+ end
22
+
23
+ def deliver
24
+ mail.deliver
25
+ update_delivered_at!
26
+ end
27
+
28
+ def deliver!
29
+ mail.deliver!
30
+ update_delivered_at!
31
+ end
32
+
33
+ def kind=(value)
34
+ value = value.present? ? value.parameterize.underscore : nil
35
+ write_attribute(:kind, value)
36
+ end
37
+
38
+ def config
39
+ begin
40
+ klass = "Notifications::#{kind.classify}Notification"
41
+ klass.constantize.new(self)
42
+ rescue NameError
43
+ klass = Gossiper.configuration.default_notification_config_class
44
+ klass.constantize.new(self)
45
+ end
46
+ end
47
+
48
+ def method_missing(method, *args, &block)
49
+ STATUSES.each do |status|
50
+ if method.to_s == "#{status}?"
51
+ return self.status == status
52
+ end
53
+ end
54
+ super(method, *args, &block)
55
+ end
56
+
57
+ protected
58
+ def mail
59
+ Gossiper::Mailer.mail_for(self)
60
+ end
61
+
62
+ def update_delivered_at!
63
+ self.delivered_at = Time.now
64
+ save!
65
+ end
66
+
67
+
68
+
69
+
70
+ end
71
+ end
72
+ end
73
+ end
@@ -1,70 +1,5 @@
1
1
  module Gossiper
2
2
  class NotificationDecorator
3
-
4
- attr_reader :notification
5
-
6
- def initialize(notification)
7
- @notification = notification
8
- end
9
-
10
- def method_missing(method, *args, &block)
11
- notification.send(method, *args, &block)
12
- end
13
-
14
- def respond_to?(method)
15
- notification.respond_to?(method)
16
- end
17
-
18
- def kind
19
- t("gossiper.notifications.#{notification.kind}.title",
20
- default: notification.kind.titleize
21
- )
22
- end
23
-
24
- def subject
25
- t("gossiper.notifications.#{notification.kind}.subject",
26
- default: kind
27
- )
28
- end
29
-
30
- def status
31
- t("gossiper.notifications.status.#{notification.status}")
32
- end
33
-
34
- def read?
35
- t(notification.read?.to_s)
36
- end
37
-
38
- def email
39
- notification.user.email
40
- end
41
- alias_method :to, :email
42
-
43
- def delivered_at
44
- decorate_date(notification.delivered_at)
45
- end
46
-
47
- def created_at
48
- decorate_date(notification.created_at)
49
- end
50
-
51
- def updated_at
52
- decorate_date(notification.updated_at)
53
- end
54
-
55
- def email_object
56
- @email_object ||= Mailer.mail_for(notification)
57
- end
58
-
59
- private
60
-
61
- def t(*args)
62
- I18n.t(*args)
63
- end
64
-
65
- def decorate_date(date)
66
- I18n.l(date, format: :short) if date
67
- end
68
-
3
+ include Gossiper::Concerns::Decorators::Notification
69
4
  end
70
5
  end
@@ -1,3 +1,3 @@
1
1
  module Gossiper
2
- VERSION = "0.3.5"
2
+ VERSION = "0.3.6"
3
3
  end
data/lib/gossiper.rb CHANGED
@@ -1,4 +1,6 @@
1
1
  require "gossiper/engine"
2
+ require "gossiper/concerns/models/notification"
3
+ require "gossiper/concerns/decorators/notification"
2
4
  require "gossiper/email_config"
3
5
  require "gossiper/mailer"
4
6
  require "gossiper/configuration"
metadata CHANGED
@@ -1,15 +1,71 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: gossiper
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.3.5
4
+ version: 0.3.6
5
5
  platform: ruby
6
6
  authors:
7
7
  - Marcelo Jacobus
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2013-12-15 00:00:00.000000000 Z
11
+ date: 2014-03-03 00:00:00.000000000 Z
12
12
  dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: therubyracer
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - '>='
18
+ - !ruby/object:Gem::Version
19
+ version: '0'
20
+ type: :runtime
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - '>='
25
+ - !ruby/object:Gem::Version
26
+ version: '0'
27
+ - !ruby/object:Gem::Dependency
28
+ name: less-rails
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - '>='
32
+ - !ruby/object:Gem::Version
33
+ version: '0'
34
+ type: :runtime
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - '>='
39
+ - !ruby/object:Gem::Version
40
+ version: '0'
41
+ - !ruby/object:Gem::Dependency
42
+ name: twitter-bootstrap-rails
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - '>='
46
+ - !ruby/object:Gem::Version
47
+ version: '0'
48
+ type: :runtime
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - '>='
53
+ - !ruby/object:Gem::Version
54
+ version: '0'
55
+ - !ruby/object:Gem::Dependency
56
+ name: kaminari
57
+ requirement: !ruby/object:Gem::Requirement
58
+ requirements:
59
+ - - '>='
60
+ - !ruby/object:Gem::Version
61
+ version: '0'
62
+ type: :runtime
63
+ prerelease: false
64
+ version_requirements: !ruby/object:Gem::Requirement
65
+ requirements:
66
+ - - '>='
67
+ - !ruby/object:Gem::Version
68
+ version: '0'
13
69
  - !ruby/object:Gem::Dependency
14
70
  name: sqlite3
15
71
  requirement: !ruby/object:Gem::Requirement
@@ -163,6 +219,8 @@ files:
163
219
  - lib/tasks/gossiper_tasks.rake
164
220
  - lib/gossiper/email_config.rb
165
221
  - lib/gossiper/engine.rb
222
+ - lib/gossiper/concerns/decorators/notification.rb
223
+ - lib/gossiper/concerns/models/notification.rb
166
224
  - lib/gossiper/mailer.rb
167
225
  - lib/gossiper/notification_decorator.rb
168
226
  - lib/gossiper/configuration.rb