Class: CarrierWave::FileCardUploader
- Inherits:
-
Uploader::Base
- Object
- Uploader::Base
- CarrierWave::FileCardUploader
show all
- Includes:
- Card::Env::Location
- Defined in:
- mod/carrierwave/lib/carrier_wave/file_card_uploader.rb
Instance Attribute Summary collapse
Instance Method Summary
collapse
#card_path, #card_url, #page_path
Instance Attribute Details
#mod ⇒ Object
Returns the value of attribute mod.
42
43
44
|
# File 'mod/carrierwave/lib/carrier_wave/file_card_uploader.rb', line 42
def mod
@mod
end
|
Instance Method Details
#action_id ⇒ Object
148
149
150
|
# File 'mod/carrierwave/lib/carrier_wave/file_card_uploader.rb', line 148
def action_id
model.selected_content_action_id
end
|
#cache_dir ⇒ Object
96
97
98
|
# File 'mod/carrierwave/lib/carrier_wave/file_card_uploader.rb', line 96
def cache_dir
Cardio.paths["files"].existent.first + "/cache"
end
|
#create_versions?(_new_file) ⇒ Boolean
122
123
124
|
# File 'mod/carrierwave/lib/carrier_wave/file_card_uploader.rb', line 122
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
65
66
67
68
69
|
# File 'mod/carrierwave/lib/carrier_wave/file_card_uploader.rb', line 65
def db_content opts={}
return "" unless file.present?
model.load_from_mod = opts[:mod] if opts[:mod] && !model.load_from_mod
"%s/%s" % [file_dir, url_filename(opts)]
end
|
#extension ⇒ Object
55
56
57
58
59
60
61
62
|
# File 'mod/carrierwave/lib/carrier_wave/file_card_uploader.rb', line 55
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
|
#file_dir ⇒ Object
86
87
88
89
90
91
92
93
94
|
# File 'mod/carrierwave/lib/carrier_wave/file_card_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
|
#filename ⇒ Object
47
48
49
50
51
52
53
|
# File 'mod/carrierwave/lib/carrier_wave/file_card_uploader.rb', line 47
def filename
if mod_file?
"#{model.type_code}#{extension}"
else
"#{action_id}#{extension}"
end
end
|
#mod_file? ⇒ Boolean
144
145
146
|
# File 'mod/carrierwave/lib/carrier_wave/file_card_uploader.rb', line 144
def mod_file?
model.mod_file?
end
|
#original_filename ⇒ Object
131
132
133
134
|
# File 'mod/carrierwave/lib/carrier_wave/file_card_uploader.rb', line 131
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)
127
128
129
|
# File 'mod/carrierwave/lib/carrier_wave/file_card_uploader.rb', line 127
def path version=nil
version ? versions[version].path : super()
end
|
#retrieve_dir ⇒ Object
140
141
142
|
# File 'mod/carrierwave/lib/carrier_wave/file_card_uploader.rb', line 140
def retrieve_dir
model.retrieve_dir
end
|
#retrieve_path ⇒ Object
113
114
115
|
# File 'mod/carrierwave/lib/carrier_wave/file_card_uploader.rb', line 113
def retrieve_path
File.join([retrieve_dir, full_filename(filename)].compact)
end
|
#store_dir ⇒ Object
136
137
138
|
# File 'mod/carrierwave/lib/carrier_wave/file_card_uploader.rb', line 136
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/carrierwave/lib/carrier_wave/file_card_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
|
#tmp_path ⇒ Object
117
118
119
120
|
# File 'mod/carrierwave/lib/carrier_wave/file_card_uploader.rb', line 117
def tmp_path
Dir.mkdir model.tmp_upload_dir unless Dir.exist? model.tmp_upload_dir
File.join model.tmp_upload_dir, filename
end
|
#url(opts = {}) ⇒ Object
81
82
83
84
|
# File 'mod/carrierwave/lib/carrier_wave/file_card_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
71
72
73
74
75
76
77
78
79
|
# File 'mod/carrierwave/lib/carrier_wave/file_card_uploader.rb', line 71
def url_filename opts={}
model.load_from_mod = opts[:mod] if opts[:mod] && !model.load_from_mod
basename = if (mod = mod_file?)
"#{mod}#{extension}"
else
"#{action_id}#{extension}"
end
end
|