lib/active_recall/models/deck.rb in active_recall-1.8.4 vs lib/active_recall/models/deck.rb in active_recall-1.8.5

- old
+ new

@@ -7,31 +7,25 @@ self.table_name = "active_recall_decks" belongs_to :user, polymorphic: true has_many :items, class_name: "ActiveRecall::Item", dependent: :destroy def each - _items.each do |item| - if block_given? - yield item - else - yield item - end - end + _items.find_each { |item| yield item } end def ==(other) _items == other end - def _items - source_class.find(items.pluck(:source_id)) - end - def <<(source) - raise ArgumentError, "Word already in the stack" if include?(source) + attributes = {deck: self, source_id: source.id, source_type: source.class.name} - items << ActiveRecall::Item.new(deck: self, source_id: source.id, source_type: source.class.name) + if ActiveRecall::Item.exists?(attributes) + raise ArgumentError, "Word already in the stack" + end + + items << ActiveRecall::Item.new(attributes) end def self.add_deck(user) create!(user) end @@ -69,17 +63,21 @@ def expired source_class.where(id: items.expired.select(:source_id)) end def box(number) - source_class.find(items.where(box: number).pluck(:source_id)) + source_class.where(id: items.where(box: number).select(:source_id)) end def source_class user.deck_name.to_s.singularize.titleize.constantize end private + + def _items + source_class.where(id: items.select(:source_id)) + end def _review items .untested .or(items.failed)