Module: Card::Set::Abstract::Attachment::UploadCache

Extended by:
Card::Set
Defined in:
card/tmpsets/set/mod014-card-mod-carrierwave/abstract/attachment/upload_cache.rb,
card/tmpsets/set/mod013-card-mod-carrierwave/abstract/attachment/upload_cache.rb

Overview

Set: Abstract (Attachment, UploadCache)

action id of the cached upload

Constant Summary

Constants included from Helpers

Helpers::SET_PATTERN_TEST_REGEXP

Constants included from Event::Api

Event::Api::OPTIONS

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Methods included from Card::Set

reset_modules

Methods included from I18nScope

#mod_name, #scope

Methods included from Loader

#clean_empty_module_from_hash, #clean_empty_modules, #extended, #process_base_modules, #register_set

Methods included from Helpers

#method_missing, #num_set_parts, #pattern_code, #respond_to_missing?, #set_name_parts, #shortname, #underscore

Methods included from Card::Set::AdvancedApi

#attachment, #define_set_from_error, #ensure_set, #setting_opts, #stage_method

Methods included from Format

#before, #format, layout_method_name, #view, view_method_name, view_setting_method_name, wrapper_method_name

Methods included from Inheritance

#include_set, #include_set_formats

Methods included from Basket

#abstract_basket, #add_to_basket, #basket, #unshift_basket

Methods included from Trait

#card_accessor, #card_reader, #card_writer, #require_field

Methods included from Event::Api

#event

Instance Attribute Details

#action_id_of_cached_uploadObject

Returns the value of attribute action_id_of_cached_upload.



9
10
11
# File 'card/tmpsets/set/mod014-card-mod-carrierwave/abstract/attachment/upload_cache.rb', line 9

def action_id_of_cached_upload
  @action_id_of_cached_upload
end

Class Method Details

.source_locationObject



8
# File 'card/tmpsets/set/mod014-card-mod-carrierwave/abstract/attachment/upload_cache.rb', line 8

def self.source_location; "/Users/ethan/dev/decko/gem/card-mod-carrierwave/set/abstract/attachment/upload_cache.rb"; end

Instance Method Details

#actionable?Boolean

Returns:

  • (Boolean)


11
12
13
# File 'card/tmpsets/set/mod014-card-mod-carrierwave/abstract/attachment/upload_cache.rb', line 11

def actionable?
  super || preliminary_upload?
end

#assign_attachment(file, original_filename) ⇒ Object



49
50
51
52
53
# File 'card/tmpsets/set/mod014-card-mod-carrierwave/abstract/attachment/upload_cache.rb', line 49

def assign_attachment file, original_filename
  send "#{attachment_name}=", file
  write_identifier
  @current_action&.update! comment: original_filename
end

#event: assign_attachment_on_createObject



34
35
36
37
38
39
40
# File 'card/tmpsets/set/mod014-card-mod-carrierwave/abstract/attachment/upload_cache.rb', line 34

event :assign_attachment_on_create, :initialize,
      after: :assign_action, on: :create, when: :save_preliminary_upload? do
  return unless  (action = Card::Action.fetch(@action_id_of_cached_upload))
  upload_cache_card.selected_action_id = action.id
  upload_cache_card.select_file_revision
  assign_attachment upload_cache_card.attachment.file, action.comment
end

#event: assign_attachment_on_updateObject



42
43
44
45
46
47
# File 'card/tmpsets/set/mod014-card-mod-carrierwave/abstract/attachment/upload_cache.rb', line 42

event :assign_attachment_on_update, :initialize,
      after: :assign_action, on: :update, when: :save_preliminary_upload? do
  return unless (action = Card::Action.fetch(@action_id_of_cached_upload))
  uploaded_file = with_selected_action_id(action.id) { attachment.file }
  assign_attachment uploaded_file, action.comment
end

#event: clear_draft_filesObject

at some point uploaded files of canceled file card creation should be deleted. We do this when ever an new file is created.



64
65
66
# File 'card/tmpsets/set/mod014-card-mod-carrierwave/abstract/attachment/upload_cache.rb', line 64

event :clear_draft_files, :integrate_with_delay, priority: 100, on: :create do
  Card.delete_tmp_files_of_cached_uploads
end

#event: delete_cached_upload_file_on_createObject



55
56
57
58
59
60
# File 'card/tmpsets/set/mod014-card-mod-carrierwave/abstract/attachment/upload_cache.rb', line 55

event :delete_cached_upload_file_on_create, :integrate,
      on: :create, when: :save_preliminary_upload? do
  return unless (action = Card::Action.fetch(@action_id_of_cached_upload))
  upload_cache_card.delete_files_for_action action
  action.delete
end

#event: delete_cached_upload_file_on_updateObject



68
69
70
71
72
73
# File 'card/tmpsets/set/mod014-card-mod-carrierwave/abstract/attachment/upload_cache.rb', line 68

event :delete_cached_upload_file_on_update, :integrate,
      on: :update, when: :save_preliminary_upload? do
  return unless  (action = Card::Action.fetch(@action_id_of_cached_upload))
  delete_files_for_action action
  action.delete
end

#event: prepare_attachmentObject



15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
# File 'card/tmpsets/set/mod014-card-mod-carrierwave/abstract/attachment/upload_cache.rb', line 15

event :prepare_attachment, :prepare_to_validate, on: :save, when: :preliminary_upload? do
  save_original_filename  # save original filename as comment in action
  write_identifier        # set db_content
  # (needs original filename to determine extension)
  store_attachment!
  store_card_changes
  # finalize_action         # create Card::Change entry for db_content

  card_id = new_card? ? upload_cache_card.id : id
  @current_action.update! draft: true, card_id: card_id
  success << {
    target: (new_card? ? upload_cache_card : self),
    type: type_name,
    view: "preview_editor",
    rev_id: current_action.id
  }
  abort :success
end

#preliminary_upload?Boolean

Returns:

  • (Boolean)


81
82
83
# File 'card/tmpsets/set/mod014-card-mod-carrierwave/abstract/attachment/upload_cache.rb', line 81

def preliminary_upload?
  Card::Env && Card::Env.params[:attachment_upload]
end

#save_preliminary_upload?Boolean

Returns:

  • (Boolean)


85
86
87
# File 'card/tmpsets/set/mod014-card-mod-carrierwave/abstract/attachment/upload_cache.rb', line 85

def save_preliminary_upload?
  @action_id_of_cached_upload.present?
end

#tmp_upload_dir(_action_id = nil) ⇒ Object

place for files if card doesn’t have an id yet



90
91
92
# File 'card/tmpsets/set/mod014-card-mod-carrierwave/abstract/attachment/upload_cache.rb', line 90

def tmp_upload_dir _action_id=nil
  "#{files_base_dir}/#{upload_cache_card.id}"
end

#upload_cache_cardObject

used for uploads for new cards until the new card is created



76
77
78
79
# File 'card/tmpsets/set/mod014-card-mod-carrierwave/abstract/attachment/upload_cache.rb', line 76

def upload_cache_card
  cache_card_codename = "new_#{attachment_name}"
  @upload_cache_card ||= Card::Codename.card(cache_card_codename) { Card[:new_file] }
end