Module: Exportr

Defined in:
lib/exportr.rb,
lib/exportr/version.rb,
ext/exportr/exportr.c

Constant Summary collapse

VERSION =
"0.4.4"

Class Method Summary collapse

Class Method Details

.config_fileObject



23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
# File 'ext/exportr/exportr.c', line 23

static VALUE exportr_config_file ( void ) 
{
    VALUE filepath, frag;
    VALUE exists = Qfalse;

    int i;
    for ( i=0; 1; i++ ) {
        if ( d_scan[i] == 0 ) break;

        frag = rb_str_new2(d_scan[i]);
        if ( strlen(d_scan[i]) > 0 ) rb_str_cat2(frag, "/");
        rb_str_cat2(frag, FILE);

        filepath = rb_funcall(rb_file(), rb_intern("expand_path"), 1, frag);
        exists = rb_funcall(rb_file(), rb_intern("exists?"), 1, filepath);

        if ( TYPE(exists) == T_TRUE ) break;

        filepath = Qnil;
    }
    
    return filepath;
}

.exportObject



75
76
77
78
79
80
81
82
83
84
85
# File 'ext/exportr/exportr.c', line 75

static VALUE exportr_export ( void )
{
    VALUE hash = exportr_read();

    if ( TYPE(hash) == T_HASH ) {
        rb_hash_foreach(hash, *exportr_set_env, Qnil);
        return Qtrue;
    }    

    return Qfalse;
}

.readObject



61
62
63
64
65
66
67
68
69
70
71
72
73
# File 'ext/exportr/exportr.c', line 61

static VALUE exportr_read ( void )
{
    VALUE data;
    VALUE config = exportr_config_file();
    VALUE hash = Qnil;

    if ( TYPE(config) != T_NIL ) {
        data = rb_funcall(rb_file(), rb_intern("read"), 1, config);
        hash = rb_funcall(rb_yaml(), rb_intern("load"), 1, data);
        return hash;
    }    
    return Qnil;
}