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
89
90
91
92
93
94
95
|
# File 'platypus/tmp/set/gem-defaults/mod016-carrierwave/abstract/attachment.rb', line 89
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
77
78
79
|
# File 'platypus/tmp/set/gem-defaults/mod016-carrierwave/abstract/attachment.rb', line 77
def attachment_before_act
send "#{attachment_name}_before_act"
end
|
#attachment_changed? ⇒ Boolean
69
70
71
|
# File 'platypus/tmp/set/gem-defaults/mod016-carrierwave/abstract/attachment.rb', line 69
def attachment_changed?
send "#{attachment_name}_changed?"
end
|
126
127
128
129
130
131
132
|
# File 'platypus/tmp/set/gem-defaults/mod016-carrierwave/abstract/attachment.rb', line 126
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
73
74
75
|
# File 'platypus/tmp/set/gem-defaults/mod016-carrierwave/abstract/attachment.rb', line 73
def attachment_is_changing?
send "#{attachment_name}_is_changing?"
end
|
#confirm_original_extension(ext) ⇒ Object
151
152
153
154
155
|
# File 'platypus/tmp/set/gem-defaults/mod016-carrierwave/abstract/attachment.rb', line 151
def confirm_original_extension ext
return unless ["file", original_extension].member? ext
original_extension
end
|
#create_versions?(_new_file) ⇒ Boolean
81
82
83
|
# File 'platypus/tmp/set/gem-defaults/mod016-carrierwave/abstract/attachment.rb', line 81
def create_versions? _new_file
true
end
|
#delete_files_for_action(action) ⇒ Object
110
111
112
113
114
115
116
117
|
# File 'platypus/tmp/set/gem-defaults/mod016-carrierwave/abstract/attachment.rb', line 110
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
141
142
143
144
145
|
# File 'platypus/tmp/set/gem-defaults/mod016-carrierwave/abstract/attachment.rb', line 141
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.
100
101
102
103
104
105
106
107
108
|
# File 'platypus/tmp/set/gem-defaults/mod016-carrierwave/abstract/attachment.rb', line 100
def duplicate?
real? &&
storage_type == :coded &&
(old = attachment.file) &&
(new = set_specific[attachment_name]) &&
old.size == new.size
end
|
#empty_ok? ⇒ Boolean
85
86
87
|
# File 'platypus/tmp/set/gem-defaults/mod016-carrierwave/abstract/attachment.rb', line 85
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: :create, when: proc { |c| !c.web? } 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.update! comment: 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: proc { |c| !c.web? } do
self.content = attachment.db_content
end
|
#file_ready_to_save? ⇒ Boolean
47
48
49
50
51
52
|
# File 'platypus/tmp/set/gem-defaults/mod016-carrierwave/abstract/attachment.rb', line 47
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.
55
56
57
|
# File 'platypus/tmp/set/gem-defaults/mod016-carrierwave/abstract/attachment.rb', line 55
def item_names _args={}
[name]
end
|
#original_extension ⇒ Object
157
158
159
|
# File 'platypus/tmp/set/gem-defaults/mod016-carrierwave/abstract/attachment.rb', line 157
def original_extension
@original_extension ||= attachment&.extension&.sub(/^\./, "")
end
|
#original_filename ⇒ Object
59
60
61
62
63
|
# File 'platypus/tmp/set/gem-defaults/mod016-carrierwave/abstract/attachment.rb', line 59
def original_filename
return content.split("/").last if web?
attachment.original_filename
end
|
#recognized_extension?(mime_types, ext) ⇒ Boolean
147
148
149
|
# File 'platypus/tmp/set/gem-defaults/mod016-carrierwave/abstract/attachment.rb', line 147
def recognized_extension? mime_types, ext
mime_types.find { |mt| mt.extensions.member? ext }
end
|
#rescuing_extension_issues ⇒ Object
134
135
136
137
138
139
|
# File 'platypus/tmp/set/gem-defaults/mod016-carrierwave/abstract/attachment.rb', line 134
def rescuing_extension_issues
yield
rescue StandardError => e
Rails.logger.info "attachment_format issue: #{e.message}"
nil
end
|
#revision(action, before_action = false) ⇒ Object
119
120
121
122
123
124
|
# File 'platypus/tmp/set/gem-defaults/mod016-carrierwave/abstract/attachment.rb', line 119
def revision action, before_action=false
return unless (result = super)
result[:empty_ok] = true
result
end
|
#unfilled? ⇒ Boolean
65
66
67
|
# File 'platypus/tmp/set/gem-defaults/mod016-carrierwave/abstract/attachment.rb', line 65
def unfilled?
!attachment.present? && !save_preliminary_upload? && super
end
|