Commit f81d61a3 by John Doe

fixed metadata parsing

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