encoded_id 1.0.0.rc5 → 1.0.0.rc7

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.
Files changed (38) hide show
  1. checksums.yaml +4 -4
  2. data/CHANGELOG.md +99 -3
  3. data/README.md +86 -329
  4. data/context/encoded_id.md +437 -0
  5. data/lib/encoded_id/alphabet.rb +34 -3
  6. data/lib/encoded_id/blocklist.rb +100 -0
  7. data/lib/encoded_id/encoders/base_configuration.rb +154 -0
  8. data/lib/encoded_id/encoders/hashid.rb +527 -0
  9. data/lib/encoded_id/encoders/hashid_configuration.rb +40 -0
  10. data/lib/encoded_id/encoders/hashid_consistent_shuffle.rb +110 -0
  11. data/lib/encoded_id/encoders/hashid_ordinal_alphabet_separator_guards.rb +244 -0
  12. data/lib/encoded_id/encoders/hashid_salt.rb +51 -0
  13. data/lib/encoded_id/encoders/my_sqids.rb +454 -0
  14. data/lib/encoded_id/encoders/sqids.rb +59 -0
  15. data/lib/encoded_id/encoders/sqids_configuration.rb +22 -0
  16. data/lib/encoded_id/encoders/sqids_with_blocklist_mode.rb +54 -0
  17. data/lib/encoded_id/hex_representation.rb +29 -14
  18. data/lib/encoded_id/reversible_id.rb +115 -82
  19. data/lib/encoded_id/version.rb +3 -1
  20. data/lib/encoded_id.rb +34 -4
  21. metadata +34 -26
  22. data/.devcontainer/Dockerfile +0 -9
  23. data/.devcontainer/compose.yml +0 -8
  24. data/.devcontainer/devcontainer.json +0 -8
  25. data/.standard.yml +0 -2
  26. data/Gemfile +0 -36
  27. data/Rakefile +0 -20
  28. data/Steepfile +0 -5
  29. data/ext/encoded_id/extconf.rb +0 -3
  30. data/ext/encoded_id/extension.c +0 -123
  31. data/ext/encoded_id/hashids.c +0 -939
  32. data/ext/encoded_id/hashids.h +0 -139
  33. data/lib/encoded_id/hash_id.rb +0 -227
  34. data/lib/encoded_id/hash_id_consistent_shuffle.rb +0 -27
  35. data/lib/encoded_id/hash_id_salt.rb +0 -15
  36. data/lib/encoded_id/ordinal_alphabet_separator_guards.rb +0 -90
  37. data/rbs_collection.yaml +0 -24
  38. data/sig/encoded_id.rbs +0 -189
@@ -1,123 +0,0 @@
1
- #include "ruby/ruby.h"
2
- #include "hashids.h"
3
-
4
- void wrapped_hashids_free(void* data)
5
- {
6
- hashids_free(data);
7
- }
8
-
9
- size_t wrapped_hashids_size(const void* data)
10
- {
11
- return sizeof(hashids_t);
12
- }
13
-
14
- static const rb_data_type_t wrapped_hashids_type = {
15
- .wrap_struct_name = "hashids_t",
16
- .function = {
17
- .dmark = NULL,
18
- .dfree = wrapped_hashids_free,
19
- .dsize = wrapped_hashids_size,
20
- },
21
- .data = NULL,
22
- .flags = RUBY_TYPED_FREE_IMMEDIATELY,
23
- };
24
-
25
- VALUE hashids_alloc(VALUE self)
26
- {
27
- hashids_t *data = hashids_init("salt!");
28
- return TypedData_Wrap_Struct(self, &wrapped_hashids_type, data);
29
- }
30
-
31
- //VALUE rb_hashids_m_initialize(VALUE self, VALUE val)
32
- //{
33
- // return self;
34
- //}
35
-
36
-
37
- static VALUE rb_hash_id_c_encode(VALUE self, VALUE ids) {
38
- Check_Type(ids, T_ARRAY);
39
-
40
- long length = RARRAY_LEN(ids);
41
-
42
- unsigned long long* inputs = ALLOC_N(unsigned long long, length);
43
-
44
- for (long i = 0; i < length; i++) {
45
- VALUE rb_element = rb_ary_entry(ids, i);
46
- Check_Type(rb_element, T_FIXNUM);
47
- inputs[i] = NUM2ULL(rb_element);
48
- }
49
-
50
- hashids_t* hashids;
51
-
52
- TypedData_Get_Struct(self, hashids_t, &wrapped_hashids_type, hashids);
53
-
54
- size_t bytes_encoded;
55
-
56
- size_t bytes_needed;
57
- bytes_needed = hashids_estimate_encoded_size(hashids, sizeof(&inputs) / sizeof(unsigned long long), &inputs);
58
- char *hash = ALLOC_N(char, bytes_needed);
59
-
60
- // unsigned long long numbers[] = {1ull, 2ull, 3ull, 4ull, 5ull};
61
-
62
- // printf("length: %ld\n", length);
63
- // printf("inputs[0]: %llu\n", inputs[0]);
64
- // printf("inputs[1]: %llu\n", inputs[1]);
65
- // printf("inputs[2]: %llu\n", inputs[2]);
66
- // printf("inputs[3]: %llu\n", inputs[3]);
67
- // printf("inputs[4]: %llu\n", inputs[4]);
68
- //
69
- // printf("hashids: %p\n", hashids);
70
- // printf("hashids->alphabet: %s\n", hashids->alphabet);
71
- // printf("hashids->salt: %s\n", hashids->salt);
72
- // printf("hashids->min_hash_length: %lu\n", hashids->min_hash_length);
73
- // printf("numbers: %p\n", numbers);
74
- // printf("numbers[0]: %llu\n", numbers[0]);
75
- // printf("numbers[1]: %llu\n", numbers[1]);
76
- // printf("numbers[2]: %llu\n", numbers[2]);
77
- // printf("numbers[3]: %llu\n", numbers[3]);
78
- // printf("numbers[4]: %llu\n", numbers[4]);
79
- //
80
- // printf("sizeof(*inputs) / sizeof(unsigned long long): %lu\n", sizeof(*inputs) / sizeof(unsigned long long));
81
- // printf("sizeof(numbers) / sizeof(unsigned long long): %lu\n", sizeof(numbers) / sizeof(unsigned long long));
82
- // bytes_encoded = hashids_encode(hashids, hash, sizeof(numbers) / sizeof(unsigned long long), numbers);
83
- bytes_encoded = hashids_encode(hashids, hash, length, inputs);
84
-
85
- ruby_xfree(inputs);
86
- VALUE return_value = rb_str_new2(hash);
87
- ruby_xfree(hash);
88
- return return_value;
89
- }
90
-
91
- static VALUE rb_hash_id_c_decode(VALUE self, VALUE str) {
92
- Check_Type(str, T_STRING);
93
-
94
- hashids_t* hashids;
95
-
96
- TypedData_Get_Struct(self, hashids_t, &wrapped_hashids_type, hashids);
97
-
98
- size_t numbers_count = hashids_numbers_count(hashids, RSTRING_PTR(str));
99
-
100
- unsigned long long* numbers = ALLOC_N(unsigned long long, numbers_count);
101
-
102
- hashids_decode_safe(hashids, RSTRING_PTR(str), numbers, numbers_count);
103
-
104
- VALUE rb_numbers = rb_ary_new_capa(numbers_count);
105
-
106
- for (size_t i = 0; i < numbers_count; i++) {
107
- rb_ary_push(rb_numbers, ULL2NUM(numbers[i]));
108
- }
109
-
110
- ruby_xfree(numbers);
111
- return rb_numbers;
112
- }
113
-
114
- void Init_extension(void) {
115
- VALUE EncodedId = rb_define_module("EncodedId");
116
- VALUE HashIdC = rb_define_class_under(EncodedId, "HashIdC", rb_cObject);
117
-
118
- rb_define_alloc_func(HashIdC, hashids_alloc);
119
- // rb_define_method(HashIdC, "initialize", rb_hashids_m_initialize, 1);
120
-
121
- rb_define_method(HashIdC, "encode", rb_hash_id_c_encode, 1);
122
- rb_define_method(HashIdC, "decode", rb_hash_id_c_decode, 1);
123
- }