gesttalt 0.1.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 ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA256:
3
+ metadata.gz: 86e53cb985ce258a742d39a732ab0d1fd9d410fba82a799b1e1eb00a0eccaab8
4
+ data.tar.gz: 0ef0a9cee9a733d679dca6382f46e974599efe952eeeb7992a6530bb154d800e
5
+ SHA512:
6
+ metadata.gz: 946c605226dbf5d9e8b0fedd76ba7855980b73a4172f46e9604915a2847dca6ec3ef424c39dd28c668a4cdadd08fcf36cb15f45af502405eacb48bd5c42f6402
7
+ data.tar.gz: 37b5c276882ffa8158df26fd674857f1357ede8bc46e85c2e374770de2e8544e388c124439396b5453a1c4193de4dbfc1c3dd0d087d55c7463db9f55ea63874a
data/LICENSE ADDED
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2025 Pedro Piñera Buendía
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
data/README.md ADDED
@@ -0,0 +1,44 @@
1
+ # Gesttalt Ruby Bindings
2
+
3
+ Snippets CRUD bindings for Gesttalt, powered by Zig.
4
+
5
+ ## Install
6
+
7
+ ```bash
8
+ gem install gesttalt
9
+ ```
10
+
11
+ ## Usage
12
+
13
+ ```ruby
14
+ require "gesttalt"
15
+
16
+ project_dir = "."
17
+ timestamp = 1735148400
18
+
19
+ path = Gesttalt::Snippets.create(project_dir, timestamp, "Example snippet", "const x = 1;", "example.zig")
20
+ puts path
21
+
22
+ snippet = Gesttalt::Snippets.read(project_dir, timestamp)
23
+ puts snippet["description"]
24
+
25
+ Gesttalt::Snippets.update(project_dir, timestamp, "Updated", nil, nil)
26
+
27
+ Gesttalt::Snippets.delete(project_dir, timestamp)
28
+ ```
29
+
30
+ ## Development
31
+
32
+ ```bash
33
+ # From project root
34
+ zig build -Doptimize=ReleaseFast
35
+
36
+ cd bindings/ruby
37
+ bundle install
38
+ bundle exec rake compile
39
+ bundle exec ruby -I lib -e 'require "gesttalt"; puts Gesttalt::Snippets.create(".", 1735148400, "Example", "const x = 1;", "example.zig")'
40
+ ```
41
+
42
+ ## License
43
+
44
+ MIT
@@ -0,0 +1,8 @@
1
+ require "mkmf"
2
+
3
+ project_root = File.expand_path("../../../..", __dir__)
4
+ lib_dir = File.join(project_root, "zig-out", "lib")
5
+
6
+ $LDFLAGS << " #{File.join(lib_dir, 'libgesttalt_ffi.a')}"
7
+
8
+ create_makefile("gesttalt_ext/gesttalt_ext")
@@ -0,0 +1,131 @@
1
+ #include "ruby.h"
2
+ #include <stdint.h>
3
+ #include <string.h>
4
+
5
+ int gesttalt_snippet_create(const char *project_dir, int64_t timestamp,
6
+ const char *description, const char *body,
7
+ const char *filename, char **out_path);
8
+ int gesttalt_snippet_read(const char *project_dir, int64_t timestamp,
9
+ char **out_json);
10
+ int gesttalt_snippet_update(const char *project_dir, int64_t timestamp,
11
+ const char *description, const char *body,
12
+ const char *filename);
13
+ int gesttalt_snippet_delete(const char *project_dir, int64_t timestamp);
14
+ void gesttalt_free(char *ptr);
15
+
16
+ static const char *error_message(int code) {
17
+ switch (code) {
18
+ case 1: return "Invalid timestamp";
19
+ case 2: return "Duplicate snippet";
20
+ case 3: return "Snippet not found";
21
+ case 4: return "Invalid extension";
22
+ case 5: return "Invalid description";
23
+ case 6: return "Invalid filename";
24
+ case 7: return "Parse error";
25
+ case 8: return "I/O error";
26
+ case 9: return "Out of memory";
27
+ default: return "Unknown error";
28
+ }
29
+ }
30
+
31
+ static void raise_error(int code) {
32
+ VALUE error = rb_exc_new_cstr(rb_eRuntimeError, error_message(code));
33
+ rb_iv_set(error, "@code", INT2NUM(code));
34
+ rb_exc_raise(error);
35
+ }
36
+
37
+ static VALUE rb_gesttalt_create(VALUE self, VALUE project_val, VALUE timestamp_val,
38
+ VALUE description_val, VALUE body_val, VALUE filename_val) {
39
+ VALUE project_str = StringValue(project_val);
40
+ VALUE description_str = StringValue(description_val);
41
+ VALUE body_str = StringValue(body_val);
42
+ VALUE filename_str = StringValue(filename_val);
43
+
44
+ int64_t timestamp = NUM2LL(timestamp_val);
45
+
46
+ char *out_path = NULL;
47
+ int rc = gesttalt_snippet_create(
48
+ RSTRING_PTR(project_str),
49
+ timestamp,
50
+ RSTRING_PTR(description_str),
51
+ RSTRING_PTR(body_str),
52
+ RSTRING_PTR(filename_str),
53
+ &out_path
54
+ );
55
+
56
+ if (rc != 0) {
57
+ raise_error(rc);
58
+ }
59
+
60
+ VALUE result = rb_str_new_cstr(out_path ? out_path : "");
61
+ if (out_path) {
62
+ gesttalt_free(out_path);
63
+ }
64
+ return result;
65
+ }
66
+
67
+ static VALUE rb_gesttalt_read(VALUE self, VALUE project_val, VALUE timestamp_val) {
68
+ VALUE project_str = StringValue(project_val);
69
+ int64_t timestamp = NUM2LL(timestamp_val);
70
+
71
+ char *out_json = NULL;
72
+ int rc = gesttalt_snippet_read(RSTRING_PTR(project_str), timestamp, &out_json);
73
+ if (rc != 0) {
74
+ raise_error(rc);
75
+ }
76
+
77
+ VALUE json_str = rb_str_new_cstr(out_json ? out_json : "{}");
78
+ if (out_json) {
79
+ gesttalt_free(out_json);
80
+ }
81
+
82
+ VALUE json_module = rb_const_get(rb_cObject, rb_intern("JSON"));
83
+ return rb_funcall(json_module, rb_intern("parse"), 1, json_str);
84
+ }
85
+
86
+ static VALUE rb_gesttalt_update(VALUE self, VALUE project_val, VALUE timestamp_val,
87
+ VALUE description_val, VALUE body_val, VALUE filename_val) {
88
+ VALUE project_str = StringValue(project_val);
89
+ int64_t timestamp = NUM2LL(timestamp_val);
90
+
91
+ const char *description = NIL_P(description_val) ? NULL : RSTRING_PTR(StringValue(description_val));
92
+ const char *body = NIL_P(body_val) ? NULL : RSTRING_PTR(StringValue(body_val));
93
+ const char *filename = NIL_P(filename_val) ? NULL : RSTRING_PTR(StringValue(filename_val));
94
+
95
+ int rc = gesttalt_snippet_update(
96
+ RSTRING_PTR(project_str),
97
+ timestamp,
98
+ description,
99
+ body,
100
+ filename
101
+ );
102
+
103
+ if (rc != 0) {
104
+ raise_error(rc);
105
+ }
106
+
107
+ return Qtrue;
108
+ }
109
+
110
+ static VALUE rb_gesttalt_delete(VALUE self, VALUE project_val, VALUE timestamp_val) {
111
+ VALUE project_str = StringValue(project_val);
112
+ int64_t timestamp = NUM2LL(timestamp_val);
113
+
114
+ int rc = gesttalt_snippet_delete(RSTRING_PTR(project_str), timestamp);
115
+ if (rc != 0) {
116
+ raise_error(rc);
117
+ }
118
+
119
+ return Qtrue;
120
+ }
121
+
122
+ void Init_gesttalt_ext(void) {
123
+ rb_require("json");
124
+ VALUE mGesttalt = rb_define_module("Gesttalt");
125
+ VALUE mSnippets = rb_define_module_under(mGesttalt, "Snippets");
126
+
127
+ rb_define_singleton_method(mSnippets, "create", rb_gesttalt_create, 5);
128
+ rb_define_singleton_method(mSnippets, "read", rb_gesttalt_read, 2);
129
+ rb_define_singleton_method(mSnippets, "update", rb_gesttalt_update, 5);
130
+ rb_define_singleton_method(mSnippets, "delete", rb_gesttalt_delete, 2);
131
+ }
data/lib/gesttalt.rb ADDED
@@ -0,0 +1,7 @@
1
+ # Gesttalt - Snippets CRUD bindings powered by Zig
2
+ #
3
+ # @example Basic usage
4
+ # require 'gesttalt'
5
+ # Gesttalt::Snippets.create(".", 1735148400, "Example snippet", "const x = 1;", "example.zig")
6
+ #
7
+ require "gesttalt_ext"
@@ -0,0 +1,2 @@
1
+ require "json"
2
+ require "gesttalt_ext/gesttalt_ext"
metadata ADDED
@@ -0,0 +1,64 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: gesttalt
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.0
5
+ platform: ruby
6
+ authors:
7
+ - Pedro Pinera Buendia
8
+ bindir: bin
9
+ cert_chain: []
10
+ date: 1980-01-02 00:00:00.000000000 Z
11
+ dependencies:
12
+ - !ruby/object:Gem::Dependency
13
+ name: json
14
+ requirement: !ruby/object:Gem::Requirement
15
+ requirements:
16
+ - - ">="
17
+ - !ruby/object:Gem::Version
18
+ version: '0'
19
+ type: :runtime
20
+ prerelease: false
21
+ version_requirements: !ruby/object:Gem::Requirement
22
+ requirements:
23
+ - - ">="
24
+ - !ruby/object:Gem::Version
25
+ version: '0'
26
+ description: Bindings for Gesttalt snippets CRUD, compiled from Zig to native code.
27
+ email:
28
+ - pedro@ppinera.es
29
+ executables: []
30
+ extensions:
31
+ - ext/gesttalt_ext/extconf.rb
32
+ extra_rdoc_files: []
33
+ files:
34
+ - LICENSE
35
+ - README.md
36
+ - ext/gesttalt_ext/extconf.rb
37
+ - ext/gesttalt_ext/gesttalt_ext.c
38
+ - lib/gesttalt.rb
39
+ - lib/gesttalt_ext.rb
40
+ homepage: https://github.com/pepicrft/gesttalt
41
+ licenses:
42
+ - MIT
43
+ metadata:
44
+ homepage_uri: https://github.com/pepicrft/gesttalt
45
+ source_code_uri: https://github.com/pepicrft/gesttalt
46
+ changelog_uri: https://github.com/pepicrft/gesttalt/blob/main/CHANGELOG.md
47
+ rdoc_options: []
48
+ require_paths:
49
+ - lib
50
+ required_ruby_version: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - ">="
53
+ - !ruby/object:Gem::Version
54
+ version: 2.7.0
55
+ required_rubygems_version: !ruby/object:Gem::Requirement
56
+ requirements:
57
+ - - ">="
58
+ - !ruby/object:Gem::Version
59
+ version: '0'
60
+ requirements: []
61
+ rubygems_version: 3.6.9
62
+ specification_version: 4
63
+ summary: Gesttalt snippets CRUD bindings powered by Zig
64
+ test_files: []