Class: Gnista::Logwriter

Inherits:
Object
  • Object
show all
Defined in:
lib/gnista.rb,
ext/gnista/gnista.c

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(args) ⇒ Object



70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
# File 'ext/gnista/gnista.c', line 70

static VALUE method_logwriter_initialize(VALUE self, VALUE args) {
	sparkey_returncode returncode;
	instance_logwriter *i_logwriter = get_logwriter(self);
	int len = RARRAY_LEN(args);

	if (len > 2 || len == 0) {
		rb_raise(rb_eArgError, "Wrong number of arguments");
	}

	Check_Type(rb_ary_entry(args, 0), T_STRING);

	if (len == 2) {
		if (TYPE(rb_ary_entry(args, 1)) == T_SYMBOL && (rb_to_id(rb_ary_entry(args, 1)) == rb_intern("append"))) {
			returncode = sparkey_logwriter_append(&i_logwriter->logwriter, RSTRING_PTR(rb_ary_entry(args, 0)));
		} else if (TYPE(rb_ary_entry(args, 1)) == T_FIXNUM) {
			returncode = sparkey_logwriter_create(&i_logwriter->logwriter, RSTRING_PTR(rb_ary_entry(args, 0)), SPARKEY_COMPRESSION_SNAPPY, NUM2INT(rb_ary_entry(args, 1)));
		} else {
			rb_raise(rb_eArgError, "Invalid arguments");
		}
	} else {
		returncode = sparkey_logwriter_create(&i_logwriter->logwriter, RSTRING_PTR(rb_ary_entry(args, 0)), SPARKEY_COMPRESSION_NONE, 0);
	}

	if (returncode != SPARKEY_SUCCESS) {
		raise_sparkey(returncode);
	} else {
		i_logwriter->open = true;
		rb_iv_set(self, "@logpath", rb_ary_entry(args, 0));
	}

	return self;
}

Instance Attribute Details

#logpathObject (readonly)

Returns the value of attribute logpath.



6
7
8
# File 'lib/gnista.rb', line 6

def logpath
  @logpath
end

Instance Method Details

#closeObject Also known as: close!



103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
# File 'ext/gnista/gnista.c', line 103

static VALUE method_logwriter_close(VALUE self) {
	sparkey_returncode returncode;
	instance_logwriter *i_logwriter = get_logwriter(self);
	check_open(i_logwriter->open);

	returncode = sparkey_logwriter_close(&i_logwriter->logwriter);

	if (returncode != SPARKEY_SUCCESS) {
		raise_sparkey(returncode);
	}

	i_logwriter->open = false;

	return Qnil;
}

#delete(key) ⇒ Object Also known as: del



135
136
137
138
139
140
141
142
143
144
145
146
147
148
# File 'ext/gnista/gnista.c', line 135

static VALUE method_logwriter_delete(VALUE self, VALUE key) {
	sparkey_returncode returncode;
	instance_logwriter *i_logwriter = get_logwriter(self);
	check_open(i_logwriter->open);
	Check_Type(key, T_STRING);

	returncode = sparkey_logwriter_delete(i_logwriter->logwriter, RSTRING_LEN(key), (uint8_t*)RSTRING_PTR(key));

	if (returncode != SPARKEY_SUCCESS) {
		raise_sparkey(returncode);
	}

	return Qnil;
}

#flushObject



150
151
152
153
154
155
156
157
158
159
160
161
162
# File 'ext/gnista/gnista.c', line 150

static VALUE method_logwriter_flush(VALUE self) {
	sparkey_returncode returncode;
	instance_logwriter *i_logwriter = get_logwriter(self);
	check_open(i_logwriter->open);

	returncode = sparkey_logwriter_flush(i_logwriter->logwriter);

	if (returncode != SPARKEY_SUCCESS) {
		raise_sparkey(returncode);
	}

	return Qnil;
}

#inspectObject



13
14
15
# File 'lib/gnista.rb', line 13

def inspect
  %(#<#{self.class} #{@logpath.inspect}>)
end

#open?Boolean

Returns:

  • (Boolean)


164
165
166
167
168
169
170
171
172
# File 'ext/gnista/gnista.c', line 164

static VALUE method_logwriter_open(VALUE self) {
	instance_logwriter *i_logwriter = get_logwriter(self);

	if (i_logwriter->open) {
		return Qtrue;
	} else {
		return Qfalse;
	}
}

#put(key, val) ⇒ Object Also known as: []=



119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
# File 'ext/gnista/gnista.c', line 119

static VALUE method_logwriter_put(VALUE self, VALUE key, VALUE val) {
	sparkey_returncode returncode;
	instance_logwriter *i_logwriter = get_logwriter(self);
	check_open(i_logwriter->open);
	Check_Type(key, T_STRING);
	Check_Type(val, T_STRING);

	returncode = sparkey_logwriter_put(i_logwriter->logwriter, RSTRING_LEN(key), (uint8_t*)RSTRING_PTR(key), RSTRING_LEN(val), (uint8_t*)RSTRING_PTR(val));

	if (returncode != SPARKEY_SUCCESS) {
		raise_sparkey(returncode);
	}

	return Qnil;
}

#write_batchObject



8
9
10
11
# File 'lib/gnista.rb', line 8

def write_batch
  yield if block_given?
  flush
end