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

Extended by:
Card::Set
Defined in:
platypus/tmp/set/gem-defaults/mod016-carrierwave/abstract/attachment/00_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

Methods included from I18nScope

#mod_name, #scope

Methods included from Registrar

#extended, #finalize_load, #process_base_modules, #register_set

Methods included from Helpers

#format_module, #format_modules, #method_missing, #modules, #pattern_code, #respond_to_missing?, #set_name_parts, #shortname, #underscored_name

Methods included from Card::Set::AdvancedApi

#assign_type, #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 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 'platypus/tmp/set/gem-defaults/mod016-carrierwave/abstract/attachment/00_upload_cache.rb', line 9

def action_id_of_cached_upload
  @action_id_of_cached_upload
end

Class Method Details

.source_locationObject



8
# File 'platypus/tmp/set/gem-defaults/mod016-carrierwave/abstract/attachment/00_upload_cache.rb', line 8

def self.source_location; "/Users/ethan/dev/decko/gem/mod/carrierwave/set/abstract/attachment/00_upload_cache.rb"; end

Instance Method Details

#actionable?Boolean

Returns:

  • (Boolean)


11
12
13
# File 'platypus/tmp/set/gem-defaults/mod016-carrierwave/abstract/attachment/00_upload_cache.rb', line 11

def actionable?
  super || preliminary_upload?
end

#assign_attachment(file, original_filename) ⇒ Object



51
52
53
54
55
56
# File 'platypus/tmp/set/gem-defaults/mod016-carrierwave/abstract/attachment/00_upload_cache.rb', line 51

def assign_attachment file, original_filename
  @attaching = true
  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
41
# File 'platypus/tmp/set/gem-defaults/mod016-carrierwave/abstract/attachment/00_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



43
44
45
46
47
48
49
# File 'platypus/tmp/set/gem-defaults/mod016-carrierwave/abstract/attachment/00_upload_cache.rb', line 43

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.



68
69
70
# File 'platypus/tmp/set/gem-defaults/mod016-carrierwave/abstract/attachment/00_upload_cache.rb', line 68

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



58
59
60
61
62
63
64
# File 'platypus/tmp/set/gem-defaults/mod016-carrierwave/abstract/attachment/00_upload_cache.rb', line 58

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



72
73
74
75
76
77
78
# File 'platypus/tmp/set/gem-defaults/mod016-carrierwave/abstract/attachment/00_upload_cache.rb', line 72

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 'platypus/tmp/set/gem-defaults/mod016-carrierwave/abstract/attachment/00_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)


86
87
88
# File 'platypus/tmp/set/gem-defaults/mod016-carrierwave/abstract/attachment/00_upload_cache.rb', line 86

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

#save_preliminary_upload?Boolean

Returns:

  • (Boolean)


90
91
92
# File 'platypus/tmp/set/gem-defaults/mod016-carrierwave/abstract/attachment/00_upload_cache.rb', line 90

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



95
96
97
# File 'platypus/tmp/set/gem-defaults/mod016-carrierwave/abstract/attachment/00_upload_cache.rb', line 95

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

#upload_cache_cardObject

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



81
82
83
84
# File 'platypus/tmp/set/gem-defaults/mod016-carrierwave/abstract/attachment/00_upload_cache.rb', line 81

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