Module: Narrator::ModelAdditions
- Includes:
- ActiveSupport::Inflector
- Defined in:
- lib/narrator/model_additions.rb
Instance Method Summary collapse
- #narratable_actor ⇒ Object
- #narratable_model ⇒ Object
-
#track_user_activity(subject_id, subject_class, actor_id, actor_class, target_id, target_class, verb, context) ⇒ Object
Instance Methods.
Instance Method Details
#narratable_actor ⇒ Object
46 47 48 49 50 51 52 53 54 |
# File 'lib/narrator/model_additions.rb', line 46 def narratable_actor ### # Associations ### has_many :activities, as: :actor, class_name: 'Narrator::Activity', dependent: :destroy end |
#narratable_model ⇒ Object
4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 |
# File 'lib/narrator/model_additions.rb', line 4 def narratable_model ### # Includes ### include Narrator::ModelResources ### # Associations ### has_many :activities, as: :subject, class_name: 'Narrator::Activity', dependent: :destroy ### # Instance Methods ### def track_user_activity( subject_id, subject_class, actor_id, actor_class, target_id, target_class, verb, context ) actor = actor_id.blank? ? nil : actor_class.constantize.find_by_id(actor_id) subject = subject_id.blank? ? nil : subject_class.constantize.find_by_id(subject_id) target = target_id.blank? ? nil : target_class.constantize.find_by_id(target_id) Narrator::Activity.create!( owner: nil, subject: subject, actor: actor, target: target, verb: verb, context: context ) end end |
#track_user_activity(subject_id, subject_class, actor_id, actor_class, target_id, target_class, verb, context) ⇒ Object
Instance Methods
22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 |
# File 'lib/narrator/model_additions.rb', line 22 def track_user_activity( subject_id, subject_class, actor_id, actor_class, target_id, target_class, verb, context ) actor = actor_id.blank? ? nil : actor_class.constantize.find_by_id(actor_id) subject = subject_id.blank? ? nil : subject_class.constantize.find_by_id(subject_id) target = target_id.blank? ? nil : target_class.constantize.find_by_id(target_id) Narrator::Activity.create!( owner: nil, subject: subject, actor: actor, target: target, verb: verb, context: context ) end |