Class: ladybug::Database

Inherits:
Object
  • Object
show all
Defined in:
ext/ladybug_ext/database.c

Instance Method Summary collapse

Constructor Details

#new(path, **options) ⇒ Object

Create a new Database using the given path and options.



103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
# File 'ext/ladybug_ext/database.c', line 103

static VALUE
rlbug_database_initialize( int argc, VALUE *argv, VALUE self )
{
	rlbug_database *ptr = CHECK_DATABASE( self );

	if ( !ptr ) {
		VALUE path, options, config;
		VALUE config_argv[1];
		lbug_system_config *sysconfig;
		char *database_path;

		rb_scan_args( argc, argv, "1:", &path, &options );
		if ( options == Qnil ) options = rb_hash_new();
		config_argv[0] = options;
		config = rb_funcallv_public_kw( rlbug_cLadybugConfig, rb_intern("from_options"), 1,
			config_argv, RB_PASS_KEYWORDS );

		sysconfig = rlbug_get_config( config );
		database_path = StringValueCStr( path );

		ptr = rlbug_database_alloc();
		if ( lbug_database_init(database_path, *sysconfig, &ptr->db) != LbugSuccess ) {
			xfree( ptr );
			ptr = NULL;

			rb_raise( rlbug_eDatabaseError, "Couldn't create database!" );
		}

		DEBUG_GC( ">>> allocated database %p\n", ptr );
		RTYPEDDATA_DATA( self ) = ptr;

		ptr->path = rb_obj_freeze( rb_obj_dup(path) );
		ptr->config = rb_obj_freeze( config );
	} else {
		rb_raise( rb_eRuntimeError, "cannot reinit database" );
	}

	rb_call_super( 0, 0 );

	return Qtrue;
}

Instance Method Details

#configObject

Return the Ladybug::Config that reflects the config options the database was created with.



154
155
156
157
158
159
# File 'ext/ladybug_ext/database.c', line 154

static VALUE
rlbug_database_config( VALUE self )
{
	rlbug_database *ptr = CHECK_DATABASE( self );
	return ptr->config;
}

#pathString?

Return the path the database was created with, or nil if it was created in memory.

Returns:

  • (String, nil)


171
172
173
174
175
176
177
178
179
180
181
# File 'ext/ladybug_ext/database.c', line 171

static VALUE
rlbug_database_path( VALUE self )
{
	rlbug_database *ptr = CHECK_DATABASE( self );

	if ( RSTRING_LEN(ptr->path) == 0 ) {
		return Qnil;
	} else {
		return ptr->path;
	}
}