Module: Card::Set::Abstract::Attachment
- Extended by:
- Card::Set
- Defined in:
- tmpsets/set/mod007-05_standard/abstract/attachment.rb
Class Method Summary
collapse
Instance Method Summary
collapse
Methods included from Card::Set
abstract_set?, all_set?, card_accessor, card_reader, card_writer, clean_empty_module_from_hash, clean_empty_modules, define_active_job, define_event_method, define_event_perform_later_method, define_on_format, ensure_set, event, extended, format, phase_method, process_base_module_list, process_base_modules, register_set, register_set_format, shortname, view, write_tmp_file
Class Method Details
.included(host_class) ⇒ Object
6
7
8
|
# File 'tmpsets/set/mod007-05_standard/abstract/attachment.rb', line 6
def self.included host_class
host_class.extend CarrierWave::CardMount
end
|
Instance Method Details
#assign_attachment(file, original_filename) ⇒ Object
49
50
51
52
53
|
# File 'tmpsets/set/mod007-05_standard/abstract/attachment.rb', line 49
def assign_attachment file, original_filename
send "#{attachment_name}=", file
write_identifier
@current_action.update_attributes! comment: original_filename
end
|
#assign_set_specific_attributes ⇒ Object
200
201
202
203
204
205
|
# File 'tmpsets/set/mod007-05_standard/abstract/attachment.rb', line 200
def assign_set_specific_attributes
if @set_specific && @set_specific.present?
self.content = nil
end
super
end
|
#attachment_changed? ⇒ Boolean
108
109
110
|
# File 'tmpsets/set/mod007-05_standard/abstract/attachment.rb', line 108
def attachment_changed?
send "#{attachment_name}_changed?"
end
|
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
|
# File 'tmpsets/set/mod007-05_standard/abstract/attachment.rb', line 253
def attachment_format(ext)
if ext.present? && attachment && original_ext=attachment.extension
if['file', original_ext].member? ext
original_ext
elsif exts = MIME::Types[attachment.content_type]
if exts.find {|mt| mt.extensions.member? ext }
ext
else
exts[0].extensions[0]
end
end
end
rescue => e
Rails.logger.info "attachment_format issue: #{e.message}"
nil
end
|
#cached_upload ⇒ Object
126
127
128
|
# File 'tmpsets/set/mod007-05_standard/abstract/attachment.rb', line 126
def cached_upload
@cached_upload
end
|
#cached_upload=(value) ⇒ Object
action id of the cached upload
122
123
124
|
# File 'tmpsets/set/mod007-05_standard/abstract/attachment.rb', line 122
def cached_upload= value
@cached_upload = value
end
|
#clear_upload_cache_dir_for_new_cards ⇒ Object
207
208
209
210
211
212
213
214
215
216
|
# File 'tmpsets/set/mod007-05_standard/abstract/attachment.rb', line 207
def clear_upload_cache_dir_for_new_cards
Dir.entries(tmp_upload_dir).each do |filename|
if filename =~/^\d+/
path = File.join(tmp_upload_dir, filename )
if older_than_five_days? File.ctime(path)
FileUtils.rm path
end
end
end
end
|
#create_versions? ⇒ Boolean
112
113
114
|
# File 'tmpsets/set/mod007-05_standard/abstract/attachment.rb', line 112
def create_versions?
true
end
|
#delete_files_for_action(action) ⇒ Object
222
223
224
225
226
227
228
229
|
# File 'tmpsets/set/mod007-05_standard/abstract/attachment.rb', line 222
def delete_files_for_action action
with_selected_action_id(action.id) do
FileUtils.rm attachment.file.path
attachment.versions.each_value do |version|
FileUtils.rm version.path
end
end
end
|
#item_names(args = {}) ⇒ Object
needed for flexmail attachments. hacky.
88
89
90
|
# File 'tmpsets/set/mod007-05_standard/abstract/attachment.rb', line 88
def item_names(args={}) [self.cardname]
end
|
#load_from_mod ⇒ Object
138
139
140
|
# File 'tmpsets/set/mod007-05_standard/abstract/attachment.rb', line 138
def load_from_mod
@mod
end
|
#load_from_mod=(value) ⇒ Object
130
131
132
133
134
135
136
|
# File 'tmpsets/set/mod007-05_standard/abstract/attachment.rb', line 130
def load_from_mod= value
@mod = value
write_identifier
if value
@store_in_mod = true
end
end
|
place for files of mod file cards
173
174
175
176
177
178
179
180
181
|
# File 'tmpsets/set/mod007-05_standard/abstract/attachment.rb', line 173
def mod_dir
mod = @mod || mod_file?
Card.paths['mod'].to_a.each do |mod_path|
dir = File.join(mod_path, mod, 'file', codename )
if Dir.exist? dir
return dir
end
end
end
|
#mod_file? ⇒ Boolean
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
|
# File 'tmpsets/set/mod007-05_standard/abstract/attachment.rb', line 183
def mod_file?
if @store_in_mod
return @mod
elsif !db_content_changed? && content.present?
case content
when /^:[^\/]+\/([^.]+)/ ; $1 when /^\~/ ; false else
if lines = content.split("\n") and lines.size == 4 lines.last
end
end
end
end
|
#older_than_five_days?(time) ⇒ Boolean
218
219
220
|
# File 'tmpsets/set/mod007-05_standard/abstract/attachment.rb', line 218
def older_than_five_days? time
Time.now - time > 432000
end
|
#original_filename ⇒ Object
92
93
94
|
# File 'tmpsets/set/mod007-05_standard/abstract/attachment.rb', line 92
def original_filename
attachment.original_filename
end
|
#preliminary_upload? ⇒ Boolean
100
101
102
|
# File 'tmpsets/set/mod007-05_standard/abstract/attachment.rb', line 100
def preliminary_upload?
Card::Env && Card::Env.params[:attachment_upload]
end
|
#retrieve_dir ⇒ Object
150
151
152
153
154
155
156
|
# File 'tmpsets/set/mod007-05_standard/abstract/attachment.rb', line 150
def retrieve_dir
if mod_file?
mod_dir
else
upload_dir
end
end
|
#save_preliminary_upload? ⇒ Boolean
104
105
106
|
# File 'tmpsets/set/mod007-05_standard/abstract/attachment.rb', line 104
def save_preliminary_upload?
@cached_upload.present?
end
|
#store_dir ⇒ Object
142
143
144
145
146
147
148
|
# File 'tmpsets/set/mod007-05_standard/abstract/attachment.rb', line 142
def store_dir
if @store_in_mod
mod_dir
else
upload_dir
end
end
|
#symlink_to(prior_action_id) ⇒ Object
create filesystem links to files from prior action
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
|
# File 'tmpsets/set/mod007-05_standard/abstract/attachment.rb', line 232
def symlink_to(prior_action_id) if prior_action_id != last_action_id
save_action_id = selected_action_id
links = {}
self.selected_action_id = prior_action_id
attachment.versions.each do |name, version|
links[name] = version.store_path
end
original = attachment.store_path
self.selected_action_id = last_action_id
attachment.versions.each do |name, version|
::File.symlink links[name], version.store_path
end
::File.symlink original, attachment.store_path
self.selected_action_id = save_action_id
end
end
|
#tmp_upload_dir(action_id = nil) ⇒ Object
place for files if card doesn’t have an id yet
168
169
170
|
# File 'tmpsets/set/mod007-05_standard/abstract/attachment.rb', line 168
def tmp_upload_dir action_id=nil
"#{ Card.paths['files'].existent.first }/#{upload_cache_card.id}"
end
|
#unfilled? ⇒ Boolean
96
97
98
|
# File 'tmpsets/set/mod007-05_standard/abstract/attachment.rb', line 96
def unfilled?
!attachment.present? && !save_preliminary_upload? && super
end
|
#upload_cache_card ⇒ Object
used for uploads for new cards until the new card is created
117
118
119
|
# File 'tmpsets/set/mod007-05_standard/abstract/attachment.rb', line 117
def upload_cache_card
@upload_cache_card ||= Card["new_#{attachment_name}".to_sym ]
end
|
#upload_dir ⇒ Object
place for files of regular file cards
159
160
161
162
163
164
165
|
# File 'tmpsets/set/mod007-05_standard/abstract/attachment.rb', line 159
def upload_dir
if id
"#{ Card.paths['files'].existent.first }/#{id}"
else
tmp_upload_dir
end
end
|