Class: LibCDB::CDB::Writer
- Inherits:
-
Object
- Object
- LibCDB::CDB::Writer
- Defined in:
- ext/libcdb/ruby_cdb_writer.c
Instance Method Summary collapse
-
#close ⇒ nil
Closes writer, as well as the underlying IO object.
- #closed? ⇒ Boolean
-
#new(io) ⇒ aWriter
constructor
Creates a new Writer instance to interface with
io. -
#insert(*args) ⇒ Object
Stores records in the database and returns writer.
- #inspect ⇒ Object
-
#replace(*args) ⇒ Object
(also: #[]=)
Stores records in the database and returns writer.
-
#store(*args) ⇒ Object
(also: #<<, #add)
Stores records in the database and returns writer.
Constructor Details
#new(io) ⇒ aWriter
Creates a new Writer instance to interface with io. io must be opened for writing (w); in addition, it must be opened for read-write (w+) if #insert or #replace are to be used.
26 27 28 29 30 31 32 33 34 35 |
# File 'ext/libcdb/ruby_cdb_writer.c', line 26
static VALUE
rcdb_writer_initialize(VALUE self, VALUE io) {
RCDB_INITIALIZE(writ, WRIT, cdb_make, make_start)
if (lseek(cdb_fileno(ptr), 0, SEEK_SET) == -1) {
rb_sys_fail(0);
}
return self;
}
|
Instance Method Details
#close ⇒ nil
Closes writer, as well as the underlying IO object.
233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 |
# File 'ext/libcdb/ruby_cdb_writer.c', line 233
static VALUE
rcdb_writer_close(VALUE self) {
struct cdb_make *cdbm = NULL;
if (RTEST(rcdb_writer_closed_p(self))) {
return Qnil;
}
RCDB_WRITER_GET(self, cdbm);
rb_iv_set(self, "closed", Qtrue);
if (cdb_make_finish(cdbm) == -1) {
rb_sys_fail(0);
}
rb_io_close(rb_iv_get(self, "@io"));
return Qnil;
}
|
#closed? ⇒ Boolean
#insert(key, val) ⇒ Object #insert(key, [val, ...]) ⇒ Object #insert([key, ...]) ⇒ Object #insert({ key) ⇒ Object
Stores records in the database and returns writer. Records will only be inserted if they don’t already exist in the database.
The arguments are treated the same as in #store, so duplicate keys in the arguments will produce multiple records.
222 223 224 225 |
# File 'ext/libcdb/ruby_cdb_writer.c', line 222
static VALUE
rcdb_writer_insert(int argc, VALUE *argv, VALUE self) {
return rcdb_writer_put(argc, argv, self, CDB_PUT_INSERT);
}
|
#inspect ⇒ Object
#replace(key, val) ⇒ Object #replace(key, [val, ...]) ⇒ Object #replace([key, ...]) ⇒ Object #replace({ key) ⇒ Object Also known as: []=
Stores records in the database and returns writer. Records with duplicate keys are replaced.
The arguments are treated the same as in #store, so duplicate keys in the arguments will produce multiple records.
204 205 206 207 |
# File 'ext/libcdb/ruby_cdb_writer.c', line 204
static VALUE
rcdb_writer_replace(int argc, VALUE *argv, VALUE self) {
return rcdb_writer_put(argc, argv, self, CDB_PUT_REPLACE);
}
|
#store(key, val) ⇒ Object #store(key, [val, ...]) ⇒ Object #store([key, ...]) ⇒ Object #store({ key) ⇒ Object Also known as: <<, add
Stores records in the database and returns writer. Records are stored unconditionally, so duplicate keys will produce multiple records.
If a single key/value pair is given, a record with key key and value val is created; if val is an array, one record per value is created for key. If an array of keys is given, one record per key with an empty value is created. If a hash of key/value pairs is given, one record per key/value pair is created; the same logic as for a single key/value pair applies.
186 187 188 189 |
# File 'ext/libcdb/ruby_cdb_writer.c', line 186
static VALUE
rcdb_writer_store(int argc, VALUE *argv, VALUE self) {
return rcdb_writer_put(argc, argv, self, CDB_PUT_ADD);
}
|