Class: FileUploader
- Inherits:
-
CarrierWave::Uploader::Base
- Object
- CarrierWave::Uploader::Base
- FileUploader
show all
- Includes:
- Card::Location
- Defined in:
- mod/05_standard/lib/file_uploader.rb
Instance Attribute Summary collapse
Instance Method Summary
collapse
#card_path, #card_url, #page_path
Instance Attribute Details
Returns the value of attribute mod.
39
40
41
|
# File 'mod/05_standard/lib/file_uploader.rb', line 39
def mod
@mod
end
|
Instance Method Details
#action_id ⇒ Object
150
151
152
|
# File 'mod/05_standard/lib/file_uploader.rb', line 150
def action_id
model.selected_content_action_id
end
|
#cache_dir ⇒ Object
96
97
98
|
# File 'mod/05_standard/lib/file_uploader.rb', line 96
def cache_dir
Cardio.paths['files'].existent.first + '/cache'
end
|
#create_versions?(_new_file) ⇒ Boolean
124
125
126
|
# File 'mod/05_standard/lib/file_uploader.rb', line 124
def create_versions? _new_file
model.create_versions?
end
|
#db_content(opts = {}) ⇒ Object
generate identifier that gets stored in the card’s db_content field
62
63
64
65
66
67
|
# File 'mod/05_standard/lib/file_uploader.rb', line 62
def db_content opts={}
if opts[:mod] && !model.load_from_mod
model.load_from_mod = opts[:mod]
end
'%s/%s' % [file_dir, url_filename(opts)]
end
|
#extension ⇒ Object
52
53
54
55
56
57
58
59
|
# File 'mod/05_standard/lib/file_uploader.rb', line 52
def extension
case
when file && file.extension.present? then ".#{file.extension}"
when card_content = model.content then File.extname(card_content)
when orig = original_filename then File.extname(orig)
else ''
end.downcase
end
|
86
87
88
89
90
91
92
93
94
|
# File 'mod/05_standard/lib/file_uploader.rb', line 86
def file_dir
if mod_file?
":#{model.codename}"
elsif model.id
"~#{model.id}"
else
"~#{model.upload_cache_card.id}"
end
end
|
44
45
46
47
48
49
50
|
# File 'mod/05_standard/lib/file_uploader.rb', line 44
def filename
if mod_file?
"#{model.type_code}#{extension}"
else
"#{action_id}#{extension}"
end
end
|
#mod_file? ⇒ Boolean
146
147
148
|
# File 'mod/05_standard/lib/file_uploader.rb', line 146
def mod_file?
model.mod_file?
end
|
#original_filename ⇒ Object
133
134
135
136
|
# File 'mod/05_standard/lib/file_uploader.rb', line 133
def original_filename
@original_filename ||= model.selected_action &&
model.selected_action.
end
|
#path(version = nil) ⇒ Object
paperclip compatibility used in type/file.rb#core (base format)
129
130
131
|
# File 'mod/05_standard/lib/file_uploader.rb', line 129
def path version=nil
version ? versions[version].path : super()
end
|
#retrieve_dir ⇒ Object
142
143
144
|
# File 'mod/05_standard/lib/file_uploader.rb', line 142
def retrieve_dir
model.retrieve_dir
end
|
#retrieve_path ⇒ Object
113
114
115
|
# File 'mod/05_standard/lib/file_uploader.rb', line 113
def retrieve_path
File.join([retrieve_dir, full_filename(filename)].compact)
end
|
#store_dir ⇒ Object
138
139
140
|
# File 'mod/05_standard/lib/file_uploader.rb', line 138
def store_dir
model.store_dir
end
|
#store_path(for_file = nil) ⇒ Object
Carrierwave calls store_path without argument when it stores the file and with the identifier from the db when it retrieves the file In our case the first part of our identifier is not part of the path but we can construct the filename from db data. So we don’t need the identifier.
105
106
107
108
109
110
111
|
# File 'mod/05_standard/lib/file_uploader.rb', line 105
def store_path for_file=nil
if for_file
retrieve_path
else
File.join([store_dir, full_filename(filename)].compact)
end
end
|
117
118
119
120
121
122
|
# File 'mod/05_standard/lib/file_uploader.rb', line 117
def tmp_path
if !Dir.exists? model.tmp_upload_dir
Dir.mkdir model.tmp_upload_dir
end
File.join model.tmp_upload_dir, filename
end
|
#url(opts = {}) ⇒ Object
81
82
83
84
|
# File 'mod/05_standard/lib/file_uploader.rb', line 81
def url opts = {}
'%s/%s/%s' % [card_path(Card.config.files_web_path), file_dir,
full_filename(url_filename(opts))]
end
|
#url_filename(opts = {}) ⇒ Object
69
70
71
72
73
74
75
76
77
78
79
|
# File 'mod/05_standard/lib/file_uploader.rb', line 69
def url_filename opts={}
if opts[:mod] && !model.load_from_mod
model.load_from_mod = opts[:mod]
end
basename = if (mod = mod_file?)
"#{mod}#{extension}"
else
"#{action_id}#{extension}"
end
end
|