Class: Rubydex::Config

Inherits:
Object
  • Object
show all
Defined in:
ext/rubydex/config.c

Class Method Summary collapse

Instance Method Summary collapse

Class Method Details

.Rubydex::Config.load(workspace_path) ⇒ Rubydex::Config

Loads the configuration of the workspace rooted at workspace_path, which is where its rubydex.toml is expected to be. A workspace without a configuration file gets an empty configuration. Raises Rubydex::ConfigError if the file exists, but cannot be read or is malformed.

Returns:



87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
# File 'ext/rubydex/config.c', line 87

static VALUE rdxr_config_load(VALUE klass, VALUE workspace_path) {
    Check_Type(workspace_path, T_STRING);

    struct CConfigResult result = rdx_config_load(StringValueCStr(workspace_path));
    if (result.error != NULL) {
        VALUE message = rb_utf8_str_new_cstr(result.error);
        free_c_string(result.error);

        VALUE config_error = rb_const_get(mRubydex, rb_intern("ConfigError"));
        rb_exc_raise(rb_exc_new_str(config_error, message));
    }

    VALUE config = TypedData_Wrap_Struct(klass, &config_type, result.config);
    rb_ivar_set(config, id_linter, config_linter(config));

    return config;
}

Instance Method Details

#workspace_pathString

Returns the root directory of the workspace this configuration was loaded for.

Returns:

  • (String)


111
112
113
114
115
116
117
118
119
120
# File 'ext/rubydex/config.c', line 111

static VALUE rdxr_config_workspace_path(VALUE self) {
    const char *result = rdx_config_workspace_path(rdxi_config_from_object(self));
    // A configuration always has a workspace, so there is no absent case to hand back to Ruby. NULL only means the
    // conversion itself failed, which is why this raises instead of returning nil.
    if (result == NULL) {
        rb_raise(rb_eRuntimeError, "Converting workspace path to Ruby string failed");
    }

    return rdxi_owned_c_string_to_ruby(result);
}