Module: NewsFeed::NewsFeedEvents

Defined in:
lib/news_feed/news_feed_events.rb

Instance Method Summary collapse

Instance Method Details

#generate_text(event_name, actor_name, object_class, object_title, recipient_name = nil, options = {}) ⇒ Object



3
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
# File 'lib/news_feed/news_feed_events.rb', line 3

def generate_text(event_name, actor_name, object_class, object_title, recipient_name = nil, options = {})
    # event_name is what the cases will check for
    # actor_name is the user object that performs the action
    # object_class is the class of the object of interest
    # recipient_name can include the recipient name
  
  case event_name
  when :Create
      I18n.t('news_feeds.create_object', actor: actor_name.to_s, object_class: object_class,
      object_name: object_title)
  when :Update
      I18n.t('news_feeds.update_object', actor: actor_name.to_s, object_class: object_class,
      object_name: object_title)
  when :Delete
      I18n.t('news_feeds.delete_object', actor: actor_name.to_s, object_class: object_class,
      object_name: object_title)
  when :Send
      I18n.t('news_feeds.send_object', actor: actor_name.to_s, object_class: object_class,
      object_name: object_title, recipient_name: recipient_name)
  when :Custom
    if options.nil?
      raise "Custom Message must be specified"
    else
      options
    end
  else
    raise "event_name is undefined"
  end
  

end