Class: UCL
- Inherits:
-
Object
- Object
- UCL
- Defined in:
- ext/ucl.c,
ext/ucl.c
Overview
UCL configuration file.
Defined Under Namespace
Classes: Error
Constant Summary collapse
- KEY_LOWERCASE =
Constants
INT2FIX(UCL_PARSER_KEY_LOWERCASE)
- NO_TIME =
INT2FIX(UCL_PARSER_NO_TIME )
- DISABLE_MACRO =
INT2FIX(UCL_PARSER_DISABLE_MACRO)
- NO_FILEVARS =
INT2FIX(UCL_PARSER_NO_FILEVARS )
- KEY_SYMBOL =
INT2FIX(UCL_PARSER_KEY_SYMBOL )
Class Method Summary collapse
- .flags ⇒ Object
- .flags=(val) ⇒ Object
-
.load_file(*args) ⇒ Object
Load configuration file.
-
.parse(*args) ⇒ Object
Parse a configuration file.
Class Method Details
.flags ⇒ Object
111 112 113 114 115 |
# File 'ext/ucl.c', line 111
static VALUE
ucl_s_get_flags(VALUE klass)
{
return rb_iv_get(klass, "@flags");
}
|
.flags=(val) ⇒ Object
118 119 120 121 122 123 124 |
# File 'ext/ucl.c', line 118
static VALUE
ucl_s_set_flags(VALUE klass, VALUE val)
{
rb_check_type(val, T_FIXNUM);
rb_iv_set(klass, "@flags", val);
return val;
}
|
.load_file(*args) ⇒ Object
Load configuration file
181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 |
# File 'ext/ucl.c', line 181
static VALUE
ucl_s_load_file(int argc, VALUE *argv, VALUE klass)
{
VALUE file, flags;
rb_scan_args(argc, argv, "11", &file, &flags);
if (NIL_P(flags)) flags = ucl_s_get_flags(mUCL);
rb_check_type(file, T_STRING);
rb_check_type(flags, T_FIXNUM);
int c_flags = FIX2INT(flags) & ucl_allowed_flags;
char *c_file = StringValueCStr(file);
struct ucl_parser *parser =
ucl_parser_new(c_flags | UCL_PARSER_NO_IMPLICIT_ARRAYS);
ucl_parser_add_file(parser, c_file);
if (ucl_parser_get_error(parser)) {
const char *errormsg = ucl_parser_get_error(parser);
if (parser != NULL) { ucl_parser_free(parser); }
rb_raise(eUCLError, "%s", errormsg);
}
ucl_object_t *root = ucl_parser_get_object(parser);
VALUE res = _iterate_valid_ucl(root, FIX2INT(flags));
if (parser != NULL) { ucl_parser_free(parser); }
if (root != NULL) { ucl_object_unref(root); }
return res;
}
|
.parse(*args) ⇒ Object
Parse a configuration file
135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 |
# File 'ext/ucl.c', line 135
static VALUE
ucl_s_parse(int argc, VALUE *argv, VALUE klass)
{
VALUE data, flags;
rb_scan_args(argc, argv, "11", &data, &flags);
if (NIL_P(flags)) flags = ucl_s_get_flags(mUCL);
rb_check_type(data, T_STRING);
rb_check_type(flags, T_FIXNUM);
int c_flags = FIX2INT(flags) & ucl_allowed_flags;
struct ucl_parser *parser =
ucl_parser_new(c_flags | UCL_PARSER_NO_IMPLICIT_ARRAYS);
ucl_parser_add_chunk(parser,
(unsigned char *)RSTRING_PTR(data),
RSTRING_LEN(data));
if (ucl_parser_get_error(parser)) {
const char *errormsg = ucl_parser_get_error(parser);
if (parser != NULL) { ucl_parser_free(parser); }
rb_raise(eUCLError, "%s", errormsg);
}
ucl_object_t *root = ucl_parser_get_object(parser);
VALUE res = _iterate_valid_ucl(root, FIX2INT(flags));
if (parser != NULL) { ucl_parser_free(parser); }
if (root != NULL) { ucl_object_unref(root); }
return res;
}
|