Skip to content

Commit c838d37

Browse files
committed
Merge branch 'develop'
2 parents c5b58c0 + f86ba90 commit c838d37

File tree

2 files changed

+20
-6
lines changed

2 files changed

+20
-6
lines changed

app/models/asset_field_type.rb

+19-5
Original file line numberDiff line numberDiff line change
@@ -16,19 +16,19 @@ class AssetFieldType < FieldType
1616

1717
def metadata=(metadata_hash)
1818
@metadata = metadata_hash.deep_symbolize_keys
19-
Paperclip::HasAttachedFile.define_on(self.class, :asset, metadata)
19+
@existing_data = metadata_hash[:existing_data]
20+
Paperclip::HasAttachedFile.define_on(self.class, :asset, existing_metadata)
2021
end
2122

2223
def data=(data_hash)
23-
@existing_data = data_hash.deep_symbolize_keys[:existing_data]
2424
self.asset = data_hash.deep_symbolize_keys[:asset]
2525
end
2626

2727
def data
2828
{
2929
'asset': {
3030
'file_name': asset_file_name,
31-
'url': url,
31+
'url': asset.url,
3232
'dimensions': dimensions,
3333
'content_type': asset_content_type,
3434
'file_size': asset_file_size,
@@ -115,7 +115,21 @@ def validate_asset_content_type
115115
attachment_content_type_validator.validate_each(self, :asset, asset)
116116
end
117117

118-
def url
119-
@existing_data.empty? ? asset.url : @existing_data[:asset][:url]
118+
def existing_metadata
119+
metadata.except!(:existing_data)
120+
121+
unless @existing_data.empty?
122+
metadata[:path] = updated_url(@existing_data['asset']['url'])
123+
end
124+
125+
metadata
126+
end
127+
128+
def updated_url(path)
129+
# Take the parse path of the existing URL and drop the first '/',
130+
# that will be added later and we don't want to duplicate it
131+
# Then remove the old file extension and replace it with the paperclipp'd new one
132+
new_path = URI.parse(path).path.slice(1..-1)
133+
new_path.gsub(File.extname(path), ".:extension")
120134
end
121135
end

lib/cortex/plugins/core/version.rb

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
module Cortex
22
module Plugins
33
module Core
4-
VERSION = '0.4.4'
4+
VERSION = '0.4.5'
55
end
66
end
77
end

0 commit comments

Comments
 (0)