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
92
93
94
95
96
97
98
|
# File 'platypus/tmp/set/gem-defaults/mod016-carrierwave/abstract/attachment.rb', line 92
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
80
81
82
|
# File 'platypus/tmp/set/gem-defaults/mod016-carrierwave/abstract/attachment.rb', line 80
def attachment_before_act
send "#{attachment_name}_before_act"
end
|
#attachment_changed? ⇒ Boolean
72
73
74
|
# File 'platypus/tmp/set/gem-defaults/mod016-carrierwave/abstract/attachment.rb', line 72
def attachment_changed?
send "#{attachment_name}_changed?"
end
|
129
130
131
132
133
134
135
|
# File 'platypus/tmp/set/gem-defaults/mod016-carrierwave/abstract/attachment.rb', line 129
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
76
77
78
|
# File 'platypus/tmp/set/gem-defaults/mod016-carrierwave/abstract/attachment.rb', line 76
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
84
85
86
|
# File 'platypus/tmp/set/gem-defaults/mod016-carrierwave/abstract/attachment.rb', line 84
def create_versions? _new_file
true
end
|
#delete_files_for_action(action) ⇒ Object
113
114
115
116
117
118
119
120
|
# File 'platypus/tmp/set/gem-defaults/mod016-carrierwave/abstract/attachment.rb', line 113
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
144
145
146
147
148
|
# File 'platypus/tmp/set/gem-defaults/mod016-carrierwave/abstract/attachment.rb', line 144
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.
103
104
105
106
107
108
109
110
111
|
# File 'platypus/tmp/set/gem-defaults/mod016-carrierwave/abstract/attachment.rb', line 103
def duplicate?
real? &&
storage_type == :coded &&
(old = attachment.file) &&
(new = set_specific[attachment_name]) &&
old.size == new.size
end
|
#empty_ok? ⇒ Boolean
88
89
90
|
# File 'platypus/tmp/set/gem-defaults/mod016-carrierwave/abstract/attachment.rb', line 88
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
26
27
28
|
# File 'platypus/tmp/set/gem-defaults/mod016-carrierwave/abstract/attachment.rb', line 22
event :correct_identifier, :finalize, on: :save, when: proc { |c| !c.web? } do
correct_id = attachment.db_content
return if db_content == correct_id
update_column :db_content, attachment.db_content
expire
end
|
#event: save_original_filename ⇒ Object
30
31
32
33
34
|
# File 'platypus/tmp/set/gem-defaults/mod016-carrierwave/abstract/attachment.rb', line 30
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
36
37
38
39
40
41
42
43
44
|
# File 'platypus/tmp/set/gem-defaults/mod016-carrierwave/abstract/attachment.rb', line 36
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
46
47
48
|
# File 'platypus/tmp/set/gem-defaults/mod016-carrierwave/abstract/attachment.rb', line 46
event :write_identifier, after: :save_original_filename, when: proc { |c| !c.web? } do
self.content = attachment.db_content
end
|
#file_ready_to_save? ⇒ Boolean
50
51
52
53
54
55
|
# File 'platypus/tmp/set/gem-defaults/mod016-carrierwave/abstract/attachment.rb', line 50
def file_ready_to_save?
attachment.file.present? &&
!preliminary_upload? &&
!save_preliminary_upload? &&
attachment_is_changing?
end
|
#item_names(_args = {}) ⇒ Object
needed for flexmail attachments. hacky.
58
59
60
|
# File 'platypus/tmp/set/gem-defaults/mod016-carrierwave/abstract/attachment.rb', line 58
def item_names _args={}
[name]
end
|
#original_extension ⇒ Object
160
161
162
|
# File 'platypus/tmp/set/gem-defaults/mod016-carrierwave/abstract/attachment.rb', line 160
def original_extension
@original_extension ||= attachment&.extension&.sub(/^\./, "")
end
|
#original_filename ⇒ Object
62
63
64
65
66
|
# File 'platypus/tmp/set/gem-defaults/mod016-carrierwave/abstract/attachment.rb', line 62
def original_filename
return content.split("/").last if web?
attachment.original_filename
end
|
#recognized_extension?(mime_types, ext) ⇒ Boolean
150
151
152
|
# File 'platypus/tmp/set/gem-defaults/mod016-carrierwave/abstract/attachment.rb', line 150
def recognized_extension? mime_types, ext
mime_types.find { |mt| mt.extensions.member? ext }
end
|
#rescuing_extension_issues ⇒ Object
137
138
139
140
141
142
|
# File 'platypus/tmp/set/gem-defaults/mod016-carrierwave/abstract/attachment.rb', line 137
def rescuing_extension_issues
yield
rescue StandardError => e
Rails.logger.info "attachment_format issue: #{e.message}"
nil
end
|
#revision(action, before_action = false) ⇒ Object
122
123
124
125
126
127
|
# File 'platypus/tmp/set/gem-defaults/mod016-carrierwave/abstract/attachment.rb', line 122
def revision action, before_action=false
return unless (result = super)
result[:empty_ok] = true
result
end
|
#unfilled? ⇒ Boolean
68
69
70
|
# File 'platypus/tmp/set/gem-defaults/mod016-carrierwave/abstract/attachment.rb', line 68
def unfilled?
!attachment.present? && !save_preliminary_upload? && super
end
|