user_notification 0.0.1 → 0.0.2

Sign up to get free protection for your applications and to get access to all the features.
Files changed (30) hide show
  1. checksums.yaml +4 -4
  2. data/lib/generators/user_notification/migration/templates/migration.rb +3 -3
  3. data/lib/user_notification.rb +4 -4
  4. data/lib/user_notification/actions/creation.rb +2 -2
  5. data/lib/user_notification/actions/destruction.rb +2 -2
  6. data/lib/user_notification/actions/update.rb +2 -2
  7. data/lib/user_notification/common.rb +11 -11
  8. data/lib/user_notification/models/{trackable.rb → notifiable.rb} +3 -3
  9. data/lib/user_notification/orm/active_record.rb +1 -1
  10. data/lib/user_notification/orm/active_record/activist.rb +10 -6
  11. data/lib/user_notification/orm/active_record/adapter.rb +3 -3
  12. data/lib/user_notification/orm/active_record/{trackable.rb → notifiable.rb} +5 -5
  13. data/lib/user_notification/orm/active_record/notification.rb +2 -2
  14. data/lib/user_notification/orm/mongo_mapper.rb +1 -1
  15. data/lib/user_notification/orm/mongo_mapper/activist.rb +8 -4
  16. data/lib/user_notification/orm/mongo_mapper/adapter.rb +3 -3
  17. data/lib/user_notification/orm/mongo_mapper/{trackable.rb → notifiable.rb} +2 -2
  18. data/lib/user_notification/orm/mongo_mapper/notification.rb +1 -1
  19. data/lib/user_notification/orm/mongoid.rb +1 -1
  20. data/lib/user_notification/orm/mongoid/activist.rb +8 -4
  21. data/lib/user_notification/orm/mongoid/adapter.rb +3 -3
  22. data/lib/user_notification/orm/mongoid/{trackable.rb → notifiable.rb} +2 -2
  23. data/lib/user_notification/orm/mongoid/notification.rb +1 -1
  24. data/lib/user_notification/roles/{tracked.rb → acts_as_notifiable.rb} +13 -13
  25. data/lib/user_notification/version.rb +1 -1
  26. data/test/migrations/001_create_notifications.rb +3 -3
  27. data/test/test_activist.rb +5 -5
  28. data/test/{test_tracking.rb → test_acts_as_notifiable.rb} +26 -26
  29. data/test/test_helper.rb +3 -3
  30. metadata +9 -9
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: e1c901c8b0055869556adb983350a2269ca0e3f6
4
- data.tar.gz: ad1401b517003379e34d48742132287cee17de93
3
+ metadata.gz: 09b3f9590fbbd4271b1d11dd03ad86ab3da3d12c
4
+ data.tar.gz: d4c0b7fef0be3148aa15ac838eb1302016073b37
5
5
  SHA512:
6
- metadata.gz: 30f2acc2a7562ad950d7336fa5046ccd932c4908668d0c8715d4f6fc851c00d97015db08e352e464beb1ba07eddf56f585c1e6b2c45735036df7b15602230fbf
7
- data.tar.gz: f3a169119d6080443fb38ccfc69f161c76561c38ef46b19bc861db2e193d5b8092bb4eacb809bd5a6337c711c73c6d9f142ca85c6210a141ae457c2e408bd9a1
6
+ metadata.gz: f4d6e59a0f871eb942c783499100804c5c05f5a322b2dd24668668a0235a536e87128cea6225125324f1305f819f49e97f07e3b3a780fecabed064017817b7f3
7
+ data.tar.gz: 6233c4819bc17b4947c28929c7b14ae1d7a9dfce05ade9cd7354b7cfda67af7030b33f30eb13c10ab767a38ea1d5991616dbade951beefc952b9fefd5ecda918
@@ -3,17 +3,17 @@ class CreateNotifications < ActiveRecord::Migration
3
3
  # Create table
4
4
  def self.up
5
5
  create_table :notifications do |t|
6
- t.belongs_to :trackable, :polymorphic => true
6
+ t.belongs_to :notifiable, :polymorphic => true
7
7
  t.belongs_to :owner, :polymorphic => true
8
8
  t.string :key
9
9
  t.text :parameters
10
10
  t.belongs_to :recipient, :polymorphic => true
11
- t.boolwan :read, default: false
11
+ t.boolean :read, default: false
12
12
 
13
13
  t.timestamps
14
14
  end
15
15
 
16
- add_index :notifications, [:trackable_id, :trackable_type]
16
+ add_index :notifications, [:notifiable_id, :notifiable_type]
17
17
  add_index :notifications, [:owner_id, :owner_type]
18
18
  add_index :notifications, [:recipient_id, :recipient_type]
19
19
  end
@@ -3,7 +3,7 @@ require 'action_view'
3
3
  # +user_notification+ keeps track of changes made to models
4
4
  # and allows you to display them to the users.
5
5
  #
6
- # Check {UserNotification::Tracked::ClassMethods#tracked} for more details about customizing and specifying
6
+ # Check {UserNotification::Notifiable::ClassMethods#notifiable} for more details about customizing and specifying
7
7
  # ownership to users.
8
8
  module UserNotification
9
9
  extend ActiveSupport::Concern
@@ -12,14 +12,14 @@ module UserNotification
12
12
  autoload :Notification, 'user_notification/models/notification'
13
13
  autoload :Activist, 'user_notification/models/activist'
14
14
  autoload :Adapter, 'user_notification/models/adapter'
15
- autoload :Trackable, 'user_notification/models/trackable'
15
+ autoload :Notifiable, 'user_notification/models/notifiable'
16
16
  autoload :Common
17
17
  autoload :Config
18
18
  autoload :Creation, 'user_notification/actions/creation.rb'
19
19
  autoload :Deactivatable,'user_notification/roles/deactivatable.rb'
20
20
  autoload :Destruction, 'user_notification/actions/destruction.rb'
21
21
  autoload :Renderable
22
- autoload :Tracked, 'user_notification/roles/tracked.rb'
22
+ autoload :ActsAsNotifiable, 'user_notification/roles/acts_as_notifiable.rb'
23
23
  autoload :Update, 'user_notification/actions/update.rb'
24
24
  autoload :VERSION
25
25
 
@@ -58,7 +58,7 @@ module UserNotification
58
58
  included do
59
59
  include Common
60
60
  include Deactivatable
61
- include Tracked
61
+ include ActsAsNotifiable
62
62
  include Activist # optional associations by recipient|owner
63
63
  end
64
64
  end
@@ -1,5 +1,5 @@
1
1
  module UserNotification
2
- # Handles creation of Activities upon destruction and update of tracked model.
2
+ # Handles creation of Activities upon destruction and update of notifiable model.
3
3
  module Creation
4
4
  extend ActiveSupport::Concern
5
5
 
@@ -7,7 +7,7 @@ module UserNotification
7
7
  after_create :notification_on_create
8
8
  end
9
9
  private
10
- # Creates notification upon creation of the tracked model
10
+ # Creates notification upon creation of the notifiable model
11
11
  def notification_on_create
12
12
  create_notification(:create)
13
13
  end
@@ -1,5 +1,5 @@
1
1
  module UserNotification
2
- # Handles creation of Activities upon destruction of tracked model.
2
+ # Handles creation of Activities upon destruction of notifiable model.
3
3
  module Destruction
4
4
  extend ActiveSupport::Concern
5
5
 
@@ -7,7 +7,7 @@ module UserNotification
7
7
  before_destroy :notification_on_destroy
8
8
  end
9
9
  private
10
- # Records an notification upon destruction of the tracked model
10
+ # Records an notification upon destruction of the notifiable model
11
11
  def notification_on_destroy
12
12
  create_notification(:destroy)
13
13
  end
@@ -1,5 +1,5 @@
1
1
  module UserNotification
2
- # Handles creation of Activities upon destruction and update of tracked model.
2
+ # Handles creation of Activities upon destruction and update of notifiable model.
3
3
  module Update
4
4
  extend ActiveSupport::Concern
5
5
 
@@ -7,7 +7,7 @@ module UserNotification
7
7
  after_update :notification_on_update
8
8
  end
9
9
  private
10
- # Creates notification upon modification of the tracked model
10
+ # Creates notification upon modification of the notifiable model
11
11
  def notification_on_update
12
12
  create_notification(:update)
13
13
  end
@@ -22,7 +22,7 @@ module UserNotification
22
22
  extend ActiveSupport::Concern
23
23
 
24
24
  included do
25
- include Trackable
25
+ include Notifiable
26
26
  class_attribute :notification_owner_global, :notification_recipient_global,
27
27
  :notification_params_global, :notification_hooks, :notification_custom_fields_global
28
28
  set_user_notification_class_defaults
@@ -134,11 +134,11 @@ module UserNotification
134
134
  end
135
135
 
136
136
  # Extracts a hook from the _:on_ option provided in
137
- # {Tracked::ClassMethods#tracked}. Returns nil when no hook exists for
137
+ # {Notifiable::ClassMethods#notifiable}. Returns nil when no hook exists for
138
138
  # given action
139
139
  # {Common#get_hook}
140
140
  #
141
- # @see Tracked#get_hook
141
+ # @see Notifiable#get_hook
142
142
  # @param key [String, Symbol] action to retrieve a hook for
143
143
  # @return [Proc, nil] callable hook or nil
144
144
  # @since 0.4.0
@@ -196,7 +196,7 @@ module UserNotification
196
196
  # current_user.create_notification(:avatar_changed)
197
197
  #
198
198
  # It will still gather data from any procs or symbols you passed as params
199
- # to {Tracked::ClassMethods#tracked}. It will ask the hooks you defined
199
+ # to {Notifiable::ClassMethods#notifiable}. It will ask the hooks you defined
200
200
  # whether to really save this notification.
201
201
  #
202
202
  # But you can also overwrite instance and global settings with your options:
@@ -221,9 +221,9 @@ module UserNotification
221
221
  # @article.create_notification :commented_on
222
222
  # @article.notifications.last.key # => "article.commented_on"
223
223
  #
224
- # For other parameters, see {Tracked#notification}, and "Instance options"
225
- # accessors at {Tracked}, information on hooks is available at
226
- # {Tracked::ClassMethods#tracked}.
224
+ # For other parameters, see {Notifiable#notification}, and "Instance options"
225
+ # accessors at {Notifiable}, information on hooks is available at
226
+ # {Notifiable::ClassMethods#notifiable}.
227
227
  # @see #prepare_settings
228
228
  # @return [Model, nil] If created successfully, new notification
229
229
  # @since 0.4.0
@@ -231,14 +231,14 @@ module UserNotification
231
231
  # @overload create_notification(action, options = {})
232
232
  # @param [Symbol,String] action Name of the action
233
233
  # @param [Hash] options Options with quality higher than instance options
234
- # set in {Tracked#notification}
234
+ # set in {Notifiable#notification}
235
235
  # @option options [Activist] :owner Owner
236
236
  # @option options [Activist] :recipient Recipient
237
237
  # @option options [Hash] :params Parameters, see
238
238
  # {UserNotification.resolve_value}
239
239
  # @overload create_notification(options = {})
240
240
  # @param [Hash] options Options with quality higher than instance options
241
- # set in {Tracked#notification}
241
+ # set in {Notifiable#notification}
242
242
  # @option options [Symbol,String] :action Name of the action
243
243
  # @option options [String] :key Full key
244
244
  # @option options [Activist] :owner Owner
@@ -258,8 +258,8 @@ module UserNotification
258
258
  end
259
259
 
260
260
  # Prepares settings used during creation of Notification record.
261
- # params passed directly to tracked model have priority over
262
- # settings specified in tracked() method
261
+ # params passed directly to notifiable model have priority over
262
+ # settings specified in notifiable() method
263
263
  #
264
264
  # @see #create_notification
265
265
  # @return [Hash] Settings with preserved options that were passed
@@ -1,9 +1,9 @@
1
1
  module UserNotification
2
- # Provides association for notifications bound to this object by *trackable*.
3
- module Trackable
2
+ # Provides association for notifications bound to this object by *notifiable*.
3
+ module Notifiable
4
4
  # Delegates to ORM.
5
5
  def self.included(base)
6
- base.extend UserNotification::inherit_orm("Trackable")
6
+ base.extend UserNotification::inherit_orm("Notifiable")
7
7
  end
8
8
  end
9
9
  end
@@ -2,4 +2,4 @@ require 'active_record'
2
2
  require_relative 'active_record/notification.rb'
3
3
  require_relative 'active_record/adapter.rb'
4
4
  require_relative 'active_record/activist.rb'
5
- require_relative 'active_record/trackable.rb'
5
+ require_relative 'active_record/notifiable.rb'
@@ -5,8 +5,8 @@ module UserNotification
5
5
  module Activist
6
6
  extend ActiveSupport::Concern
7
7
 
8
- # Loads the {ClassMethods#activist} method for declaring the class
9
- # as an activist.
8
+ # Loads the {ClassMethods#acts_as_activist} method for declaring the class
9
+ # as an acts_as_activist.
10
10
  def self.extended(base)
11
11
  base.extend(ClassMethods)
12
12
  end
@@ -17,20 +17,20 @@ module UserNotification
17
17
  # Adds ActiveRecord associations to model to simplify fetching
18
18
  # so you can list notifications performed by the owner.
19
19
  # It is completely optional. Any model can be an owner to an notification
20
- # even without being an explicit activist.
20
+ # even without being an explicit acts_as_activist.
21
21
  #
22
22
  # == Usage:
23
23
  # In model:
24
24
  #
25
25
  # class User < ActiveRecord::Base
26
26
  # include UserNotification::Model
27
- # activist
27
+ # acts_as_activist
28
28
  # end
29
29
  #
30
30
  # In controller:
31
31
  # User.first.notifications
32
32
  #
33
- def activist
33
+ def acts_as_activist
34
34
  # Association of notifications as their owner.
35
35
  # @!method notifications_as_owner
36
36
  # @return [Array<Notification>] Activities which self is the owner of.
@@ -39,7 +39,11 @@ module UserNotification
39
39
  # Association of notifications as their recipient.
40
40
  # @!method notifications_as_recipient
41
41
  # @return [Array<Notification>] Activities which self is the recipient of.
42
- has_many :notifications_as_recipient, :class_name => "::UserNotification::Notification", :as => :recipient
42
+ has_many :notifications_as_recipient, :class_name => "::UserNotification::Notification", :as => :recipient do
43
+ def unread
44
+ where(read: false)
45
+ end
46
+ end
43
47
  end
44
48
  end
45
49
  end
@@ -6,9 +6,9 @@ module UserNotification
6
6
  # Provides ActiveRecord specific, database-related routines for use by
7
7
  # UserNotification.
8
8
  class Adapter
9
- # Creates the notification on `trackable` with `options`
10
- def self.create_notification(trackable, options)
11
- trackable.notifications.create options
9
+ # Creates the notification on `notifiable` with `options`
10
+ def self.create_notification(notifiable, options)
11
+ notifiable.notifications.create options
12
12
  end
13
13
  end
14
14
  end
@@ -1,13 +1,13 @@
1
1
  module UserNotification
2
2
  module ORM
3
3
  module ActiveRecord
4
- # Implements {UserNotification::Trackable} for ActiveRecord
5
- # @see UserNotification::Trackable
6
- module Trackable
7
- # Creates an association for notifications where self is the *trackable*
4
+ # Implements {UserNotification::Notifiable} for ActiveRecord
5
+ # @see UserNotification::Notifiable
6
+ module Notifiable
7
+ # Creates an association for notifications where self is the *notifiable*
8
8
  # object.
9
9
  def self.extended(base)
10
- base.has_many :notifications, :class_name => "::UserNotification::Notification", :as => :trackable
10
+ base.has_many :notifications, :class_name => "::UserNotification::Notification", :as => :notifiable
11
11
  end
12
12
  end
13
13
  end
@@ -7,7 +7,7 @@ module UserNotification
7
7
  include Renderable
8
8
 
9
9
  # Define polymorphic association to the parent
10
- belongs_to :trackable, :polymorphic => true
10
+ belongs_to :notifiable, :polymorphic => true
11
11
  # Define ownership to a resource responsible for this notification
12
12
  belongs_to :owner, :polymorphic => true
13
13
  # Define ownership to a resource targeted by this notification
@@ -16,7 +16,7 @@ module UserNotification
16
16
  serialize :parameters, Hash
17
17
 
18
18
  if ::ActiveRecord::VERSION::MAJOR < 4
19
- attr_accessible :key, :owner, :parameters, :recipient, :trackable
19
+ attr_accessible :key, :owner, :parameters, :recipient, :notifiable
20
20
  end
21
21
  end
22
22
  end
@@ -1,4 +1,4 @@
1
1
  require_relative "mongo_mapper/notification.rb"
2
2
  require_relative "mongo_mapper/adapter.rb"
3
3
  require_relative "mongo_mapper/activist.rb"
4
- require_relative "mongo_mapper/trackable.rb"
4
+ require_relative "mongo_mapper/notifiable.rb"
@@ -21,7 +21,7 @@ module UserNotification
21
21
  # Adds MongoMapper associations to model to simplify fetching
22
22
  # so you can list notifications performed by the owner.
23
23
  # It is completely optional. Any model can be an owner to an notification
24
- # even without being an explicit activist.
24
+ # even without being an explicit acts_as_activist.
25
25
  #
26
26
  # == Usage:
27
27
  # In model:
@@ -29,15 +29,19 @@ module UserNotification
29
29
  # class User
30
30
  # include MongoMapper::Document
31
31
  # include UserNotification::Model
32
- # activist
32
+ # acts_as_activist
33
33
  # end
34
34
  #
35
35
  # In controller:
36
36
  # User.first.notifications
37
37
  #
38
- def activist
38
+ def acts_as_activist
39
39
  many :notifications_as_owner, :class_name => "::UserNotification::Notification", :as => :owner
40
- many :notifications_as_recipient, :class_name => "::UserNotification::Notification", :as => :recipient
40
+ many :notifications_as_recipient, :class_name => "::UserNotification::Notification", :as => :recipient do
41
+ def unread
42
+ where(read: false)
43
+ end
44
+ end
41
45
  end
42
46
  end
43
47
  end
@@ -2,9 +2,9 @@ module UserNotification
2
2
  module ORM
3
3
  module MongoMapper
4
4
  class Adapter
5
- # Creates the notification on `trackable` with `options`
6
- def self.create_notification(trackable, options)
7
- trackable.notifications.create options
5
+ # Creates the notification on `notifiable` with `options`
6
+ def self.create_notification(notifiable, options)
7
+ notifiable.notifications.create options
8
8
  end
9
9
  end
10
10
  end
@@ -1,9 +1,9 @@
1
1
  module UserNotification
2
2
  module ORM
3
3
  module MongoMapper
4
- module Trackable
4
+ module Notifiable
5
5
  def self.extended(base)
6
- base.many :notifications, :class_name => "::UserNotification::Notification", order: :created_at.asc, :as => :trackable
6
+ base.many :notifications, :class_name => "::UserNotification::Notification", order: :created_at.asc, :as => :notifiable
7
7
  end
8
8
  end
9
9
  end
@@ -17,7 +17,7 @@ module UserNotification
17
17
  end
18
18
 
19
19
  # Define polymorphic association to the parent
20
- belongs_to :trackable, polymorphic: true
20
+ belongs_to :notifiable, polymorphic: true
21
21
  # Define ownership to a resource responsible for this notification
22
22
  belongs_to :owner, polymorphic: true
23
23
  # Define ownership to a resource targeted by this notification
@@ -1,4 +1,4 @@
1
1
  require_relative "mongoid/notification.rb"
2
2
  require_relative "mongoid/adapter.rb"
3
3
  require_relative "mongoid/activist.rb"
4
- require_relative "mongoid/trackable.rb"
4
+ require_relative "mongoid/notifiable.rb"
@@ -21,22 +21,26 @@ module UserNotification
21
21
  # Adds ActiveRecord associations to model to simplify fetching
22
22
  # so you can list notifications performed by the owner.
23
23
  # It is completely optional. Any model can be an owner to an notification
24
- # even without being an explicit activist.
24
+ # even without being an explicit acts_as_activist.
25
25
  #
26
26
  # == Usage:
27
27
  # In model:
28
28
  #
29
29
  # class User < ActiveRecord::Base
30
30
  # include UserNotification::Model
31
- # activist
31
+ # acts_as_activist
32
32
  # end
33
33
  #
34
34
  # In controller:
35
35
  # User.first.notifications
36
36
  #
37
- def activist
37
+ def acts_as_activist
38
38
  has_many :notifications_as_owner, :class_name => "::UserNotification::Notification", :inverse_of => :owner
39
- has_many :notifications_as_recipient, :class_name => "::UserNotification::Notification", :inverse_of => :recipient
39
+ has_many :notifications_as_recipient, :class_name => "::UserNotification::Notification", :inverse_of => :recipient do
40
+ def unread
41
+ where(read: false)
42
+ end
43
+ end
40
44
  end
41
45
  end
42
46
  end
@@ -2,9 +2,9 @@ module UserNotification
2
2
  module ORM
3
3
  module Mongoid
4
4
  class Adapter
5
- # Creates the notification on `trackable` with `options`
6
- def self.create_notification(trackable, options)
7
- trackable.notifications.create options
5
+ # Creates the notification on `notifiable` with `options`
6
+ def self.create_notification(notifiable, options)
7
+ notifiable.notifications.create options
8
8
  end
9
9
  end
10
10
  end
@@ -1,9 +1,9 @@
1
1
  module UserNotification
2
2
  module ORM
3
3
  module Mongoid
4
- module Trackable
4
+ module Notifiable
5
5
  def self.extended(base)
6
- base.has_many :notifications, :class_name => "::UserNotification::Notification", :as => :trackable
6
+ base.has_many :notifications, :class_name => "::UserNotification::Notification", :as => :notifiable
7
7
  end
8
8
  end
9
9
  end
@@ -12,7 +12,7 @@ module UserNotification
12
12
  include Renderable
13
13
 
14
14
  # Define polymorphic association to the parent
15
- belongs_to :trackable, polymorphic: true
15
+ belongs_to :notifiable, polymorphic: true
16
16
  # Define ownership to a resource responsible for this notification
17
17
  belongs_to :owner, polymorphic: true
18
18
  # Define ownership to a resource targeted by this notification
@@ -1,6 +1,6 @@
1
1
  module UserNotification
2
2
  # Main module extending classes we want to keep track of.
3
- module Tracked
3
+ module ActsAsNotifiable
4
4
  extend ActiveSupport::Concern
5
5
  # A shortcut method for setting custom key, owner and parameters of {Notification}
6
6
  # in one line. Accepts a hash with 3 keys:
@@ -25,7 +25,7 @@ module UserNotification
25
25
  # @article.notifications.last.key #=> "my.custom.article.key"
26
26
  # @article.notifications.last.parameters #=> {:title => "New article"}
27
27
  #
28
- # @param options [Hash] instance options to set on the tracked model
28
+ # @param options [Hash] instance options to set on the notifiable model
29
29
  # @return [nil]
30
30
  def notification(options = {})
31
31
  rest = options.clone
@@ -37,10 +37,10 @@ module UserNotification
37
37
  nil
38
38
  end
39
39
 
40
- # Module with basic +tracked+ method that enables tracking models.
40
+ # Module with basic +acts_as_notifiable+ method that enables tracking models.
41
41
  module ClassMethods
42
42
  # Adds required callbacks for creating and updating
43
- # tracked models and adds +notifications+ relation for listing
43
+ # acts_as_notifiable models and adds +notifications+ relation for listing
44
44
  # associated notifications.
45
45
  #
46
46
  # == Parameters:
@@ -49,8 +49,8 @@ module UserNotification
49
49
  # It can be a Proc, Symbol or an ActiveRecord object:
50
50
  # == Examples:
51
51
  #
52
- # tracked :owner => :author
53
- # tracked :owner => proc {|o| o.author}
52
+ # acts_as_notifiable :owner => :author
53
+ # acts_as_notifiable :owner => proc {|o| o.author}
54
54
  #
55
55
  # Keep in mind that owner relation is polymorphic, so you can't just
56
56
  # provide id number of the owner object.
@@ -59,8 +59,8 @@ module UserNotification
59
59
  # It can be a Proc, Symbol, or an ActiveRecord object
60
60
  # == Examples:
61
61
  #
62
- # tracked :recipient => :author
63
- # tracked :recipient => proc {|o| o.author}
62
+ # acts_as_notifiable :recipient => :author
63
+ # acts_as_notifiable :recipient => proc {|o| o.author}
64
64
  #
65
65
  # Keep in mind that recipient relation is polymorphic, so you can't just
66
66
  # provide id number of the owner object.
@@ -70,7 +70,7 @@ module UserNotification
70
70
  # == Example:
71
71
  # class Article < ActiveRecord::Base
72
72
  # include UserNotification::Model
73
- # tracked :params => {
73
+ # acts_as_notifiable :params => {
74
74
  # :title => :title,
75
75
  # :author_name => "Michael",
76
76
  # :category_name => proc {|controller, model_instance| model_instance.category.name},
@@ -79,7 +79,7 @@ module UserNotification
79
79
  # end
80
80
  #
81
81
  # Values in the :params hash can either be an *exact* *value*, a *Proc/Lambda* executed before saving the notification or a *Symbol*
82
- # which is a an attribute or a method name executed on the tracked model's instance.
82
+ # which is a an attribute or a method name executed on the acts_as_notifiable model's instance.
83
83
  #
84
84
  # Everything specified here has a lower priority than parameters
85
85
  # specified directly in {#notification} method.
@@ -95,7 +95,7 @@ module UserNotification
95
95
  # * _:update_
96
96
  # * _:destroy_
97
97
  # Selecting one or more of these will make UserNotification create notifications
98
- # automatically for the tracked model on selected actions.
98
+ # automatically for the acts_as_notifiable model on selected actions.
99
99
  #
100
100
  # Resulting notifications will have have keys assigned to, respectively:
101
101
  # * _article.create_
@@ -123,14 +123,14 @@ module UserNotification
123
123
  #
124
124
  # == Example:
125
125
  # # app/models/article.rb
126
- # tracked :on => {:update => proc {|model, controller| model.published? }}
126
+ # acts_as_notifiable :on => {:update => proc {|model, controller| model.published? }}
127
127
  #
128
128
  # In the example above, given a model Article with boolean column _published_.
129
129
  # The notifications with key _article.update_ will only be created
130
130
  # if the published status is set to true on that article.
131
131
  # @param opts [Hash] options
132
132
  # @return [nil] options
133
- def tracked(opts = {})
133
+ def acts_as_notifiable(opts = {})
134
134
  options = opts.clone
135
135
 
136
136
  all_options = [:create, :update, :destroy]
@@ -1,4 +1,4 @@
1
1
  module UserNotification
2
2
  # A constant with gem's version
3
- VERSION = '0.0.1'
3
+ VERSION = '0.0.2'
4
4
  end
@@ -3,17 +3,17 @@ class CreateNotifications < ActiveRecord::Migration
3
3
  # Create table
4
4
  def self.up
5
5
  create_table :notifications do |t|
6
- t.belongs_to :trackable, :polymorphic => true
6
+ t.belongs_to :notifiable, :polymorphic => true
7
7
  t.belongs_to :owner, :polymorphic => true
8
8
  t.string :key
9
9
  t.text :parameters
10
10
  t.belongs_to :recipient, :polymorphic => true
11
- t.boolwan :read, default: false
11
+ t.boolean :read, default: false
12
12
 
13
13
  t.timestamps
14
14
  end
15
15
 
16
- add_index :notifications, [:trackable_id, :trackable_type]
16
+ add_index :notifications, [:notifiable_id, :notifiable_type]
17
17
  add_index :notifications, [:owner_id, :owner_type]
18
18
  add_index :notifications, [:recipient_id, :recipient_type]
19
19
  end
@@ -3,8 +3,8 @@ require 'test_helper'
3
3
  describe UserNotification::Activist do
4
4
  it 'adds owner association' do
5
5
  klass = article
6
- klass.must_respond_to :activist
7
- klass.activist
6
+ klass.must_respond_to :acts_as_activist
7
+ klass.acts_as_activist
8
8
  klass.new.must_respond_to :notifications
9
9
  case ENV["PA_ORM"]
10
10
  when "active_record"
@@ -28,13 +28,13 @@ describe UserNotification::Activist do
28
28
  class ActivistUser < ActiveRecord::Base
29
29
  include UserNotification::Model
30
30
  self.table_name = 'users'
31
- activist
31
+ acts_as_activist
32
32
  end
33
33
  when :mongoid
34
34
  class ActivistUser
35
35
  include Mongoid::Document
36
36
  include UserNotification::Model
37
- activist
37
+ acts_as_activist
38
38
 
39
39
  field :name, type: String
40
40
  end
@@ -42,7 +42,7 @@ describe UserNotification::Activist do
42
42
  class ActivistUser
43
43
  include MongoMapper::Document
44
44
  include UserNotification::Model
45
- activist
45
+ acts_as_activist
46
46
 
47
47
  key :name, String
48
48
  end
@@ -1,6 +1,6 @@
1
1
  require 'test_helper'
2
2
 
3
- describe UserNotification::Tracked do
3
+ describe UserNotification::ActsAsNotifiable do
4
4
  describe 'defining instance options' do
5
5
  subject { article.new }
6
6
  let :options do
@@ -25,10 +25,10 @@ describe UserNotification::Tracked do
25
25
  specify { notification.recipient.must_equal options[:recipient] }
26
26
  end
27
27
 
28
- it 'can be tracked and be an activist at the same time' do
28
+ it 'can be acts_as_notifiable and be an activist at the same time' do
29
29
  case UserNotification.config.orm
30
30
  when :mongoid
31
- class ActivistAndTrackedArticle
31
+ class ActivistAndNotifiableArticle
32
32
  include Mongoid::Document
33
33
  include Mongoid::Timestamps
34
34
  include UserNotification::Model
@@ -37,11 +37,11 @@ describe UserNotification::Tracked do
37
37
 
38
38
  field :name, type: String
39
39
  field :published, type: Boolean
40
- tracked
41
- activist
40
+ acts_as_notifiable
41
+ acts_as_activist
42
42
  end
43
43
  when :mongo_mapper
44
- class ActivistAndTrackedArticle
44
+ class ActivistAndNotifiableArticle
45
45
  include MongoMapper::Document
46
46
  include UserNotification::Model
47
47
 
@@ -49,16 +49,16 @@ describe UserNotification::Tracked do
49
49
 
50
50
  key :name, String
51
51
  key :published, Boolean
52
- tracked
53
- activist
52
+ acts_as_notifiable
53
+ acts_as_activist
54
54
  timestamps!
55
55
  end
56
56
  when :active_record
57
- class ActivistAndTrackedArticle < ActiveRecord::Base
57
+ class ActivistAndNotifiableArticle < ActiveRecord::Base
58
58
  self.table_name = 'articles'
59
59
  include UserNotification::Model
60
- tracked
61
- activist
60
+ acts_as_notifiable
61
+ acts_as_activist
62
62
 
63
63
  if ::ActiveRecord::VERSION::MAJOR < 4
64
64
  attr_accessible :name, :published, :user
@@ -67,9 +67,9 @@ describe UserNotification::Tracked do
67
67
  end
68
68
  end
69
69
 
70
- art = ActivistAndTrackedArticle.new
70
+ art = ActivistAndNotifiableArticle.new
71
71
  art.save
72
- art.notifications.last.trackable_id.must_equal art.id
72
+ art.notifications.last.notifiable_id.must_equal art.id
73
73
  art.notifications.last.owner_id.must_equal nil
74
74
  end
75
75
 
@@ -159,7 +159,7 @@ describe UserNotification::Tracked do
159
159
  end
160
160
  end
161
161
 
162
- describe '#tracked' do
162
+ describe '#acts_as_notifiable' do
163
163
  subject { article(options) }
164
164
  let(:options) { {} }
165
165
 
@@ -175,7 +175,7 @@ describe UserNotification::Tracked do
175
175
 
176
176
  field :name, type: String
177
177
  field :published, type: Boolean
178
- tracked :skip_defaults => true
178
+ acts_as_notifiable :skip_defaults => true
179
179
  end
180
180
  when :mongo_mapper
181
181
  art = Class.new do
@@ -186,7 +186,7 @@ describe UserNotification::Tracked do
186
186
 
187
187
  key :name, String
188
188
  key :published, Boolean
189
- tracked :skip_defaults => true
189
+ acts_as_notifiable :skip_defaults => true
190
190
 
191
191
  timestamps!
192
192
  end
@@ -232,7 +232,7 @@ describe UserNotification::Tracked do
232
232
 
233
233
  field :name, type: String
234
234
  field :published, type: Boolean
235
- tracked :except => [:create]
235
+ acts_as_notifiable :except => [:create]
236
236
  end
237
237
  when :mongo_mapper
238
238
  art = Class.new do
@@ -243,7 +243,7 @@ describe UserNotification::Tracked do
243
243
 
244
244
  key :name, String
245
245
  key :published, Boolean
246
- tracked :except => [:create]
246
+ acts_as_notifiable :except => [:create]
247
247
 
248
248
  timestamps!
249
249
  end
@@ -269,7 +269,7 @@ describe UserNotification::Tracked do
269
269
  field :name, type: String
270
270
  field :published, type: Boolean
271
271
 
272
- tracked :only => [:create, :update]
272
+ acts_as_notifiable :only => [:create, :update]
273
273
  end
274
274
  when :mongo_mapper
275
275
  art = Class.new do
@@ -281,7 +281,7 @@ describe UserNotification::Tracked do
281
281
  key :name, String
282
282
  key :published, Boolean
283
283
 
284
- tracked :only => [:create, :update]
284
+ acts_as_notifiable :only => [:create, :update]
285
285
  end
286
286
  when :active_record
287
287
  art = article({:only => [:create, :update]})
@@ -294,31 +294,31 @@ describe UserNotification::Tracked do
294
294
 
295
295
  it 'accepts :owner option' do
296
296
  owner = mock('owner')
297
- subject.tracked(:owner => owner)
297
+ subject.acts_as_notifiable(:owner => owner)
298
298
  subject.notification_owner_global.must_equal owner
299
299
  end
300
300
 
301
301
  it 'accepts :params option' do
302
302
  params = {:a => 1}
303
- subject.tracked(:params => params)
303
+ subject.acts_as_notifiable(:params => params)
304
304
  subject.notification_params_global.must_equal params
305
305
  end
306
306
 
307
307
  it 'accepts :on option' do
308
308
  on = {:a => lambda{}, :b => proc {}}
309
- subject.tracked(:on => on)
309
+ subject.acts_as_notifiable(:on => on)
310
310
  subject.notification_hooks.must_equal on
311
311
  end
312
312
 
313
313
  it 'accepts :on option with string keys' do
314
314
  on = {'a' => lambda {}}
315
- subject.tracked(:on => on)
315
+ subject.acts_as_notifiable(:on => on)
316
316
  subject.notification_hooks.must_equal on.symbolize_keys
317
317
  end
318
318
 
319
319
  it 'accepts :on values that are procs' do
320
320
  on = {:unpassable => 1, :proper => lambda {}, :proper_proc => proc {}}
321
- subject.tracked(:on => on)
321
+ subject.acts_as_notifiable(:on => on)
322
322
  subject.notification_hooks.must_include :proper
323
323
  subject.notification_hooks.must_include :proper_proc
324
324
  subject.notification_hooks.wont_include :unpassable
@@ -350,7 +350,7 @@ describe UserNotification::Tracked do
350
350
  end
351
351
 
352
352
  it 'allows hooks to decide if notification should be created' do
353
- subject.tracked
353
+ subject.acts_as_notifiable
354
354
  @article = subject.new(:name => 'Some Name')
355
355
  UserNotification.set_controller(mock('controller'))
356
356
  pf = proc { |model, controller|
data/test/test_helper.rb CHANGED
@@ -30,7 +30,7 @@ when :active_record
30
30
  klass = Class.new(ActiveRecord::Base) do
31
31
  self.table_name = 'articles'
32
32
  include UserNotification::Model
33
- tracked options
33
+ acts_as_notifiable options
34
34
  belongs_to :user
35
35
 
36
36
  def self.name
@@ -78,7 +78,7 @@ when :mongoid
78
78
  def article(options = {})
79
79
  Article.class_eval do
80
80
  set_user_notification_class_defaults
81
- tracked options
81
+ acts_as_notifiable options
82
82
  end
83
83
  Article
84
84
  end
@@ -111,7 +111,7 @@ when :mongo_mapper
111
111
  def article(options = {})
112
112
  Article.class_eval do
113
113
  set_user_notification_class_defaults
114
- tracked options
114
+ acts_as_notifiable options
115
115
  end
116
116
  Article
117
117
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: user_notification
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.1
4
+ version: 0.0.2
5
5
  platform: ruby
6
6
  authors:
7
7
  - Wei Zhu
@@ -10,7 +10,7 @@ authors:
10
10
  autorequire:
11
11
  bindir: bin
12
12
  cert_chain: []
13
- date: 2013-08-25 00:00:00.000000000 Z
13
+ date: 2013-08-26 00:00:00.000000000 Z
14
14
  dependencies:
15
15
  - !ruby/object:Gem::Dependency
16
16
  name: actionpack
@@ -174,26 +174,26 @@ files:
174
174
  - lib/user_notification/config.rb
175
175
  - lib/user_notification/models/activist.rb
176
176
  - lib/user_notification/models/adapter.rb
177
+ - lib/user_notification/models/notifiable.rb
177
178
  - lib/user_notification/models/notification.rb
178
- - lib/user_notification/models/trackable.rb
179
179
  - lib/user_notification/orm/active_record.rb
180
180
  - lib/user_notification/orm/active_record/activist.rb
181
181
  - lib/user_notification/orm/active_record/adapter.rb
182
+ - lib/user_notification/orm/active_record/notifiable.rb
182
183
  - lib/user_notification/orm/active_record/notification.rb
183
- - lib/user_notification/orm/active_record/trackable.rb
184
184
  - lib/user_notification/orm/mongo_mapper.rb
185
185
  - lib/user_notification/orm/mongo_mapper/activist.rb
186
186
  - lib/user_notification/orm/mongo_mapper/adapter.rb
187
+ - lib/user_notification/orm/mongo_mapper/notifiable.rb
187
188
  - lib/user_notification/orm/mongo_mapper/notification.rb
188
- - lib/user_notification/orm/mongo_mapper/trackable.rb
189
189
  - lib/user_notification/orm/mongoid.rb
190
190
  - lib/user_notification/orm/mongoid/activist.rb
191
191
  - lib/user_notification/orm/mongoid/adapter.rb
192
+ - lib/user_notification/orm/mongoid/notifiable.rb
192
193
  - lib/user_notification/orm/mongoid/notification.rb
193
- - lib/user_notification/orm/mongoid/trackable.rb
194
194
  - lib/user_notification/renderable.rb
195
+ - lib/user_notification/roles/acts_as_notifiable.rb
195
196
  - lib/user_notification/roles/deactivatable.rb
196
- - lib/user_notification/roles/tracked.rb
197
197
  - lib/user_notification/utility/store_controller.rb
198
198
  - lib/user_notification/utility/view_helpers.rb
199
199
  - lib/user_notification/version.rb
@@ -208,12 +208,12 @@ files:
208
208
  - test/mongo_mapper.yml
209
209
  - test/mongoid.yml
210
210
  - test/test_activist.rb
211
+ - test/test_acts_as_notifiable.rb
211
212
  - test/test_common.rb
212
213
  - test/test_controller_integration.rb
213
214
  - test/test_generators.rb
214
215
  - test/test_helper.rb
215
216
  - test/test_notification.rb
216
- - test/test_tracking.rb
217
217
  - test/test_view_helpers.rb
218
218
  - test/views/layouts/_notification.erb
219
219
  - test/views/user_notification/_test.erb
@@ -248,12 +248,12 @@ test_files:
248
248
  - test/mongo_mapper.yml
249
249
  - test/mongoid.yml
250
250
  - test/test_activist.rb
251
+ - test/test_acts_as_notifiable.rb
251
252
  - test/test_common.rb
252
253
  - test/test_controller_integration.rb
253
254
  - test/test_generators.rb
254
255
  - test/test_helper.rb
255
256
  - test/test_notification.rb
256
- - test/test_tracking.rb
257
257
  - test/test_view_helpers.rb
258
258
  - test/views/layouts/_notification.erb
259
259
  - test/views/user_notification/_test.erb