Commit f81d61a3 by John Doe

fixed metadata parsing

parent 6e571f5a
......@@ -24,6 +24,7 @@ class DbAdapter
"description",
"hidden",
"name"))
metadata.symbolize_keys!
# Create the schema:
# 3 elements: path, attributes, streams
{ path: entry[0],
......@@ -33,7 +34,7 @@ class DbAdapter
end_time: entry[3] || 0,
total_rows: entry[4],
total_time: entry[5]
}.merge(metadata.except("streams")),
}.merge(metadata.except(:streams)),
streams: streams
}
end
......
......@@ -7,6 +7,10 @@ class DbFile < ActiveRecord::Base
has_many :db_decimations, dependent: :destroy
def defined_attributes
[:name, :name_abbrev, :description, :hidden]
end
def remove(db_service:)
db_service.remove_file(path)
destroy
......
......@@ -7,6 +7,10 @@ class DbFolder < ActiveRecord::Base
has_many :subfolders, class_name: 'DbFolder', foreign_key: 'parent_id'
has_many :db_files
def defined_attributes
[:name, :description, :hidden]
end
def insert_file(file:)
# add the file to this folder
file.db_folder = self
......
......@@ -61,12 +61,13 @@ class UpdateDb # rubocop:disable Metrics/ClassLength
# if this folder has an info stream, find that entry and
# use its metadata to update the folder's attributes
def __read_info_entry(entries)
if entries[0][:chunks] == ['info']
# if there is an info entry, remove it from the array
# so we don't process it as a seperate file
info_entry = entries.slice!(0)
info_entry[:attributes]
end
info_entry = entries.detect{ |entry|
entry[:chunks] == ['info']} || {}
# if there is an info entry, remove it from the array
# so we don't process it as a seperate file
entries.delete(info_entry)
# return the attributes
info_entry[:attributes]
end
# all entries agree on a common path
......@@ -86,7 +87,9 @@ class UpdateDb # rubocop:disable Metrics/ClassLength
return @root_folder if parent.nil?
folder = parent.subfolders.find_by_path(path)
folder ||= DbFolder.new(parent: parent, path: path)
folder.update_attributes(info.slice(:name))
byebug
folder.update_attributes(info.slice(
*folder.defined_attributes))
folder.save!
folder
end
......@@ -160,7 +163,6 @@ class UpdateDb # rubocop:disable Metrics/ClassLength
# if the file doesn't have a name, use the default
base[:attributes][:name] ||= default_name
# automatically updates the streams for this file
byebug if base[:attributes][:streams] != nil
file.update_attributes(base[:attributes])
file.save!
__build_decimations(file: file,
......
......@@ -94,16 +94,16 @@ describe 'UpdateDb' do
end
# info streams and metadata
describe 'given info streams' do
it 'uses info stream to set folder data' do
describe 'uses metadata' do
it 'from folder info stream' do
schema = Array.new(simple_db)
schema << helper.entry('/folder1/info', metadata: { name: 'first' })
update_with_schema(schema)
folder1 = @root.subfolders[0]
expect(folder1.name).to eq('first')
end
it 'reads metadata from base file'
it 'reads metadata from decimations'
it 'from base file'
it 'from decimations'
end
end
end
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or sign in to comment