Sha256: cc65f1de5a6565383d4a84fc7f97706cc4a5257306c544ee2aa9a8d1d37e5179

Contents?: true

Size: 1.38 KB

Versions: 9

Compression:

Stored size: 1.38 KB

Contents

# -*- encoding : utf-8 -*-
class Card; module Set; class All
# Set: All cards (FileUtils)
#
module FileUtils;
extend Card::Set
def self.source_location; "/Users/ethan/dev/decko/gem/card/mod/carrierwave/set/all/file_utils.rb"; end
module ClassMethods
  def update_all_storage_locations
    Card.search(type_id: ["in", FileID, ImageID])
        .each(&:update_storage_location!)
  end

  def delete_tmp_files_of_cached_uploads
    cards_with_disposable_attachments do |card, action|
      card.delete_files_for_action action
      action.delete
    end
  end

  def cards_with_disposable_attachments
    draft_actions_with_attachment.each do |action|
      # we don't want to delete uploads in progress
      next unless old_enough?(action.created_at) && (card = action.card)
      # we can't delete attachments we don't have write access to
      next if card.read_only?

      yield card, action
    end
  end

  def old_enough? time, expiration_time=5.day.to_i
    Time.now - time > expiration_time
  end

  def draft_actions_with_attachment
    Card::Action.find_by_sql(
      "SELECT * FROM card_actions "\
        "INNER JOIN cards ON card_actions.card_id = cards.id "\
        "WHERE cards.type_id IN (#{Card::FileID}, #{Card::ImageID}) "\
        "AND card_actions.draft = true"
    )
  end
end
end;end;end;end;
# ~~ generated from /Users/ethan/dev/decko/gem/card/mod/carrierwave/set/all/file_utils.rb ~~

Version data entries

9 entries across 9 versions & 1 rubygems

Version Path
card-1.99.4 tmpsets/set/mod019-carrierwave/all/file_utils.rb
card-1.99.3 tmpsets/set/mod019-carrierwave/all/file_utils.rb
card-1.99.2 tmpsets/set/mod019-carrierwave/all/file_utils.rb
card-1.99.1 tmpsets/set/mod019-carrierwave/all/file_utils.rb
card-1.99.0 tmpsets/set/mod019-carrierwave/all/file_utils.rb
card-1.98.3 tmpsets/set/mod019-carrierwave/all/file_utils.rb
card-1.98.2 tmpsets/set/mod019-carrierwave/all/file_utils.rb
card-1.98.1 tmpsets/set/mod019-carrierwave/all/file_utils.rb
card-1.98.0 tmpsets/set/mod019-carrierwave/all/file_utils.rb