Class: WatchedWordGroup

Inherits:
ActiveRecord::Base
  • Object
show all
Defined in:
app/models/watched_word_group.rb

Instance Method Summary collapse

Instance Method Details

#action_log_detailsObject



27
28
29
# File 'app/models/watched_word_group.rb', line 27

def action_log_details
  "#{WatchedWord.actions.key(self.action)}#{watched_words.pluck(:word).join(", ")}"
end

#create_or_update_members(words, params) ⇒ Object



14
15
16
17
18
19
20
21
22
23
24
25
# File 'app/models/watched_word_group.rb', line 14

def create_or_update_members(words, params)
  WatchedWordGroup.transaction do
    self.action = WatchedWord.actions[params[:action_key].to_sym]

    words.each do |word|
      watched_word = WatchedWord.create_or_update_word(params.merge(word: word))
      self.watched_words << watched_word
    end

    self.save!
  end
end

#watched_words_validationObject



9
10
11
12
# File 'app/models/watched_word_group.rb', line 9

def watched_words_validation
  watched_words.each { |word| errors.merge!(word.errors) }
  errors.add(:watched_words, :empty) if watched_words.empty?
end