Module: Card::Set::Abstract::Attachment
- Extended by:
- Card::Set
- Defined in:
- platypus/tmp/set/gem-defaults/mod016-carrierwave/abstract/attachment.rb,
platypus/tmp/set/gem-defaults/mod016-carrierwave/abstract/attachment/web.rb,
platypus/tmp/set/gem-defaults/mod016-carrierwave/abstract/attachment/cloud.rb,
platypus/tmp/set/gem-defaults/mod016-carrierwave/abstract/attachment/coded.rb,
platypus/tmp/set/gem-defaults/mod016-carrierwave/abstract/attachment/local.rb,
platypus/tmp/set/gem-defaults/mod016-carrierwave/abstract/attachment/paths.rb,
platypus/tmp/set/gem-defaults/mod016-carrierwave/abstract/attachment/00_upload_cache.rb,
platypus/tmp/set/gem-defaults/mod016-carrierwave/abstract/attachment/01_storage_type.rb
Overview
Set: Abstract (Attachment)
Defined Under Namespace
Modules: Cloud, Coded, Local, Paths, StorageType, UploadCache, Web
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
#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
#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
#empty_ok=(value) ⇒ Object
Sets the attribute empty_ok
10
11
12
|
# File 'platypus/tmp/set/gem-defaults/mod016-carrierwave/abstract/attachment.rb', line 10
def empty_ok=(value)
@empty_ok = value
end
|
Class Method Details
.included(host_class) ⇒ Object
12
13
14
|
# File 'platypus/tmp/set/gem-defaults/mod016-carrierwave/abstract/attachment.rb', line 12
def self.included host_class
host_class.extend CarrierWave::CardMount
end
|
.source_location ⇒ Object
7
|
# File 'platypus/tmp/set/gem-defaults/mod016-carrierwave/abstract/attachment.rb', line 7
def self.source_location; "/Users/ethan/dev/decko/gem/mod/carrierwave/set/abstract/attachment.rb"; end
|
Instance Method Details
#assign_set_specific_attributes ⇒ Object
100
101
102
103
104
105
106
|
# File 'platypus/tmp/set/gem-defaults/mod016-carrierwave/abstract/attachment.rb', line 100
def assign_set_specific_attributes
@attaching = set_specific[attachment_name].present?
@mod = set_specific[:mod]
self.content = nil if @attaching && !duplicate?
super
end
|
#attachment_before_act ⇒ Object
88
89
90
|
# File 'platypus/tmp/set/gem-defaults/mod016-carrierwave/abstract/attachment.rb', line 88
def attachment_before_act
send "#{attachment_name}_before_act"
end
|
#attachment_changed? ⇒ Boolean
80
81
82
|
# File 'platypus/tmp/set/gem-defaults/mod016-carrierwave/abstract/attachment.rb', line 80
def attachment_changed?
send "#{attachment_name}_changed?"
end
|
135
136
137
138
139
140
141
|
# File 'platypus/tmp/set/gem-defaults/mod016-carrierwave/abstract/attachment.rb', line 135
def attachment_format ext
rescuing_extension_issues do
return unless ext.present? && original_extension
confirm_original_extension(ext) || detect_extension(ext)
end
end
|
#attachment_is_changing? ⇒ Boolean
84
85
86
|
# File 'platypus/tmp/set/gem-defaults/mod016-carrierwave/abstract/attachment.rb', line 84
def attachment_is_changing?
send "#{attachment_name}_is_changing?"
end
|
#confirm_original_extension(ext) ⇒ Object
154
155
156
157
158
|
# File 'platypus/tmp/set/gem-defaults/mod016-carrierwave/abstract/attachment.rb', line 154
def confirm_original_extension ext
return unless ["file", original_extension].member? ext
original_extension
end
|
#create_versions?(_new_file) ⇒ Boolean
92
93
94
|
# File 'platypus/tmp/set/gem-defaults/mod016-carrierwave/abstract/attachment.rb', line 92
def create_versions? _new_file
true
end
|
#delete_files_for_action(action) ⇒ Object
119
120
121
122
123
124
125
126
|
# File 'platypus/tmp/set/gem-defaults/mod016-carrierwave/abstract/attachment.rb', line 119
def delete_files_for_action action
with_selected_action_id action.id do
attachment.file.delete
attachment.versions.each_value do |version|
version.file&.delete
end
end
end
|
#detect_extension(ext) ⇒ Object
160
161
162
163
164
|
# File 'platypus/tmp/set/gem-defaults/mod016-carrierwave/abstract/attachment.rb', line 160
def detect_extension ext
return unless (mime_types = MIME::Types[attachment.content_type])
recognized_extension?(mime_types, ext) ? ext : mime_types[0].extensions[0]
end
|
#duplicate? ⇒ Boolean
FIXME: this is weak duplicate detection and currently only catches duplicate
updates to coded cards. Tried #read but wasn’t getting the same value on both
files even when they were definitely duplicates.
111
112
113
114
115
116
117
|
# File 'platypus/tmp/set/gem-defaults/mod016-carrierwave/abstract/attachment.rb', line 111
def duplicate?
real? &&
storage_type == :coded &&
(old = attachment.file) &&
(new = set_specific[attachment_name]) &&
old.size == new.size
end
|
#empty_ok? ⇒ Boolean
96
97
98
|
# File 'platypus/tmp/set/gem-defaults/mod016-carrierwave/abstract/attachment.rb', line 96
def empty_ok?
@empty_ok
end
|
#event: correct_identifier ⇒ Object
we need a card id for the path so we have to update db_content when we have
an id
22
23
24
25
|
# File 'platypus/tmp/set/gem-defaults/mod016-carrierwave/abstract/attachment.rb', line 22
event :correct_identifier, :finalize, on: :save, when: :incorrect_identifier? do
update_column :db_content, attachment.db_content
expire
end
|
#event: save_original_filename ⇒ Object
27
28
29
30
31
|
# File 'platypus/tmp/set/gem-defaults/mod016-carrierwave/abstract/attachment.rb', line 27
event :save_original_filename, :prepare_to_store, on: :save, when: :file_ready_to_save? do
return unless @current_action
@current_action. = original_filename
end
|
#event: select_file_revision ⇒ Object
16
17
18
|
# File 'platypus/tmp/set/gem-defaults/mod016-carrierwave/abstract/attachment.rb', line 16
event :select_file_revision, after: :select_action do
attachment.retrieve_from_store!(attachment.identifier)
end
|
#event: validate_file_exist ⇒ Object
33
34
35
36
37
38
39
40
41
|
# File 'platypus/tmp/set/gem-defaults/mod016-carrierwave/abstract/attachment.rb', line 33
event :validate_file_exist, :validate, on: :create, skip: :allowed do
return if empty_ok?
if web?
errors.add "url is missing" if content.blank?
elsif !attachment.file.present?
errors.add attachment_name, "is missing"
end
end
|
#event: write_identifier ⇒ Object
43
44
45
|
# File 'platypus/tmp/set/gem-defaults/mod016-carrierwave/abstract/attachment.rb', line 43
event :write_identifier, after: :save_original_filename, when: :write_identifier? do
self.content = attachment.db_content
end
|
#file_ready_to_save? ⇒ Boolean
58
59
60
61
62
63
|
# File 'platypus/tmp/set/gem-defaults/mod016-carrierwave/abstract/attachment.rb', line 58
def file_ready_to_save?
attachment.file.present? &&
!preliminary_upload? &&
!save_preliminary_upload? &&
attachment_is_changing?
end
|
#incorrect_identifier? ⇒ Boolean
47
48
49
50
51
52
|
# File 'platypus/tmp/set/gem-defaults/mod016-carrierwave/abstract/attachment.rb', line 47
def incorrect_identifier?
return false if web?
correct_id = attachment.db_content
correct_id.present? && db_content != correct_id
end
|
#item_names(_args = {}) ⇒ Object
needed for flexmail attachments. hacky.
66
67
68
|
# File 'platypus/tmp/set/gem-defaults/mod016-carrierwave/abstract/attachment.rb', line 66
def item_names _args={}
[name]
end
|
#original_extension ⇒ Object
143
144
145
|
# File 'platypus/tmp/set/gem-defaults/mod016-carrierwave/abstract/attachment.rb', line 143
def original_extension
@original_extension ||= attachment&.extension&.sub(/^\./, "")
end
|
#original_filename ⇒ Object
70
71
72
73
74
|
# File 'platypus/tmp/set/gem-defaults/mod016-carrierwave/abstract/attachment.rb', line 70
def original_filename
return content.split("/").last if web?
attachment.original_filename
end
|
#recognized_extension?(mime_types, ext) ⇒ Boolean
166
167
168
|
# File 'platypus/tmp/set/gem-defaults/mod016-carrierwave/abstract/attachment.rb', line 166
def recognized_extension? mime_types, ext
mime_types.find { |mt| mt.extensions.member? ext }
end
|
#rescuing_extension_issues ⇒ Object
147
148
149
150
151
152
|
# File 'platypus/tmp/set/gem-defaults/mod016-carrierwave/abstract/attachment.rb', line 147
def rescuing_extension_issues
yield
rescue StandardError => e
Rails.logger.info "attachment_format issue: #{e.message}"
nil
end
|
#revision(action, before_action: false) ⇒ Object
128
129
130
131
132
133
|
# File 'platypus/tmp/set/gem-defaults/mod016-carrierwave/abstract/attachment.rb', line 128
def revision action, before_action: false
return unless (result = super)
result[:empty_ok] = true
result
end
|
#unfilled? ⇒ Boolean
76
77
78
|
# File 'platypus/tmp/set/gem-defaults/mod016-carrierwave/abstract/attachment.rb', line 76
def unfilled?
!attachment.present? && !save_preliminary_upload? && super
end
|
#write_identifier? ⇒ Boolean
54
55
56
|
# File 'platypus/tmp/set/gem-defaults/mod016-carrierwave/abstract/attachment.rb', line 54
def write_identifier?
!web?
end
|