Sha256: b5b3e89a1d4a692680129ac1bc77f0a24e3471d3a89122dcd4efece8e44dbd63

Contents?: true

Size: 910 Bytes

Versions: 41

Compression:

Stored size: 910 Bytes

Contents

# frozen_string_literal: true

module Doing
  class Items < Array
    ##
    ## Delete an item from the index
    ##
    ## @param      item  The item
    ##
    def delete_item(item, single: false)
      deleted = delete(item)
      Doing.logger.count(:deleted)
      Doing.logger.info('Entry deleted:', deleted.title) if single
      deleted
    end

    ##
    ## Update an item in the index with a modified item
    ##
    ## @param      old_item  The old item
    ## @param      new_item  The new item
    ##
    def update_item(old_item, new_item)
      s_idx = index { |item| item.equal?(old_item) }

      raise ItemNotFound, 'Unable to find item in index, did it mutate?' unless s_idx

      return if fetch(s_idx).equal?(new_item)

      self[s_idx] = new_item
      Doing.logger.count(:updated)
      Doing.logger.info('Entry updated:', self[s_idx].title.trunc(60))
      new_item
    end
  end
end

Version data entries

41 entries across 41 versions & 1 rubygems

Version Path
doing-2.1.88 lib/doing/items/modify.rb
doing-2.1.87 lib/doing/items/modify.rb
doing-2.1.86 lib/doing/items/modify.rb
doing-2.1.85 lib/doing/items/modify.rb
doing-2.1.84 lib/doing/items/modify.rb
doing-2.1.83 lib/doing/items/modify.rb
doing-2.1.82 lib/doing/items/modify.rb
doing-2.1.81 lib/doing/items/modify.rb
doing-2.1.80 lib/doing/items/modify.rb
doing-2.1.79 lib/doing/items/modify.rb
doing-2.1.78 lib/doing/items/modify.rb
doing-2.1.77 lib/doing/items/modify.rb
doing-2.1.76 lib/doing/items/modify.rb
doing-2.1.75 lib/doing/items/modify.rb
doing-2.1.74 lib/doing/items/modify.rb
doing-2.1.73 lib/doing/items/modify.rb
doing-2.1.72 lib/doing/items/modify.rb
doing-2.1.69 lib/doing/items/modify.rb
doing-2.1.68 lib/doing/items/modify.rb
doing-2.1.66 lib/doing/items/modify.rb