Class: Rubydex::Definition

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

Instance Method Summary collapse

Constructor Details

#initializeObject

Instance Method Details

#commentsObject

Definition#comments -> [Rubydex::Comment]



88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
# File 'ext/rubydex/definition.c', line 88

static VALUE rdxr_definition_comments(VALUE self) {
    HandleData *data;
    TypedData_Get_Struct(self, HandleData, &handle_type, data);

    void *graph;
    TypedData_Get_Struct(data->graph_obj, void *, &graph_type, graph);

    CommentArray *arr = rdx_definition_comments(graph, data->id);
    if (arr == NULL || arr->len == 0) {
        if (arr != NULL) {
            rdx_definition_comments_free(arr);
        }
        return rb_ary_new();
    }

    VALUE ary = rb_ary_new_capa((long)arr->len);
    for (size_t i = 0; i < arr->len; i++) {
        CommentEntry entry = arr->items[i];

        VALUE string = rb_utf8_str_new_cstr(entry.string);

        Location *loc = entry.location;
        VALUE location = rdxi_build_location_value(loc);

        VALUE comment_kwargs = rb_hash_new();
        rb_hash_aset(comment_kwargs, ID2SYM(rb_intern("string")), string);
        rb_hash_aset(comment_kwargs, ID2SYM(rb_intern("location")), location);
        VALUE comment = rb_class_new_instance_kw(1, &comment_kwargs, cComment, RB_PASS_KEYWORDS);

        rb_ary_push(ary, comment);
    }

    // Free the array and all inner allocations on the Rust side
    rdx_definition_comments_free(arr);
    return ary;
}

#deprecated?Boolean

Definition#deprecated? -> bool

Returns:

  • (Boolean)


143
144
145
146
147
148
149
150
151
152
# File 'ext/rubydex/definition.c', line 143

static VALUE rdxr_definition_deprecated(VALUE self) {
    HandleData *data;
    TypedData_Get_Struct(self, HandleData, &handle_type, data);

    void *graph;
    TypedData_Get_Struct(data->graph_obj, void *, &graph_type, graph);

    bool deprecated = rdx_definition_is_deprecated(graph, data->id);
    return deprecated ? Qtrue : Qfalse;
}

#locationObject

Definition#location -> Rubydex::Location



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

static VALUE rdxr_definition_location(VALUE self) {
    HandleData *data;
    TypedData_Get_Struct(self, HandleData, &handle_type, data);

    void *graph;
    TypedData_Get_Struct(data->graph_obj, void *, &graph_type, graph);

    Location *loc = rdx_definition_location(graph, data->id);
    VALUE location = rdxi_build_location_value(loc);
    rdx_location_free(loc);

    return location;
}

#nameObject

Definition#name -> String



126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
# File 'ext/rubydex/definition.c', line 126

static VALUE rdxr_definition_name(VALUE self) {
    HandleData *data;
    TypedData_Get_Struct(self, HandleData, &handle_type, data);

    void *graph;
    TypedData_Get_Struct(data->graph_obj, void *, &graph_type, graph);

    const char *name = rdx_definition_name(graph, data->id);
    if (name == NULL) {
        return Qnil;
    }
    VALUE str = rb_utf8_str_new_cstr(name);
    free_c_string(name);
    return str;
}

#name_locationObject

(e.g., “Bar” in “class Foo::Bar”). For other definition types, returns nil.



157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
# File 'ext/rubydex/definition.c', line 157

static VALUE rdxr_definition_name_location(VALUE self) {
    HandleData *data;
    TypedData_Get_Struct(self, HandleData, &handle_type, data);

    void *graph;
    TypedData_Get_Struct(data->graph_obj, void *, &graph_type, graph);

    Location *loc = rdx_definition_name_location(graph, data->id);
    if (loc == NULL) {
        return Qnil;
    }
    VALUE location = rdxi_build_location_value(loc);
    rdx_location_free(loc);

    return location;
}