Class: Pose::Word
- Inherits:
-
ActiveRecord::Base
- Object
- ActiveRecord::Base
- Pose::Word
- Defined in:
- lib/pose/word.rb
Class Method Summary collapse
-
.factory(texts) ⇒ Object
Returns the Pose::Word instances with the given texts.
- .remove_unused_words(progress_bar = nil) ⇒ Object
Class Method Details
.factory(texts) ⇒ Object
Returns the Pose::Word instances with the given texts.
11 12 13 |
# File 'lib/pose/word.rb', line 11 def self.factory texts texts.map {|text| Word.find_or_create_by text: text} end |
.remove_unused_words(progress_bar = nil) ⇒ Object
16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 |
# File 'lib/pose/word.rb', line 16 def self.remove_unused_words = nil if Pose.has_sql_connection? # SQL database --> use an optimized query. Word.select("pose_words.id"). joins("LEFT OUTER JOIN pose_assignments ON pose_assignments.word_id = pose_words.id"). group("pose_words.id"). having("COUNT(pose_assignments.id) = 0"). delete_all else # Unknown database --> use metawhere. Word.select(:id).includes(:assignments).find_each(batch_size: 100) do |word| word.delete if word.assignments.size.zero? .try(:increment) end end end |