Skip to content
Toggle navigation
P
Projects
G
Groups
S
Snippets
Help
wattsworth
/
lumen-api
This project
Loading...
Sign in
Toggle navigation
Go to a project
Project
Repository
Issues
0
Merge Requests
0
Pipelines
Wiki
Settings
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Commit
f81d61a3
authored
Jul 10, 2016
by
John Doe
Browse files
Options
_('Browse Files')
Download
Email Patches
Plain Diff
fixed metadata parsing
parent
6e571f5a
Show whitespace changes
Inline
Side-by-side
Showing
5 changed files
with
21 additions
and
10 deletions
app/adapters/db_adapter.rb
app/models/db_file.rb
app/models/db_folder.rb
app/services/db/update_db.rb
spec/services/db/update_db_spec.rb
app/adapters/db_adapter.rb
View file @
f81d61a3
...
@@ -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
...
...
app/models/db_file.rb
View file @
f81d61a3
...
@@ -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
...
...
app/models/db_folder.rb
View file @
f81d61a3
...
@@ -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
...
...
app/services/db/update_db.rb
View file @
f81d61a3
...
@@ -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
,
...
...
spec/services/db/update_db_spec.rb
View file @
f81d61a3
...
@@ -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
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment