[Pkg-javascript-commits] [node-leveldown] 190/492: _location -> location exposed as read-only
Andrew Kelley
andrewrk-guest at moszumanska.debian.org
Sun Jul 6 17:13:58 UTC 2014
This is an automated email from the git hooks/post-receive script.
andrewrk-guest pushed a commit to annotated tag rocksdb-0.10.1
in repository node-leveldown.
commit 02026ac1b63c4f3d15a2a01d54288c3168d6a61a
Author: Rod Vagg <rod at vagg.org>
Date: Mon Jan 28 11:20:21 2013 +1100
_location -> location exposed as read-only
---
README.md | 8 ++--
lib/levelup.js | 9 +++-
test/compression-test.js | 8 ++--
test/deferred-open-test.js | 4 +-
test/read-stream-test.js | 2 +-
test/simple-test.js | 109 +++++++++++++++++++++++----------------------
6 files changed, 74 insertions(+), 66 deletions(-)
diff --git a/README.md b/README.md
index f92da98..864893d 100644
--- a/README.md
+++ b/README.md
@@ -29,11 +29,11 @@ See also a list of <a href="https://github.com/rvagg/node-levelup/wiki/Modules">
Tested & supported platforms
----------------------------
- * **Linux** (tested on Ubuntu)
+ * **Linux** (including ARM platforms such as Raspberry Pi)
* **Mac OS**
- * **Solaris** (tested on SmartOS & Nodejitsu)
+ * **Solaris** (SmartOS & Nodejitsu)
-**Windows** support is coming soon; see [issue #5](https://github.com/rvagg/node-levelup/issues/5) if you would like to help on that front.
+**Windows** support is a work in progress; see [issue #5](https://github.com/rvagg/node-levelup/issues/5) if you would like to help on that front.
<a name="basic"></a>
Basic usage
@@ -108,6 +108,8 @@ db.get('foo', function (err, value) {
})
```
+The `location` argument is available as a read-only property on the returned LevelUP instance.
+
#### `options`
`levelup()` takes an optional options object as its second argument; the following properties are accepted:
diff --git a/lib/levelup.js b/lib/levelup.js
index 4c2a9ec..8075bdd 100644
--- a/lib/levelup.js
+++ b/lib/levelup.js
@@ -82,7 +82,12 @@ var bridge = require('bindings')('levelup.node')
this.setMaxListeners(Infinity)
this._options = extend(extend({}, defaultOptions), options)
- this._location = location
+ Object.defineProperty(this, 'location', {
+ value: location
+ , configurable: false
+ , enumerable: true
+ , writable: false
+ })
}
inherits(LevelUP, EventEmitter)
@@ -102,7 +107,7 @@ var bridge = require('bindings')('levelup.node')
var execute = function () {
var db = bridge.createDatabase()
- db.open(this._location, this._options, function (err) {
+ db.open(this.location, this._options, function (err) {
if (err) {
err = new errors.OpenError(err)
if (callback)
diff --git a/test/compression-test.js b/test/compression-test.js
index b3ba4e6..59b5f63 100644
--- a/test/compression-test.js
+++ b/test/compression-test.js
@@ -29,7 +29,7 @@ var buster = require('buster')
// close, open, close again.. 'compaction' is also performed on open()s
, cycle = function (db, compression, callback) {
- var location = db._location
+ var location = db.location
db.close(function (err) {
if (err) return refute(err)
levelup(location, { errorIfExists: false, compression: compression }, function (err, db) {
@@ -56,7 +56,7 @@ buster.testCase('Compression', {
, function (args, callback) {
db.put.apply(db, args.concat([callback]))
}
- , cycle.bind(null, db, true, delayed.delayed(verify.bind(null, db._location, true, done), 0.01))
+ , cycle.bind(null, db, true, delayed.delayed(verify.bind(null, db.location, true, done), 0.01))
)
})
}
@@ -70,7 +70,7 @@ buster.testCase('Compression', {
, function (args, callback) {
db.put.apply(db, args.concat([callback]))
}
- , cycle.bind(null, db, false, delayed.delayed(verify.bind(null, db._location, false, done), 0.01))
+ , cycle.bind(null, db, false, delayed.delayed(verify.bind(null, db.location, false, done), 0.01))
)
})
}
@@ -81,7 +81,7 @@ buster.testCase('Compression', {
Array.apply(null, Array(multiples)).map(function (e, i) {
return { type: 'put', key: i, value: compressableData }
})
- , cycle.bind(null, db, false, delayed.delayed(verify.bind(null, db._location, false, done), 0.01))
+ , cycle.bind(null, db, false, delayed.delayed(verify.bind(null, db.location, false, done), 0.01))
)
})
}
diff --git a/test/deferred-open-test.js b/test/deferred-open-test.js
index 9f7d9eb..8386048 100644
--- a/test/deferred-open-test.js
+++ b/test/deferred-open-test.js
@@ -21,7 +21,7 @@ buster.testCase('Deferred open()', {
this.closeableDatabases.push(db)
this.cleanupDirs.push(location)
assert.isObject(db)
- assert.equals(db._location, location)
+ assert.equals(db.location, location)
async.parallel([
// 2) insert 3 values with put(), these should be deferred until the database is actually open
@@ -64,7 +64,7 @@ buster.testCase('Deferred open()', {
this.closeableDatabases.push(db)
this.cleanupDirs.push(location)
assert.isObject(db)
- assert.equals(db._location, location)
+ assert.equals(db.location, location)
// 2) insert 3 values with batch(), these should be deferred until the database is actually open
db.batch([
diff --git a/test/read-stream-test.js b/test/read-stream-test.js
index f59975e..680d4cd 100644
--- a/test/read-stream-test.js
+++ b/test/read-stream-test.js
@@ -550,7 +550,7 @@ buster.testCase('ReadStream', {
refute(err)
db.close(function (err) {
refute(err)
- var db2 = levelup(db._location, { createIfMissing: false, errorIfExists: false, encoding: 'utf8' })
+ var db2 = levelup(db.location, { createIfMissing: false, errorIfExists: false, encoding: 'utf8' })
execute(db2)
})
}.bind(this))
diff --git a/test/simple-test.js b/test/simple-test.js
index 4304891..6693a66 100644
--- a/test/simple-test.js
+++ b/test/simple-test.js
@@ -37,13 +37,12 @@ buster.testCase('Basic API', {
assert.isObject(db)
assert.isTrue(db._options.createIfMissing)
assert.isFalse(db._options.errorIfExists)
- assert.equals(db._location, location)
+ assert.equals(db.location, location)
- /*
// read-only properties
db.location = 'foo'
assert.equals(db.location, location)
- */
+
done()
}.bind(this))
}.bind(this))
@@ -60,27 +59,27 @@ buster.testCase('Basic API', {
assert.isObject(db)
assert.isTrue(db._options.createIfMissing)
assert.isTrue(db._options.errorIfExists)
- assert.equals(db._location, location)
+ assert.equals(db.location, location)
+
- /*
// read-only properties
- db._location = 'bar'
- assert.equals(db._location, location)
- */
+ db.location = 'bar'
+ assert.equals(db.location, location)
+
done()
}.bind(this))
}
, 'without callback': function (done) {
var location = common.nextLocation()
- var db = levelup(location, { createIfMissing: true, errorIfExists: true })
+ , db = levelup(location, { createIfMissing: true, errorIfExists: true })
this.closeableDatabases.push(db)
this.cleanupDirs.push(location)
assert.isObject(db)
assert.isTrue(db._options.createIfMissing)
assert.isTrue(db._options.errorIfExists)
- assert.equals(db._location, location)
+ assert.equals(db.location, location)
db.on("ready", function () {
assert.isTrue(db.isOpen())
@@ -425,53 +424,55 @@ buster.testCase('Basic API', {
, 'approximateSize() work on none-empty database': function(done) {
var location = common.nextLocation()
- var db
- async.series(
- [
- function (callback) {
- this.openTestDatabase(
- location
- , function (_db) {
- db = _db
- callback()
- }
- )
- }.bind(this)
- , function (callback) {
- var batch = [];
- for(var i = 0; i < 10; ++i) {
- batch.push({
- type: 'put', key: String(i), value: 'afoovalue'
- });
+ , db
+
+ async.series(
+ [
+ function (callback) {
+ this.openTestDatabase(
+ location
+ , function (_db) {
+ db = _db
+ callback()
}
- db.batch(
- batch
- , { sync: true }
- , callback
- )
- }
- , function (callback) {
- // close db to make sure stuff gets written to disc
- db.close(callback)
- }
- , function (callback) {
- levelup(location, function (err, _db) {
- refute(err)
- db = _db
- callback()
- }
- )
- }
- , function (callback) {
- db.approximateSize('', '99', function(err, size) {
- refute(err) // sanity
- refute.equals(size, 0)
- done()
+ )
+ }.bind(this)
+ , function (callback) {
+ var batch = []
+ , i = 0
+
+ for (; i < 10; ++i) {
+ batch.push({
+ type: 'put', key: String(i), value: 'afoovalue'
})
}
- ]
- , done
- )
+ db.batch(
+ batch
+ , { sync: true }
+ , callback
+ )
+ }
+ , function (callback) {
+ // close db to make sure stuff gets written to disc
+ db.close(callback)
+ }
+ , function (callback) {
+ levelup(location, function (err, _db) {
+ refute(err)
+ db = _db
+ callback()
+ })
+ }
+ , function (callback) {
+ db.approximateSize('', '99', function(err, size) {
+ refute(err) // sanity
+ refute.equals(size, 0)
+ callback()
+ })
+ }
+ ]
+ , done
+ )
}
}
--
Alioth's /usr/local/bin/git-commit-notice on /srv/git.debian.org/git/pkg-javascript/node-leveldown.git
More information about the Pkg-javascript-commits
mailing list