lib/isomorfeus/data/enhancer.rb in isomorfeus-data-23.9.0.rc2 vs lib/isomorfeus/data/enhancer.rb in isomorfeus-data-23.9.0.rc3
- old
+ new
@@ -178,68 +178,69 @@
data, meta = item_class.file_accelerator.load(sid: sid)
item_hash = {}
if data
content_type = Marcel::MimeType.for(data)
data_uri = item_class.format_data_uri(content_type, data)
- revision = meta[:revision]
- item_hash = { data_uri: data_uri, revision: revision }
+ item_hash = { data_uri: data_uri }.merge(meta)
end
action = { type: 'DATA_MERGE', data: { item_class_name => { item_key => item_hash }}}
elsif action_type == 'FILE_SAVE'
item_class_name = action[:class_name]
item_key = action[:key]
item_class = get_verified_class(item_class_name)
data_uri = action[:data_uri]
authorization_error!(action) unless Isomorfeus.current_user.authorized?(item_class, :save, { key: item_key, data_uri: data_uri })
revision = action[:revision]
+ name = action[:name]
sid = SID.new(item_class_name, item_key)
meta = item_class.file_accelerator.meta(sid: sid)
stored_revision = meta[:revision]
if stored_revision == action[:revision]
revision = stored_revision + 1
instance_uuid = action[:instance_uuid]
if item_class.before_save_block
res = item_class.before_save_block.call(key: item_key, data_uri: data_uri)
data_uri = res[:data_uri] if res.is_a?(Hash) && res.key?(:data_uri)
end
- if item_class.file_accelerator.save(sid: sid, data: URI::Data.new(data_uri).data, meta: { revision: revision })
+ if item_class.file_accelerator.save(sid: sid, data: URI::Data.new(data_uri).data, meta: { revision: revision, name: name })
item_class.after_save_block.call(key: item_key, data_uri: data_uri) if item_class.after_save_block
else
instance_uuid = nil
end
else
revision = 0
instance_uuid = nil
end
- action = { type: 'DATA_MERGE', data: { item_class_name => { item_key => { data_uri: data_uri, revision: revision, instance_uuid: instance_uuid }}}}
+ action = { type: 'DATA_MERGE', data: { item_class_name => { item_key => { data_uri: data_uri, revision: revision, name: name, instance_uuid: instance_uuid }}}}
elsif action_type == 'FILE_CREATE'
item_class_name = action[:class_name]
item_key = action[:key]
item_class = get_verified_class(item_class_name)
data_uri = action[:data_uri]
authorization_error!(action) unless Isomorfeus.current_user.authorized?(item_class, :create, { key: item_key, data_uri: data_uri })
+ name = action[:name]
sid = SID.new(item_class_name, item_key)
meta = item_class.file_accelerator.meta(sid: sid)
stored_revision = meta ? meta[:revision] : nil
if stored_revision.nil?
revision = 1
instance_uuid = action[:instance_uuid]
if item_class.before_create_block
res = item_class.before_create_block.call(key: item_key, data_uri: data_uri)
data_uri = res[:data_uri] if res.is_a?(Hash) && res.key?(:data_uri)
end
- if item_class.file_accelerator.create(sid: sid, data: URI::Data.new(data_uri).data, meta: { revision: revision })
+ if item_class.file_accelerator.create(sid: sid, data: URI::Data.new(data_uri).data, meta: { revision: revision, name: name })
item_class.after_create_block.call(key: item_key, data_uri: data_uri) if item_class.after_create_block
else
stored_revision = 0
instance_uuid = nil
end
else
revision = stored_revision
instance_uuid = nil
end
- action = { type: 'DATA_ADD', data: { item_class_name => { item_key => { data_uri: data_uri, revision: revision, instance_uuid: instance_uuid }}}}
+ action = { type: 'DATA_ADD', data: { item_class_name => { item_key => { data_uri: data_uri, revision: revision, name: name, instance_uuid: instance_uuid }}}}
elsif action_type == 'FILE_SEARCH'
item_class_name = action[:class_name]
item_class = get_verified_class(item_class_name)
query = action[:query].to_sym
params = action[:params]
@@ -300,10 +301,10 @@
end
end
end
def get_verified_class(item_class_name)
- raise "Invalid data class!" unless Isomorfeus.valid_data_class_name?(item_class_name)
+ raise "Invalid data class #{item_class_name}!" unless Isomorfeus.valid_data_class_name?(item_class_name)
item_class = Isomorfeus.cached_data_class(item_class_name)
end
def authorization_error!(action)
raise "Not authorized!#{" (action: #{action})" if Isomorfeus.development?}"