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
e859908b
authored
Jul 10, 2016
by
John Doe
Browse files
Options
_('Browse Files')
Download
Email Patches
Plain Diff
cleaned up code
parent
65a0409f
Hide whitespace changes
Inline
Side-by-side
Showing
10 changed files
with
38 additions
and
42 deletions
app/adapters/db_adapter.rb
app/models/db_decimation.rb
app/models/db_file.rb
app/models/db_stream.rb
app/services/db/update_db.rb
spec/factories/db_schema_helper.rb
spec/models/db_file_spec.rb
spec/models/db_folder_spec.rb
spec/models/db_stream_spec.rb
spec/services/db/update_db_spec.rb
app/adapters/db_adapter.rb
View file @
e859908b
...
...
@@ -12,19 +12,11 @@ class DbAdapter
# GET extended info stream list
dump
=
self
.
class
.
get
(
"
#{
@url
}
/stream/list?extended=1"
)
dump
.
parsed_response
.
map
do
|
entry
|
# TODO: implement global metadata dump, because this is sloooow
# GET metadata for the stream
dump
=
self
.
class
.
get
(
"
#{
@url
}
/stream/get_metadata?path=
#{
entry
[
0
]
}
"
)
metadata
=
JSON
.
parse
(
dump
.
parsed_response
[
'config_key__'
]
||
'{}'
)
metadata
=
__get_metadata
(
entry
[
0
])
# The streams are not pure attributes, pull them out
streams
=
metadata
[
"streams"
]
||
{}
# Add plain-text metadata keys (retrofit for *info streams which keep
# attributes in seperate metadata tags
metadata
.
merge!
(
dump
.
parsed_response
.
slice
(
"delete_locked"
,
"description"
,
"hidden"
,
"name"
))
metadata
.
symbolize_keys!
streams
=
metadata
.
delete
(
:streams
)
||
{}
# Create the schema:
# 3 elements: path, attributes, streams
{
path:
entry
[
0
],
...
...
@@ -34,9 +26,22 @@ class DbAdapter
end_time:
entry
[
3
]
||
0
,
total_rows:
entry
[
4
],
total_time:
entry
[
5
]
}.
merge
(
metadata
.
except
(
:streams
)
),
}.
merge
(
metadata
),
streams:
streams
}
end
end
# retrieve metadata for a particular stream
def
__get_metadata
(
path
)
dump
=
self
.
class
.
get
(
"
#{
@url
}
/stream/get_metadata?path=
#{
path
}
"
)
metadata
=
JSON
.
parse
(
dump
.
parsed_response
[
'config_key__'
]
||
'{}'
)
# Add plain-text metadata keys (retrofit for *info streams which keep
# attributes in seperate metadata tags
metadata
.
merge!
(
dump
.
parsed_response
.
slice
(
'delete_locked'
,
'description'
,
'hidden'
,
'name'
))
metadata
.
symbolize_keys
end
end
app/models/db_decimation.rb
View file @
e859908b
...
...
@@ -7,5 +7,4 @@ class DbDecimation < ActiveRecord::Base
def
as_json
(
_options
=
{})
super
(
except:
[
:created_at
,
:updated_at
])
end
end
app/models/db_file.rb
View file @
e859908b
...
...
@@ -6,7 +6,6 @@ class DbFile < ActiveRecord::Base
has_many
:db_streams
,
dependent: :destroy
has_many
:db_decimations
,
dependent: :destroy
def
defined_attributes
[
:name
,
:name_abbrev
,
:description
,
:hidden
]
end
...
...
app/models/db_stream.rb
View file @
e859908b
...
...
@@ -8,5 +8,4 @@ class DbStream < ActiveRecord::Base
def
as_json
(
_options
=
{})
super
(
except:
[
:created_at
,
:updated_at
])
end
end
app/services/db/update_db.rb
View file @
e859908b
...
...
@@ -60,9 +60,11 @@ 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
)
info_entry
=
entries
.
detect
{
|
entry
|
entry
[
:chunks
]
==
[
'info'
]}
||
{}
def
__read_info_entry
(
entries
)
info_entry
=
entries
.
detect
do
|
entry
|
entry
[
:chunks
]
==
[
'info'
]
end
info_entry
||=
{}
# 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
)
...
...
@@ -87,8 +89,8 @@ 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
(
*
folder
.
defined_attributes
))
folder
.
update_attributes
(
info
.
slice
(
*
folder
.
defined_attributes
))
folder
.
save!
folder
end
...
...
@@ -139,20 +141,10 @@ class UpdateDb # rubocop:disable Metrics/ClassLength
# determine if the entry groups constitute a single file
def
file?
(
entry_group
)
# if any entry_group has multiple chunks left or if the
# last chunk is 'info', this is a folder
folder_entries
=
entry_group
.
select
{
|
entry
|
entry
[
:chunks
].
length
>
1
||
entry
[
:chunks
][
0
]
==
'info'
}.
count
if
(
folder_entries
>
0
)
return
false
end
# if the path's are the same up to a ~decimXX suffix
# this is a file, otherwise return false
num_files
=
entry_group
.
map
{
|
entry
|
entry
[
:path
].
gsub
(
decimation_tag
,
''
)
}.
uniq
.
count
num_files
==
1
# if any entry_group has chunks left, this is a folder
entry_group
.
select
{
|
entry
|
!
entry
[
:chunks
].
empty?
}.
count
==
0
end
# create or update a DbFile object at the
...
...
spec/factories/db_schema_helper.rb
View file @
e859908b
...
...
@@ -4,9 +4,8 @@
# are usually returned by DbAdapter.schema
class
DbSchemaHelper
# schema data
# rubocop:disable Metrics/MethodLength
def
entry
(
path
,
type:
'uint8_1'
,
metadata:
{},
stream_count:
0
)
data
=
{
{
path:
path
,
attributes:
{
data_type:
type
,
...
...
@@ -16,7 +15,6 @@ class DbSchemaHelper
total_time:
0
}.
merge
(
metadata
),
streams:
__build_streams
(
stream_count
)
}
end
# rubocop:enable Metrics/MethodLength
...
...
spec/models/db_file_spec.rb
View file @
e859908b
...
...
@@ -9,7 +9,6 @@ RSpec.describe 'DbFile' do
specify
{
expect
(
db_file
).
to
respond_to
(
:description
)
}
specify
{
expect
(
db_file
).
to
respond_to
(
:db_streams
)
}
specify
{
expect
(
db_file
).
to
respond_to
(
:hidden
)
}
end
describe
'remove'
do
...
...
spec/models/db_folder_spec.rb
View file @
e859908b
...
...
@@ -10,7 +10,6 @@ RSpec.describe 'DbFolder' do
specify
{
expect
(
db_folder
).
to
respond_to
(
:subfolders
)
}
specify
{
expect
(
db_folder
).
to
respond_to
(
:db_files
)
}
specify
{
expect
(
db_folder
).
to
respond_to
(
:hidden
)
}
end
describe
'insert_file'
do
...
...
spec/models/db_stream_spec.rb
View file @
e859908b
...
...
@@ -13,6 +13,5 @@ RSpec.describe 'DbStream' do
specify
{
expect
(
db_stream
).
to
respond_to
(
:offset
)
}
specify
{
expect
(
db_stream
).
to
respond_to
(
:plottable
)
}
specify
{
expect
(
db_stream
).
to
respond_to
(
:discrete
)
}
end
end
spec/services/db/update_db_spec.rb
View file @
e859908b
...
...
@@ -114,10 +114,17 @@ describe 'UpdateDb' do
# corner cases
describe
'cornercases:'
do
it
'handles empty folders'
do
schema
=
[
helper
.
entry
(
'/folder_lonley/info'
,
metadata:
{
name:
'lonely'
})]
schema
=
[
helper
.
entry
(
'/folder_lonley/info'
,
metadata:
{
name:
'lonely'
})]
update_with_schema
(
schema
)
expect
(
@root
.
subfolders
.
find_by_name
(
'lonely'
)).
to
be_present
end
it
'handles chains of folders'
do
schema
=
[
helper
.
entry
(
'/fa/fb/data'
,
metadata:
{
name:
'the_file'
})]
update_with_schema
(
schema
)
file
=
DbFile
.
find_by_name
(
'the_file'
)
expect
(
file
.
db_folder
.
parent
.
parent
).
to
eq
(
@root
)
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