Module: Card::Set::All::FileUtils::ClassMethods

Defined in:
platypus/tmp/set/gem-defaults/mod016-carrierwave/all/file_utils.rb

Overview

eg, create new Card::File class in lib/card/file

Instance Method Summary collapse

Instance Method Details

#cards_with_disposable_attachmentsObject



23
24
25
26
27
28
29
30
31
32
# File 'platypus/tmp/set/gem-defaults/mod016-carrierwave/all/file_utils.rb', line 23

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

#count_cards_with_attachmentObject



47
48
49
# File 'platypus/tmp/set/gem-defaults/mod016-carrierwave/all/file_utils.rb', line 47

def count_cards_with_attachment
  Card.search type_id: ["in", Card::FileID, Card::ImageID], return: :count
end

#delete_tmp_files_of_cached_uploadsObject

def update_all_storage_locations Card.search(type_id: [“in”, Card::FileID, Card::ImageID]) .each(&:update_storage_location!) end



16
17
18
19
20
21
# File 'platypus/tmp/set/gem-defaults/mod016-carrierwave/all/file_utils.rb', line 16

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

#draft_actions_with_attachmentObject



38
39
40
41
42
43
44
45
# File 'platypus/tmp/set/gem-defaults/mod016-carrierwave/all/file_utils.rb', line 38

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

#old_enough?(time, expiration_time = 5.day.to_i) ⇒ Boolean

Returns:

  • (Boolean)


34
35
36
# File 'platypus/tmp/set/gem-defaults/mod016-carrierwave/all/file_utils.rb', line 34

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