plamo 0.2.0 → 0.3.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/.github/FUNDING.yml +12 -0
- data/Gemfile.lock +1 -1
- data/ext/plamo/plamo.c +5 -0
- data/ext/plamo/plamo.h +5 -0
- data/ext/plamo/plamo_app.c +26 -25
- data/ext/plamo/plamo_byte_array.c +28 -14
- data/ext/plamo/plamo_byte_array.h +1 -0
- data/ext/plamo/plamo_form_data.c +67 -0
- data/ext/plamo/plamo_form_data.h +6 -0
- data/ext/plamo/plamo_form_data_field.c +70 -0
- data/ext/plamo/plamo_form_data_field.h +9 -0
- data/ext/plamo/plamo_form_data_field_array.c +88 -0
- data/ext/plamo/plamo_form_data_field_array.h +9 -0
- data/ext/plamo/plamo_form_data_file.c +69 -0
- data/ext/plamo/plamo_form_data_file.h +9 -0
- data/ext/plamo/plamo_form_urlencoded.c +62 -0
- data/ext/plamo/plamo_form_urlencoded.h +6 -0
- data/ext/plamo/plamo_http_header.c +32 -31
- data/ext/plamo/plamo_http_header.h +1 -0
- data/ext/plamo/plamo_http_query.c +26 -21
- data/ext/plamo/plamo_http_query.h +1 -0
- data/ext/plamo/plamo_middleware.c +19 -18
- data/ext/plamo/plamo_middleware.h +1 -0
- data/ext/plamo/plamo_request.c +44 -45
- data/ext/plamo/plamo_request.h +1 -0
- data/ext/plamo/plamo_response.c +33 -33
- data/ext/plamo/plamo_response.h +1 -0
- data/ext/plamo/plamo_string_array.c +46 -27
- data/ext/plamo/plamo_string_array.h +1 -0
- data/lib/plamo/version.rb +1 -1
- metadata +13 -3
- data/ext/plamo/wrapper.h +0 -8
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 1c4ae5281f4f0bfe6afd2aa63ae96828864613a2151e4de30b12419c2a75cd50
|
4
|
+
data.tar.gz: c41e70ecd32f274461e6c20a287d13776dec0c2d49edb07bb286e501f5f3cb74
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 1f5627c7779b69bb216542f7e9c17fdda6ef49283a46223e893fbd813b77d35d79d0c365e5aed8ab2aaf13ec44f46c7f31557d90fd1558d3c2a73e7a825f2bab
|
7
|
+
data.tar.gz: 1afea3d6d614ca68e66b83dfc0a5c189362930732e7f047efd0d94b065ccf8008ca8d22755576df4161f181b72f7f8317e5df0f191217968a56a9e2f4fd77443
|
data/.github/FUNDING.yml
ADDED
@@ -0,0 +1,12 @@
|
|
1
|
+
# These are supported funding model platforms
|
2
|
+
|
3
|
+
github: [otake84] # Replace with up to 4 GitHub Sponsors-enabled usernames e.g., [user1, user2]
|
4
|
+
patreon: # Replace with a single Patreon username
|
5
|
+
open_collective: # Replace with a single Open Collective username
|
6
|
+
ko_fi: # Replace with a single Ko-fi username
|
7
|
+
tidelift: # Replace with a single Tidelift platform-name/package-name e.g., npm/babel
|
8
|
+
community_bridge: # Replace with a single Community Bridge project-name e.g., cloud-foundry
|
9
|
+
liberapay: # Replace with a single Liberapay username
|
10
|
+
issuehunt: # Replace with a single IssueHunt username
|
11
|
+
otechie: # Replace with a single Otechie username
|
12
|
+
custom: # Replace with up to 4 custom sponsorship URLs e.g., ['link1', 'link2']
|
data/Gemfile.lock
CHANGED
data/ext/plamo/plamo.c
CHANGED
@@ -10,6 +10,11 @@ void Init_plamo(void) {
|
|
10
10
|
Init_plamo_http_query();
|
11
11
|
Init_plamo_request();
|
12
12
|
Init_plamo_response();
|
13
|
+
Init_plamo_form_urlencoded();
|
14
|
+
Init_plamo_form_data_file();
|
15
|
+
Init_plamo_form_data_field();
|
16
|
+
Init_plamo_form_data_field_array();
|
17
|
+
Init_plamo_form_data();
|
13
18
|
Init_plamo_middleware();
|
14
19
|
Init_plamo_app();
|
15
20
|
}
|
data/ext/plamo/plamo.h
CHANGED
@@ -10,6 +10,11 @@
|
|
10
10
|
#include "plamo_http_query.h"
|
11
11
|
#include "plamo_request.h"
|
12
12
|
#include "plamo_response.h"
|
13
|
+
#include "plamo_form_urlencoded.h"
|
14
|
+
#include "plamo_form_data_file.h"
|
15
|
+
#include "plamo_form_data_field.h"
|
16
|
+
#include "plamo_form_data_field_array.h"
|
17
|
+
#include "plamo_form_data.h"
|
13
18
|
#include "plamo_middleware.h"
|
14
19
|
#include "plamo_app.h"
|
15
20
|
|
data/ext/plamo/plamo_app.c
CHANGED
@@ -1,46 +1,47 @@
|
|
1
1
|
#include "plamo.h"
|
2
|
-
#include "wrapper.h"
|
3
2
|
|
4
3
|
VALUE rb_cPlamoApp;
|
5
4
|
|
6
|
-
static void deallocate(
|
7
|
-
plamo_app_destroy(
|
8
|
-
free(wrapper);
|
5
|
+
static void deallocate(void *plamo_app) {
|
6
|
+
plamo_app_destroy(plamo_app);
|
9
7
|
}
|
10
8
|
|
9
|
+
const rb_data_type_t rb_plamo_app_type = {
|
10
|
+
"App",
|
11
|
+
{
|
12
|
+
NULL,
|
13
|
+
deallocate,
|
14
|
+
NULL,
|
15
|
+
},
|
16
|
+
NULL,
|
17
|
+
NULL,
|
18
|
+
0,
|
19
|
+
};
|
20
|
+
|
11
21
|
static VALUE allocate(VALUE klass) {
|
12
|
-
return
|
22
|
+
return TypedData_Wrap_Struct(klass, &rb_plamo_app_type, NULL);
|
13
23
|
}
|
14
24
|
|
15
25
|
static VALUE initialize(VALUE self) {
|
16
|
-
|
17
|
-
Data_Get_Struct(self, Wrapper, wrapper);
|
18
|
-
wrapper->inner = plamo_app_new();
|
26
|
+
DATA_PTR(self) = plamo_app_new();
|
19
27
|
return self;
|
20
28
|
}
|
21
29
|
|
22
30
|
static VALUE push_middleware(VALUE self, VALUE rb_plamo_middleware) {
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
|
27
|
-
plamo_app_add_middleware(
|
31
|
+
PlamoApp *plamo_app;
|
32
|
+
TypedData_Get_Struct(self, PlamoApp, &rb_plamo_app_type, plamo_app);
|
33
|
+
PlamoMiddleware *plamo_middleware;
|
34
|
+
TypedData_Get_Struct(rb_plamo_middleware, PlamoMiddleware, &rb_plamo_middleware_type, plamo_middleware);
|
35
|
+
plamo_app_add_middleware(plamo_app, plamo_middleware);
|
28
36
|
return Qnil;
|
29
37
|
}
|
30
38
|
|
31
39
|
static VALUE execute(VALUE self, VALUE rb_plamo_request) {
|
32
|
-
|
33
|
-
|
34
|
-
|
35
|
-
|
36
|
-
|
37
|
-
|
38
|
-
PlamoResponse *response = plamo_app_execute(wrapper->inner, plamo_request_wrapper->inner);
|
39
|
-
VALUE rb_plamo_response = Data_Wrap_Struct(rb_cPlamoResponse, NULL, free, malloc(sizeof(Wrapper)));
|
40
|
-
Wrapper *plamo_response_wrapper;
|
41
|
-
Data_Get_Struct(rb_plamo_response, Wrapper, plamo_response_wrapper);
|
42
|
-
plamo_response_wrapper->inner = response;
|
43
|
-
|
40
|
+
PlamoApp *plamo_app;
|
41
|
+
TypedData_Get_Struct(self, PlamoApp, &rb_plamo_app_type, plamo_app);
|
42
|
+
PlamoRequest *plamo_request;
|
43
|
+
TypedData_Get_Struct(self, PlamoRequest, &rb_plamo_request_type, plamo_request);
|
44
|
+
VALUE rb_plamo_response = TypedData_Wrap_Struct(rb_cPlamoResponse, &rb_plamo_response_type, plamo_app_execute(plamo_app, plamo_request));
|
44
45
|
return rb_plamo_response;
|
45
46
|
}
|
46
47
|
|
@@ -1,34 +1,48 @@
|
|
1
1
|
#include "plamo.h"
|
2
|
-
#include "wrapper.h"
|
3
2
|
|
4
3
|
VALUE rb_cPlamoByteArray;
|
5
4
|
|
6
|
-
static void deallocate(
|
7
|
-
plamo_byte_array_destroy(
|
8
|
-
free(wrapper);
|
5
|
+
static void deallocate(void *plamo_byte_array) {
|
6
|
+
plamo_byte_array_destroy(plamo_byte_array);
|
9
7
|
}
|
10
8
|
|
9
|
+
const rb_data_type_t rb_plamo_byte_array_type = {
|
10
|
+
"ByteArray",
|
11
|
+
{
|
12
|
+
NULL,
|
13
|
+
deallocate,
|
14
|
+
NULL,
|
15
|
+
},
|
16
|
+
NULL,
|
17
|
+
NULL,
|
18
|
+
0,
|
19
|
+
};
|
20
|
+
|
11
21
|
static VALUE allocate(VALUE klass) {
|
12
|
-
return
|
22
|
+
return TypedData_Wrap_Struct(klass, &rb_plamo_byte_array_type, NULL);
|
13
23
|
}
|
14
24
|
|
15
25
|
static VALUE initialize(VALUE self, VALUE body) {
|
16
|
-
|
17
|
-
Data_Get_Struct(self, Wrapper, wrapper);
|
18
|
-
wrapper->inner = plamo_byte_array_new((const unsigned char*)RARRAY_PTR(body), RARRAY_LEN(body));
|
26
|
+
DATA_PTR(self) = plamo_byte_array_new((const unsigned char*)RARRAY_PTR(body), RARRAY_LEN(body));
|
19
27
|
return self;
|
20
28
|
}
|
21
29
|
|
22
30
|
static VALUE get_body(VALUE self) {
|
23
|
-
|
24
|
-
|
25
|
-
|
31
|
+
PlamoByteArray *plamo_byte_array;
|
32
|
+
TypedData_Get_Struct(self, PlamoByteArray, &rb_plamo_byte_array_type, plamo_byte_array);
|
33
|
+
const size_t size = plamo_byte_array_get_body_size(plamo_byte_array);
|
34
|
+
const unsigned char *body = plamo_byte_array_get_body(plamo_byte_array);
|
35
|
+
VALUE rb_array = rb_ary_new2(size);
|
36
|
+
for (int i = 0; i < size; i++) {
|
37
|
+
rb_ary_store(rb_array, i, CHR2FIX(*(body + i)));
|
38
|
+
}
|
39
|
+
return rb_array;
|
26
40
|
}
|
27
41
|
|
28
42
|
static VALUE get_size(VALUE self) {
|
29
|
-
|
30
|
-
|
31
|
-
return ULONG2NUM(plamo_byte_array_get_body_size(
|
43
|
+
PlamoByteArray *plamo_byte_array;
|
44
|
+
TypedData_Get_Struct(self, PlamoByteArray, &rb_plamo_byte_array_type, plamo_byte_array);
|
45
|
+
return ULONG2NUM(plamo_byte_array_get_body_size(plamo_byte_array));
|
32
46
|
}
|
33
47
|
|
34
48
|
void Init_plamo_byte_array(void) {
|
@@ -0,0 +1,67 @@
|
|
1
|
+
#include "plamo.h"
|
2
|
+
|
3
|
+
VALUE rb_cPlamoFormData;
|
4
|
+
|
5
|
+
static void deallocate(void *plamo_form_data) {
|
6
|
+
plamo_form_data_destroy(plamo_form_data);
|
7
|
+
}
|
8
|
+
|
9
|
+
static const rb_data_type_t rb_plamo_form_data_type = {
|
10
|
+
"FormData",
|
11
|
+
{
|
12
|
+
NULL,
|
13
|
+
deallocate,
|
14
|
+
NULL,
|
15
|
+
},
|
16
|
+
NULL,
|
17
|
+
NULL,
|
18
|
+
0,
|
19
|
+
};
|
20
|
+
|
21
|
+
static VALUE allocate(VALUE klass) {
|
22
|
+
return TypedData_Wrap_Struct(klass, &rb_plamo_form_data_type, NULL);
|
23
|
+
}
|
24
|
+
|
25
|
+
static VALUE initialize(VALUE self, VALUE rb_plamo_request) {
|
26
|
+
PlamoRequest *plamo_request;
|
27
|
+
TypedData_Get_Struct(rb_plamo_request, PlamoRequest, &rb_plamo_request_type, plamo_request);
|
28
|
+
PlamoFormData *plamo_form_data = plamo_form_data_new(plamo_request);
|
29
|
+
if (plamo_form_data == NULL) {
|
30
|
+
return Qnil;
|
31
|
+
}
|
32
|
+
DATA_PTR(self) = plamo_form_data;
|
33
|
+
return self;
|
34
|
+
}
|
35
|
+
|
36
|
+
static void execute_each(const char *key, const PlamoFormDataField *value) {
|
37
|
+
VALUE rb_plamo_form_data_field = TypedData_Wrap_Struct(rb_cPlamoFormDataField, &rb_plamo_form_data_field_type, (PlamoFormDataField*)value);
|
38
|
+
OBJ_FREEZE(rb_plamo_form_data_field);
|
39
|
+
rb_yield(rb_ary_new3(2, rb_str_new2(key), rb_plamo_form_data_field));
|
40
|
+
}
|
41
|
+
|
42
|
+
static VALUE each(VALUE self) {
|
43
|
+
PlamoFormData *plamo_form_data;
|
44
|
+
TypedData_Get_Struct(self, PlamoFormData, &rb_plamo_form_data_type, plamo_form_data);
|
45
|
+
plamo_form_data_for_each(plamo_form_data, execute_each);
|
46
|
+
return Qnil;
|
47
|
+
}
|
48
|
+
|
49
|
+
static VALUE get(VALUE self, VALUE key) {
|
50
|
+
PlamoFormData *plamo_form_data;
|
51
|
+
TypedData_Get_Struct(self, PlamoFormData, &rb_plamo_form_data_type, plamo_form_data);
|
52
|
+
const PlamoFormDataFieldArray *plamo_form_data_field_array = plamo_form_data_get(plamo_form_data, StringValueCStr(key));
|
53
|
+
if (plamo_form_data_field_array == NULL) {
|
54
|
+
return Qnil;
|
55
|
+
}
|
56
|
+
VALUE rb_plamo_form_data_field_array = TypedData_Wrap_Struct(rb_cPlamoFormDataFieldArray, &rb_plamo_form_data_field_array_type, (PlamoFormDataFieldArray*)plamo_form_data_field_array);
|
57
|
+
OBJ_FREEZE(rb_plamo_form_data_field_array);
|
58
|
+
return rb_plamo_form_data_field_array;
|
59
|
+
}
|
60
|
+
|
61
|
+
void Init_plamo_form_data(void) {
|
62
|
+
rb_cPlamoFormData = rb_define_class_under(rb_mPlamo, "FormData", rb_cObject);
|
63
|
+
rb_define_alloc_func(rb_cPlamoFormData, allocate);
|
64
|
+
rb_define_method(rb_cPlamoFormData, "initialize", initialize, 1);
|
65
|
+
rb_define_method(rb_cPlamoFormData, "[]", get, 1);
|
66
|
+
rb_define_method(rb_cPlamoFormData, "each", each, 0);
|
67
|
+
}
|
@@ -0,0 +1,70 @@
|
|
1
|
+
#include "plamo.h"
|
2
|
+
|
3
|
+
VALUE rb_cPlamoFormDataField;
|
4
|
+
|
5
|
+
const rb_data_type_t rb_plamo_form_data_field_type = {
|
6
|
+
"FormDataField",
|
7
|
+
{
|
8
|
+
NULL,
|
9
|
+
NULL,
|
10
|
+
NULL,
|
11
|
+
},
|
12
|
+
NULL,
|
13
|
+
NULL,
|
14
|
+
0,
|
15
|
+
};
|
16
|
+
|
17
|
+
static VALUE allocate(VALUE klass) {
|
18
|
+
return TypedData_Wrap_Struct(klass, &rb_plamo_form_data_field_type, NULL);
|
19
|
+
}
|
20
|
+
|
21
|
+
static VALUE get_text(VALUE self) {
|
22
|
+
PlamoFormDataField *plamo_form_data_field;
|
23
|
+
TypedData_Get_Struct(self, PlamoFormDataField, &rb_plamo_form_data_field_type, plamo_form_data_field);
|
24
|
+
if (plamo_form_data_field->text) {
|
25
|
+
return rb_str_new2(plamo_string_get_char(plamo_form_data_field->text));
|
26
|
+
} else {
|
27
|
+
return Qnil;
|
28
|
+
}
|
29
|
+
}
|
30
|
+
|
31
|
+
static VALUE get_file(VALUE self) {
|
32
|
+
PlamoFormDataField *plamo_form_data_field;
|
33
|
+
TypedData_Get_Struct(self, PlamoFormDataField, &rb_plamo_form_data_field_type, plamo_form_data_field);
|
34
|
+
if (plamo_form_data_field->file) {
|
35
|
+
VALUE rb_plamo_form_data_file = TypedData_Wrap_Struct(rb_cPlamoFormDataFile, &rb_plamo_form_data_file_type, plamo_form_data_field->file);
|
36
|
+
OBJ_FREEZE(rb_plamo_form_data_file);
|
37
|
+
return rb_plamo_form_data_file;
|
38
|
+
} else {
|
39
|
+
return Qnil;
|
40
|
+
}
|
41
|
+
}
|
42
|
+
|
43
|
+
static VALUE is_text(VALUE self) {
|
44
|
+
PlamoFormDataField *plamo_form_data_field;
|
45
|
+
TypedData_Get_Struct(self, PlamoFormDataField, &rb_plamo_form_data_field_type, plamo_form_data_field);
|
46
|
+
if (plamo_form_data_field->text) {
|
47
|
+
return Qtrue;
|
48
|
+
} else {
|
49
|
+
return Qfalse;
|
50
|
+
}
|
51
|
+
}
|
52
|
+
|
53
|
+
static VALUE is_file(VALUE self) {
|
54
|
+
PlamoFormDataField *plamo_form_data_field;
|
55
|
+
TypedData_Get_Struct(self, PlamoFormDataField, &rb_plamo_form_data_field_type, plamo_form_data_field);
|
56
|
+
if (plamo_form_data_field->file) {
|
57
|
+
return Qtrue;
|
58
|
+
} else {
|
59
|
+
return Qfalse;
|
60
|
+
}
|
61
|
+
}
|
62
|
+
|
63
|
+
void Init_plamo_form_data_field(void) {
|
64
|
+
rb_cPlamoFormDataField = rb_define_class_under(rb_mPlamo, "FormDataField", rb_cObject);
|
65
|
+
rb_define_alloc_func(rb_cPlamoFormDataField, allocate);
|
66
|
+
rb_define_method(rb_cPlamoFormDataField, "text", get_text, 0);
|
67
|
+
rb_define_method(rb_cPlamoFormDataField, "file", get_file, 0);
|
68
|
+
rb_define_method(rb_cPlamoFormDataField, "text?", is_text, 0);
|
69
|
+
rb_define_method(rb_cPlamoFormDataField, "file?", is_file, 0);
|
70
|
+
}
|
@@ -0,0 +1,9 @@
|
|
1
|
+
#ifndef RUBY_PLAMO_FORM_DATA_FIELD_H
|
2
|
+
#define RUBY_PLAMO_FORM_DATA_FIELD_H
|
3
|
+
|
4
|
+
extern VALUE rb_cPlamoFormDataField;
|
5
|
+
extern const rb_data_type_t rb_plamo_form_data_field_type;
|
6
|
+
|
7
|
+
void Init_plamo_form_data_field(void);
|
8
|
+
|
9
|
+
#endif /* RUBY_PLAMO_FORM_DATA_FIELD_H */
|
@@ -0,0 +1,88 @@
|
|
1
|
+
#include "plamo.h"
|
2
|
+
|
3
|
+
VALUE rb_cPlamoFormDataFieldArray;
|
4
|
+
|
5
|
+
const rb_data_type_t rb_plamo_form_data_field_array_type = {
|
6
|
+
"FormDataFieldArray",
|
7
|
+
{
|
8
|
+
NULL,
|
9
|
+
NULL,
|
10
|
+
NULL,
|
11
|
+
},
|
12
|
+
NULL,
|
13
|
+
NULL,
|
14
|
+
0,
|
15
|
+
};
|
16
|
+
|
17
|
+
static VALUE allocate(VALUE klass) {
|
18
|
+
return TypedData_Wrap_Struct(klass, &rb_plamo_form_data_field_array_type, NULL);
|
19
|
+
}
|
20
|
+
|
21
|
+
static VALUE length(VALUE self) {
|
22
|
+
PlamoFormDataFieldArray *plamo_form_data_field_array;
|
23
|
+
TypedData_Get_Struct(self, PlamoFormDataFieldArray, &rb_plamo_form_data_field_array_type, plamo_form_data_field_array);
|
24
|
+
return SIZET2NUM(plamo_form_data_field_array_length(plamo_form_data_field_array));
|
25
|
+
}
|
26
|
+
|
27
|
+
static void execute_each(const PlamoFormDataField *value) {
|
28
|
+
VALUE rb_plamo_form_data_field = TypedData_Wrap_Struct(rb_cPlamoFormDataField, &rb_plamo_form_data_field_type, (PlamoFormDataField*)value);
|
29
|
+
OBJ_FREEZE(rb_plamo_form_data_field);
|
30
|
+
rb_yield(rb_plamo_form_data_field);
|
31
|
+
}
|
32
|
+
|
33
|
+
static VALUE each(VALUE self) {
|
34
|
+
PlamoFormDataFieldArray *plamo_form_data_field_array;
|
35
|
+
TypedData_Get_Struct(self, PlamoFormDataFieldArray, &rb_plamo_form_data_field_array_type, plamo_form_data_field_array);
|
36
|
+
plamo_form_data_field_array_for_each(plamo_form_data_field_array, execute_each);
|
37
|
+
return Qnil;
|
38
|
+
}
|
39
|
+
|
40
|
+
static VALUE get_at(VALUE self, VALUE index) {
|
41
|
+
PlamoFormDataFieldArray *plamo_form_data_field_array;
|
42
|
+
TypedData_Get_Struct(self, PlamoFormDataFieldArray, &rb_plamo_form_data_field_array_type, plamo_form_data_field_array);
|
43
|
+
const PlamoFormDataField *plamo_form_data_field = plamo_form_data_field_array_get_at(plamo_form_data_field_array, NUM2SIZET(index));
|
44
|
+
if (plamo_form_data_field) {
|
45
|
+
VALUE rb_plamo_form_data_field = TypedData_Wrap_Struct(rb_cPlamoFormDataField, &rb_plamo_form_data_field_type, (PlamoFormDataField*)plamo_form_data_field);
|
46
|
+
OBJ_FREEZE(rb_plamo_form_data_field);
|
47
|
+
return rb_plamo_form_data_field;
|
48
|
+
} else {
|
49
|
+
return Qnil;
|
50
|
+
}
|
51
|
+
}
|
52
|
+
|
53
|
+
static VALUE get_first(VALUE self) {
|
54
|
+
PlamoFormDataFieldArray *plamo_form_data_field_array;
|
55
|
+
TypedData_Get_Struct(self, PlamoFormDataFieldArray, &rb_plamo_form_data_field_array_type, plamo_form_data_field_array);
|
56
|
+
const PlamoFormDataField *plamo_form_data_field = plamo_form_data_field_array_get_first(plamo_form_data_field_array);
|
57
|
+
if (plamo_form_data_field) {
|
58
|
+
VALUE rb_plamo_form_data_field = TypedData_Wrap_Struct(rb_cPlamoFormDataField, &rb_plamo_form_data_field_type, (PlamoFormDataField*)plamo_form_data_field);
|
59
|
+
OBJ_FREEZE(rb_plamo_form_data_field);
|
60
|
+
return rb_plamo_form_data_field;
|
61
|
+
} else {
|
62
|
+
return Qnil;
|
63
|
+
}
|
64
|
+
}
|
65
|
+
|
66
|
+
static VALUE get_last(VALUE self) {
|
67
|
+
PlamoFormDataFieldArray *plamo_form_data_field_array;
|
68
|
+
TypedData_Get_Struct(self, PlamoFormDataFieldArray, &rb_plamo_form_data_field_array_type, plamo_form_data_field_array);
|
69
|
+
const PlamoFormDataField *plamo_form_data_field = plamo_form_data_field_array_get_last(plamo_form_data_field_array);
|
70
|
+
if (plamo_form_data_field) {
|
71
|
+
VALUE rb_plamo_form_data_field = TypedData_Wrap_Struct(rb_cPlamoFormDataField, &rb_plamo_form_data_field_type, (PlamoFormDataField*)plamo_form_data_field);
|
72
|
+
OBJ_FREEZE(rb_plamo_form_data_field);
|
73
|
+
return rb_plamo_form_data_field;
|
74
|
+
} else {
|
75
|
+
return Qnil;
|
76
|
+
}
|
77
|
+
}
|
78
|
+
|
79
|
+
void Init_plamo_form_data_field_array(void) {
|
80
|
+
rb_cPlamoFormDataFieldArray = rb_define_class_under(rb_mPlamo, "FormDataFieldArray", rb_cObject);
|
81
|
+
rb_define_alloc_func(rb_cPlamoFormDataFieldArray, allocate);
|
82
|
+
rb_define_method(rb_cPlamoFormDataFieldArray, "length", length, 0);
|
83
|
+
rb_define_alias(rb_cPlamoFormDataFieldArray, "size", "length");
|
84
|
+
rb_define_method(rb_cPlamoFormDataFieldArray, "each", each, 0);
|
85
|
+
rb_define_method(rb_cPlamoFormDataFieldArray, "[]", get_at, 1);
|
86
|
+
rb_define_method(rb_cPlamoFormDataFieldArray, "first", get_first, 0);
|
87
|
+
rb_define_method(rb_cPlamoFormDataFieldArray, "last", get_last, 0);
|
88
|
+
}
|