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

Defined in:
tmpsets/set/mod015-carrierwave/all/file_utils.rb

Overview

~~ above autogenerated; below pulled from /Users/ethan/dev/wagn/gem/card/mod/carrierwave/set/all/file_utils.rb ~~

Instance Method Summary collapse

Instance Method Details

#delete_tmp_files_of_cached_uploadsObject



10
11
12
13
14
15
16
17
# File 'tmpsets/set/mod015-carrierwave/all/file_utils.rb', line 10

def delete_tmp_files_of_cached_uploads
  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)
    card.delete_files_for_action action
    action.delete
  end
end

#draft_actions_with_attachmentObject



23
24
25
26
27
28
29
30
# File 'tmpsets/set/mod015-carrierwave/all/file_utils.rb', line 23

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)


19
20
21
# File 'tmpsets/set/mod015-carrierwave/all/file_utils.rb', line 19

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

#update_all_storage_locationsObject



5
6
7
8
# File 'tmpsets/set/mod015-carrierwave/all/file_utils.rb', line 5

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