File tree Expand file tree Collapse file tree 2 files changed +20
-1
lines changed
Expand file tree Collapse file tree 2 files changed +20
-1
lines changed Original file line number Diff line number Diff line change @@ -4,7 +4,14 @@ const promisify = require('then-flat-file-db')
44const escapeRegexp = require ( 'escape-regex' )
55const Observable = require ( "zen-observable" )
66
7- const db = promisify ( flatfile . sync ( path . resolve ( process . cwd ( ) , process . env . DB_NAME || 'views.db' ) ) )
7+ let db
8+
9+ function init ( options ) {
10+ db = promisify ( flatfile . sync ( path . resolve ( process . cwd ( ) , options . dbName || 'views.db' ) ) )
11+ }
12+
13+ // This is here for backwards compatability should be removed at some point
14+ init ( { dbName : process . env . DB_NAME } )
815
916const keyRegex = ( str ) => {
1017 str = str . split ( '*' ) . map ( s => escapeRegexp ( s ) ) . join ( '*' )
@@ -23,6 +30,14 @@ const observable = new Observable((observer) => {
2330} ) ;
2431
2532module . exports = {
33+ options : [
34+ {
35+ name : 'db-name' ,
36+ description : 'The name of the flat-file-db file.' ,
37+ defaultValue : process . env . DB_NAME || 'views.db'
38+ }
39+ ] ,
40+ init,
2641 put : ( key , value ) => {
2742 handlers . forEach ( handler => {
2843 handler ( { key, value} ) ;
Original file line number Diff line number Diff line change @@ -4,11 +4,15 @@ const promisify = require('then-flat-file-db')
44const test = require ( 'micro-analytics-cli/adapter-tests/unit-tests' )
55
66const db = promisify ( flatfile . sync ( path . resolve ( process . cwd ( ) , process . env . DB_NAME || 'views.db' ) ) )
7+ const adapter = require ( './index' )
78
89
910test ( {
1011 name : 'flat-file-db' ,
1112 modulePath : path . resolve ( __dirname , './index.js' ) ,
13+ beforeAll : ( ) => {
14+ adapter . init ( { dbName : 'views.db' } )
15+ } ,
1216 beforeEach : ( ) => {
1317 return db . clear ( ) ;
1418 }
You can’t perform that action at this time.
0 commit comments