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
529e3b06
authored
Jun 18, 2017
by
John Doe
Browse files
Options
_('Browse Files')
Download
Email Patches
Plain Diff
add info streams on demand when folder is customized
parent
83003a9f
Show whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
27 additions
and
0 deletions
app/adapters/db_adapter.rb
spec/adapters/db_adapter_spec.rb
app/adapters/db_adapter.rb
View file @
529e3b06
...
...
@@ -99,6 +99,8 @@ class DbAdapter
end
def
set_folder_metadata
(
db_folder
)
# always try to create the info stream, this fails silently if it exists
__create_stream
(
"
#{
db_folder
.
path
}
/info"
,
"uint8_1"
)
_set_path_metadata
(
"
#{
db_folder
.
path
}
/info"
,
__build_folder_metadata
(
db_folder
))
end
...
...
@@ -202,6 +204,24 @@ class DbAdapter
__sanitize_metadata
(
metadata
)
end
# create a new stream on the database
def
__create_stream
(
path
,
dtype
)
params
=
{
path:
path
,
layout:
dtype
}.
to_json
begin
response
=
self
.
class
.
post
(
"
#{
@url
}
/stream/create"
,
body:
params
,
headers:
{
'Content-Type'
=>
'application/json'
})
rescue
return
{
error:
true
,
msg:
'cannot contact NilmDB server'
}
end
unless
response
.
success?
Rails
.
logger
.
warn
(
"
#{
@url
}
: create(
#{
path
}
)"
\
" =>
#{
response
.
code
}
:
#{
response
.
body
}
"
)
return
{
error:
true
,
msg:
"error creating
#{
path
}
"
}
end
{
error:
false
,
msg:
'success'
}
end
# make sure all the keys are valid parameters
# this function does not know the difference between folders and streams
# this *should* be ok as long as nobody tinkers with the config_key__ entries
...
...
spec/adapters/db_adapter_spec.rb
View file @
529e3b06
...
...
@@ -50,6 +50,13 @@ describe DbAdapter do
result
=
adapter
.
set_folder_metadata
(
folder
)
expect
(
result
[
:error
]).
to
be
false
end
it
'creates info stream if missing'
,
:vcr
do
adapter
=
DbAdapter
.
new
(
url
)
folder
=
DbFolder
.
new
(
path:
'/v2_folder/another'
,
name:
'another'
,
description:
'new'
)
result
=
adapter
.
set_folder_metadata
(
folder
)
expect
(
result
[
:error
]).
to
be
false
end
it
'returns error on server failure'
,
:vcr
do
adapter
=
DbAdapter
.
new
(
url
)
folder
=
DbFolder
.
new
(
path:
'/badpath'
)
...
...
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