autocompl 0.2.1 → 0.2.2

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 (131) hide show
  1. checksums.yaml +4 -4
  2. data/lib/autocompl/repository.rb +11 -1
  3. data/lib/autocompl/version.rb +1 -1
  4. data/test/dummy/log/development.log +467 -0
  5. data/test/dummy/log/test.log +3 -0
  6. data/test/dummy/vendor/bundle/ruby/2.3.0/bin/console +23 -0
  7. data/test/dummy/vendor/bundle/ruby/2.3.0/cache/pg-0.19.0.gem +0 -0
  8. data/test/dummy/vendor/bundle/ruby/2.3.0/cache/pq-0.0.1.gem +0 -0
  9. data/test/dummy/vendor/bundle/ruby/2.3.0/extensions/x86_64-darwin-15/2.3.0-static/pg-0.19.0/gem.build_complete +0 -0
  10. data/test/dummy/vendor/bundle/ruby/2.3.0/extensions/x86_64-darwin-15/2.3.0-static/pg-0.19.0/gem_make.out +78 -0
  11. data/test/dummy/vendor/bundle/ruby/2.3.0/extensions/x86_64-darwin-15/2.3.0-static/pg-0.19.0/mkmf.log +1346 -0
  12. data/test/dummy/vendor/bundle/ruby/2.3.0/extensions/x86_64-darwin-15/2.3.0-static/pg-0.19.0/pg_ext.bundle +0 -0
  13. data/test/dummy/vendor/bundle/ruby/2.3.0/gems/pg-0.19.0/BSDL +22 -0
  14. data/test/dummy/vendor/bundle/ruby/2.3.0/gems/pg-0.19.0/ChangeLog +6378 -0
  15. data/test/dummy/vendor/bundle/ruby/2.3.0/gems/pg-0.19.0/Contributors.rdoc +46 -0
  16. data/test/dummy/vendor/bundle/ruby/2.3.0/gems/pg-0.19.0/History.rdoc +363 -0
  17. data/test/dummy/vendor/bundle/ruby/2.3.0/gems/pg-0.19.0/LICENSE +56 -0
  18. data/test/dummy/vendor/bundle/ruby/2.3.0/gems/pg-0.19.0/Manifest.txt +85 -0
  19. data/test/dummy/vendor/bundle/ruby/2.3.0/gems/pg-0.19.0/POSTGRES +23 -0
  20. data/test/dummy/vendor/bundle/ruby/2.3.0/gems/pg-0.19.0/README-OS_X.rdoc +68 -0
  21. data/test/dummy/vendor/bundle/ruby/2.3.0/gems/pg-0.19.0/README-Windows.rdoc +56 -0
  22. data/test/dummy/vendor/bundle/ruby/2.3.0/gems/pg-0.19.0/README.ja.rdoc +14 -0
  23. data/test/dummy/vendor/bundle/ruby/2.3.0/gems/pg-0.19.0/README.rdoc +168 -0
  24. data/test/dummy/vendor/bundle/ruby/2.3.0/gems/pg-0.19.0/Rakefile +216 -0
  25. data/test/dummy/vendor/bundle/ruby/2.3.0/gems/pg-0.19.0/Rakefile.cross +301 -0
  26. data/test/dummy/vendor/bundle/ruby/2.3.0/gems/pg-0.19.0/ext/Makefile +261 -0
  27. data/test/dummy/vendor/bundle/ruby/2.3.0/gems/pg-0.19.0/ext/errorcodes.def +947 -0
  28. data/test/dummy/vendor/bundle/ruby/2.3.0/gems/pg-0.19.0/ext/errorcodes.rb +45 -0
  29. data/test/dummy/vendor/bundle/ruby/2.3.0/gems/pg-0.19.0/ext/errorcodes.txt +467 -0
  30. data/test/dummy/vendor/bundle/ruby/2.3.0/gems/pg-0.19.0/ext/extconf.h +38 -0
  31. data/test/dummy/vendor/bundle/ruby/2.3.0/gems/pg-0.19.0/ext/extconf.rb +112 -0
  32. data/test/dummy/vendor/bundle/ruby/2.3.0/gems/pg-0.19.0/ext/gvl_wrappers.c +13 -0
  33. data/test/dummy/vendor/bundle/ruby/2.3.0/gems/pg-0.19.0/ext/gvl_wrappers.h +257 -0
  34. data/test/dummy/vendor/bundle/ruby/2.3.0/gems/pg-0.19.0/ext/gvl_wrappers.o +0 -0
  35. data/test/dummy/vendor/bundle/ruby/2.3.0/gems/pg-0.19.0/ext/pg.c +667 -0
  36. data/test/dummy/vendor/bundle/ruby/2.3.0/gems/pg-0.19.0/ext/pg.h +395 -0
  37. data/test/dummy/vendor/bundle/ruby/2.3.0/gems/pg-0.19.0/ext/pg.o +0 -0
  38. data/test/dummy/vendor/bundle/ruby/2.3.0/gems/pg-0.19.0/ext/pg_binary_decoder.c +162 -0
  39. data/test/dummy/vendor/bundle/ruby/2.3.0/gems/pg-0.19.0/ext/pg_binary_decoder.o +0 -0
  40. data/test/dummy/vendor/bundle/ruby/2.3.0/gems/pg-0.19.0/ext/pg_binary_encoder.c +162 -0
  41. data/test/dummy/vendor/bundle/ruby/2.3.0/gems/pg-0.19.0/ext/pg_binary_encoder.o +0 -0
  42. data/test/dummy/vendor/bundle/ruby/2.3.0/gems/pg-0.19.0/ext/pg_coder.c +500 -0
  43. data/test/dummy/vendor/bundle/ruby/2.3.0/gems/pg-0.19.0/ext/pg_coder.o +0 -0
  44. data/test/dummy/vendor/bundle/ruby/2.3.0/gems/pg-0.19.0/ext/pg_connection.c +4102 -0
  45. data/test/dummy/vendor/bundle/ruby/2.3.0/gems/pg-0.19.0/ext/pg_connection.o +0 -0
  46. data/test/dummy/vendor/bundle/ruby/2.3.0/gems/pg-0.19.0/ext/pg_copy_coder.c +591 -0
  47. data/test/dummy/vendor/bundle/ruby/2.3.0/gems/pg-0.19.0/ext/pg_copy_coder.o +0 -0
  48. data/test/dummy/vendor/bundle/ruby/2.3.0/gems/pg-0.19.0/ext/pg_errors.c +95 -0
  49. data/test/dummy/vendor/bundle/ruby/2.3.0/gems/pg-0.19.0/ext/pg_errors.o +0 -0
  50. data/test/dummy/vendor/bundle/ruby/2.3.0/gems/pg-0.19.0/ext/pg_ext.bundle +0 -0
  51. data/test/dummy/vendor/bundle/ruby/2.3.0/gems/pg-0.19.0/ext/pg_result.c +1271 -0
  52. data/test/dummy/vendor/bundle/ruby/2.3.0/gems/pg-0.19.0/ext/pg_result.o +0 -0
  53. data/test/dummy/vendor/bundle/ruby/2.3.0/gems/pg-0.19.0/ext/pg_text_decoder.c +421 -0
  54. data/test/dummy/vendor/bundle/ruby/2.3.0/gems/pg-0.19.0/ext/pg_text_decoder.o +0 -0
  55. data/test/dummy/vendor/bundle/ruby/2.3.0/gems/pg-0.19.0/ext/pg_text_encoder.c +683 -0
  56. data/test/dummy/vendor/bundle/ruby/2.3.0/gems/pg-0.19.0/ext/pg_text_encoder.o +0 -0
  57. data/test/dummy/vendor/bundle/ruby/2.3.0/gems/pg-0.19.0/ext/pg_type_map.c +159 -0
  58. data/test/dummy/vendor/bundle/ruby/2.3.0/gems/pg-0.19.0/ext/pg_type_map.o +0 -0
  59. data/test/dummy/vendor/bundle/ruby/2.3.0/gems/pg-0.19.0/ext/pg_type_map_all_strings.c +116 -0
  60. data/test/dummy/vendor/bundle/ruby/2.3.0/gems/pg-0.19.0/ext/pg_type_map_all_strings.o +0 -0
  61. data/test/dummy/vendor/bundle/ruby/2.3.0/gems/pg-0.19.0/ext/pg_type_map_by_class.c +239 -0
  62. data/test/dummy/vendor/bundle/ruby/2.3.0/gems/pg-0.19.0/ext/pg_type_map_by_class.o +0 -0
  63. data/test/dummy/vendor/bundle/ruby/2.3.0/gems/pg-0.19.0/ext/pg_type_map_by_column.c +312 -0
  64. data/test/dummy/vendor/bundle/ruby/2.3.0/gems/pg-0.19.0/ext/pg_type_map_by_column.o +0 -0
  65. data/test/dummy/vendor/bundle/ruby/2.3.0/gems/pg-0.19.0/ext/pg_type_map_by_mri_type.c +284 -0
  66. data/test/dummy/vendor/bundle/ruby/2.3.0/gems/pg-0.19.0/ext/pg_type_map_by_mri_type.o +0 -0
  67. data/test/dummy/vendor/bundle/ruby/2.3.0/gems/pg-0.19.0/ext/pg_type_map_by_oid.c +355 -0
  68. data/test/dummy/vendor/bundle/ruby/2.3.0/gems/pg-0.19.0/ext/pg_type_map_by_oid.o +0 -0
  69. data/test/dummy/vendor/bundle/ruby/2.3.0/gems/pg-0.19.0/ext/pg_type_map_in_ruby.c +299 -0
  70. data/test/dummy/vendor/bundle/ruby/2.3.0/gems/pg-0.19.0/ext/pg_type_map_in_ruby.o +0 -0
  71. data/test/dummy/vendor/bundle/ruby/2.3.0/gems/pg-0.19.0/ext/util.c +149 -0
  72. data/test/dummy/vendor/bundle/ruby/2.3.0/gems/pg-0.19.0/ext/util.h +65 -0
  73. data/test/dummy/vendor/bundle/ruby/2.3.0/gems/pg-0.19.0/ext/util.o +0 -0
  74. data/test/dummy/vendor/bundle/ruby/2.3.0/gems/pg-0.19.0/ext/vc/pg.sln +26 -0
  75. data/test/dummy/vendor/bundle/ruby/2.3.0/gems/pg-0.19.0/ext/vc/pg_18/pg.vcproj +216 -0
  76. data/test/dummy/vendor/bundle/ruby/2.3.0/gems/pg-0.19.0/ext/vc/pg_19/pg_19.vcproj +209 -0
  77. data/test/dummy/vendor/bundle/ruby/2.3.0/gems/pg-0.19.0/lib/pg.rb +64 -0
  78. data/test/dummy/vendor/bundle/ruby/2.3.0/gems/pg-0.19.0/lib/pg/basic_type_mapping.rb +426 -0
  79. data/test/dummy/vendor/bundle/ruby/2.3.0/gems/pg-0.19.0/lib/pg/coder.rb +83 -0
  80. data/test/dummy/vendor/bundle/ruby/2.3.0/gems/pg-0.19.0/lib/pg/connection.rb +271 -0
  81. data/test/dummy/vendor/bundle/ruby/2.3.0/gems/pg-0.19.0/lib/pg/constants.rb +11 -0
  82. data/test/dummy/vendor/bundle/ruby/2.3.0/gems/pg-0.19.0/lib/pg/exceptions.rb +11 -0
  83. data/test/dummy/vendor/bundle/ruby/2.3.0/gems/pg-0.19.0/lib/pg/result.rb +30 -0
  84. data/test/dummy/vendor/bundle/ruby/2.3.0/gems/pg-0.19.0/lib/pg/text_decoder.rb +51 -0
  85. data/test/dummy/vendor/bundle/ruby/2.3.0/gems/pg-0.19.0/lib/pg/text_encoder.rb +35 -0
  86. data/test/dummy/vendor/bundle/ruby/2.3.0/gems/pg-0.19.0/lib/pg/type_map_by_column.rb +15 -0
  87. data/test/dummy/vendor/bundle/ruby/2.3.0/gems/pg-0.19.0/lib/pg_ext.bundle +0 -0
  88. data/test/dummy/vendor/bundle/ruby/2.3.0/gems/pg-0.19.0/sample/array_insert.rb +20 -0
  89. data/test/dummy/vendor/bundle/ruby/2.3.0/gems/pg-0.19.0/sample/async_api.rb +106 -0
  90. data/test/dummy/vendor/bundle/ruby/2.3.0/gems/pg-0.19.0/sample/async_copyto.rb +39 -0
  91. data/test/dummy/vendor/bundle/ruby/2.3.0/gems/pg-0.19.0/sample/async_mixed.rb +56 -0
  92. data/test/dummy/vendor/bundle/ruby/2.3.0/gems/pg-0.19.0/sample/check_conn.rb +21 -0
  93. data/test/dummy/vendor/bundle/ruby/2.3.0/gems/pg-0.19.0/sample/copyfrom.rb +81 -0
  94. data/test/dummy/vendor/bundle/ruby/2.3.0/gems/pg-0.19.0/sample/copyto.rb +19 -0
  95. data/test/dummy/vendor/bundle/ruby/2.3.0/gems/pg-0.19.0/sample/cursor.rb +21 -0
  96. data/test/dummy/vendor/bundle/ruby/2.3.0/gems/pg-0.19.0/sample/disk_usage_report.rb +186 -0
  97. data/test/dummy/vendor/bundle/ruby/2.3.0/gems/pg-0.19.0/sample/issue-119.rb +94 -0
  98. data/test/dummy/vendor/bundle/ruby/2.3.0/gems/pg-0.19.0/sample/losample.rb +69 -0
  99. data/test/dummy/vendor/bundle/ruby/2.3.0/gems/pg-0.19.0/sample/minimal-testcase.rb +17 -0
  100. data/test/dummy/vendor/bundle/ruby/2.3.0/gems/pg-0.19.0/sample/notify_wait.rb +72 -0
  101. data/test/dummy/vendor/bundle/ruby/2.3.0/gems/pg-0.19.0/sample/pg_statistics.rb +294 -0
  102. data/test/dummy/vendor/bundle/ruby/2.3.0/gems/pg-0.19.0/sample/replication_monitor.rb +231 -0
  103. data/test/dummy/vendor/bundle/ruby/2.3.0/gems/pg-0.19.0/sample/test_binary_values.rb +33 -0
  104. data/test/dummy/vendor/bundle/ruby/2.3.0/gems/pg-0.19.0/sample/wal_shipper.rb +434 -0
  105. data/test/dummy/vendor/bundle/ruby/2.3.0/gems/pg-0.19.0/sample/warehouse_partitions.rb +320 -0
  106. data/test/dummy/vendor/bundle/ruby/2.3.0/gems/pg-0.19.0/spec/data/expected_trace.out +26 -0
  107. data/test/dummy/vendor/bundle/ruby/2.3.0/gems/pg-0.19.0/spec/data/random_binary_data +0 -0
  108. data/test/dummy/vendor/bundle/ruby/2.3.0/gems/pg-0.19.0/spec/helpers.rb +352 -0
  109. data/test/dummy/vendor/bundle/ruby/2.3.0/gems/pg-0.19.0/spec/pg/basic_type_mapping_spec.rb +305 -0
  110. data/test/dummy/vendor/bundle/ruby/2.3.0/gems/pg-0.19.0/spec/pg/connection_spec.rb +1676 -0
  111. data/test/dummy/vendor/bundle/ruby/2.3.0/gems/pg-0.19.0/spec/pg/result_spec.rb +449 -0
  112. data/test/dummy/vendor/bundle/ruby/2.3.0/gems/pg-0.19.0/spec/pg/type_map_by_class_spec.rb +138 -0
  113. data/test/dummy/vendor/bundle/ruby/2.3.0/gems/pg-0.19.0/spec/pg/type_map_by_column_spec.rb +222 -0
  114. data/test/dummy/vendor/bundle/ruby/2.3.0/gems/pg-0.19.0/spec/pg/type_map_by_mri_type_spec.rb +136 -0
  115. data/test/dummy/vendor/bundle/ruby/2.3.0/gems/pg-0.19.0/spec/pg/type_map_by_oid_spec.rb +149 -0
  116. data/test/dummy/vendor/bundle/ruby/2.3.0/gems/pg-0.19.0/spec/pg/type_map_in_ruby_spec.rb +164 -0
  117. data/test/dummy/vendor/bundle/ruby/2.3.0/gems/pg-0.19.0/spec/pg/type_map_spec.rb +22 -0
  118. data/test/dummy/vendor/bundle/ruby/2.3.0/gems/pg-0.19.0/spec/pg/type_spec.rb +777 -0
  119. data/test/dummy/vendor/bundle/ruby/2.3.0/gems/pg-0.19.0/spec/pg_spec.rb +50 -0
  120. data/test/dummy/vendor/bundle/ruby/2.3.0/gems/pq-0.0.1/Gemfile +4 -0
  121. data/test/dummy/vendor/bundle/ruby/2.3.0/gems/pq-0.0.1/LICENSE.txt +22 -0
  122. data/test/dummy/vendor/bundle/ruby/2.3.0/gems/pq-0.0.1/README.md +76 -0
  123. data/test/dummy/vendor/bundle/ruby/2.3.0/gems/pq-0.0.1/Rakefile +1 -0
  124. data/test/dummy/vendor/bundle/ruby/2.3.0/gems/pq-0.0.1/bin/console +7 -0
  125. data/test/dummy/vendor/bundle/ruby/2.3.0/gems/pq-0.0.1/lib/pq.rb +99 -0
  126. data/test/dummy/vendor/bundle/ruby/2.3.0/gems/pq-0.0.1/pq.gemspec +29 -0
  127. data/test/dummy/vendor/bundle/ruby/2.3.0/gems/pq-0.0.1/spec/helpers.rb +10 -0
  128. data/test/dummy/vendor/bundle/ruby/2.3.0/gems/pq-0.0.1/spec/queue_spec.rb +84 -0
  129. data/test/dummy/vendor/bundle/ruby/2.3.0/specifications/pg-0.19.0.gemspec +63 -0
  130. data/test/dummy/vendor/bundle/ruby/2.3.0/specifications/pq-0.0.1.gemspec +49 -0
  131. metadata +253 -1
@@ -0,0 +1,162 @@
1
+ /*
2
+ * pg_column_map.c - PG::ColumnMap class extension
3
+ * $Id: pg_binary_encoder.c,v e61a06f1f5ed 2015/12/25 21:14:21 lars $
4
+ *
5
+ */
6
+
7
+ #include "pg.h"
8
+ #include "util.h"
9
+ #ifdef HAVE_INTTYPES_H
10
+ #include <inttypes.h>
11
+ #endif
12
+
13
+ VALUE rb_mPG_BinaryEncoder;
14
+
15
+
16
+ /*
17
+ * Document-class: PG::BinaryEncoder::Boolean < PG::SimpleEncoder
18
+ *
19
+ * This is the encoder class for the PostgreSQL boolean type.
20
+ *
21
+ * It accepts true and false. Other values will raise an exception.
22
+ *
23
+ */
24
+ static int
25
+ pg_bin_enc_boolean(t_pg_coder *conv, VALUE value, char *out, VALUE *intermediate, int enc_idx)
26
+ {
27
+ char mybool;
28
+ switch(value){
29
+ case Qtrue : mybool = 1; break;
30
+ case Qfalse : mybool = 0; break;
31
+ default :
32
+ rb_raise( rb_eTypeError, "wrong data for binary boolean converter" );
33
+ }
34
+ if(out) *out = mybool;
35
+ return 1;
36
+ }
37
+
38
+ /*
39
+ * Document-class: PG::BinaryEncoder::Int2 < PG::SimpleEncoder
40
+ *
41
+ * This is the encoder class for the PostgreSQL int2 type.
42
+ *
43
+ * Non-Number values are expected to have method +to_i+ defined.
44
+ *
45
+ */
46
+ static int
47
+ pg_bin_enc_int2(t_pg_coder *conv, VALUE value, char *out, VALUE *intermediate, int enc_idx)
48
+ {
49
+ if(out){
50
+ write_nbo16(NUM2INT(*intermediate), out);
51
+ }else{
52
+ *intermediate = pg_obj_to_i(value);
53
+ }
54
+ return 2;
55
+ }
56
+
57
+ /*
58
+ * Document-class: PG::BinaryEncoder::Int2 < PG::SimpleEncoder
59
+ *
60
+ * This is the encoder class for the PostgreSQL int4 type.
61
+ *
62
+ * Non-Number values are expected to have method +to_i+ defined.
63
+ *
64
+ */
65
+ static int
66
+ pg_bin_enc_int4(t_pg_coder *conv, VALUE value, char *out, VALUE *intermediate, int enc_idx)
67
+ {
68
+ if(out){
69
+ write_nbo32(NUM2LONG(*intermediate), out);
70
+ }else{
71
+ *intermediate = pg_obj_to_i(value);
72
+ }
73
+ return 4;
74
+ }
75
+
76
+ /*
77
+ * Document-class: PG::BinaryEncoder::Int2 < PG::SimpleEncoder
78
+ *
79
+ * This is the encoder class for the PostgreSQL int8 type.
80
+ *
81
+ * Non-Number values are expected to have method +to_i+ defined.
82
+ *
83
+ */
84
+ static int
85
+ pg_bin_enc_int8(t_pg_coder *conv, VALUE value, char *out, VALUE *intermediate, int enc_idx)
86
+ {
87
+ if(out){
88
+ write_nbo64(NUM2LL(*intermediate), out);
89
+ }else{
90
+ *intermediate = pg_obj_to_i(value);
91
+ }
92
+ return 8;
93
+ }
94
+
95
+ /*
96
+ * Document-class: PG::BinaryEncoder::FromBase64 < PG::CompositeEncoder
97
+ *
98
+ * This is an encoder class for conversion of base64 encoded data
99
+ * to it's binary representation.
100
+ *
101
+ */
102
+ static int
103
+ pg_bin_enc_from_base64(t_pg_coder *conv, VALUE value, char *out, VALUE *intermediate, int enc_idx)
104
+ {
105
+ int strlen;
106
+ VALUE subint;
107
+ t_pg_composite_coder *this = (t_pg_composite_coder *)conv;
108
+ t_pg_coder_enc_func enc_func = pg_coder_enc_func(this->elem);
109
+
110
+ if(out){
111
+ /* Second encoder pass, if required */
112
+ strlen = enc_func(this->elem, value, out, intermediate, enc_idx);
113
+ strlen = base64_decode( out, out, strlen );
114
+
115
+ return strlen;
116
+ } else {
117
+ /* First encoder pass */
118
+ strlen = enc_func(this->elem, value, NULL, &subint, enc_idx);
119
+
120
+ if( strlen == -1 ){
121
+ /* Encoded string is returned in subint */
122
+ VALUE out_str;
123
+
124
+ strlen = RSTRING_LENINT(subint);
125
+ out_str = rb_str_new(NULL, BASE64_DECODED_SIZE(strlen));
126
+
127
+ strlen = base64_decode( RSTRING_PTR(out_str), RSTRING_PTR(subint), strlen);
128
+ rb_str_set_len( out_str, strlen );
129
+ *intermediate = out_str;
130
+
131
+ return -1;
132
+ } else {
133
+ *intermediate = subint;
134
+
135
+ return BASE64_DECODED_SIZE(strlen);
136
+ }
137
+ }
138
+ }
139
+
140
+ void
141
+ init_pg_binary_encoder()
142
+ {
143
+ /* This module encapsulates all encoder classes with binary output format */
144
+ rb_mPG_BinaryEncoder = rb_define_module_under( rb_mPG, "BinaryEncoder" );
145
+
146
+ /* Make RDoc aware of the encoder classes... */
147
+ /* dummy = rb_define_class_under( rb_mPG_BinaryEncoder, "Boolean", rb_cPG_SimpleEncoder ); */
148
+ pg_define_coder( "Boolean", pg_bin_enc_boolean, rb_cPG_SimpleEncoder, rb_mPG_BinaryEncoder );
149
+ /* dummy = rb_define_class_under( rb_mPG_BinaryEncoder, "Int2", rb_cPG_SimpleEncoder ); */
150
+ pg_define_coder( "Int2", pg_bin_enc_int2, rb_cPG_SimpleEncoder, rb_mPG_BinaryEncoder );
151
+ /* dummy = rb_define_class_under( rb_mPG_BinaryEncoder, "Int4", rb_cPG_SimpleEncoder ); */
152
+ pg_define_coder( "Int4", pg_bin_enc_int4, rb_cPG_SimpleEncoder, rb_mPG_BinaryEncoder );
153
+ /* dummy = rb_define_class_under( rb_mPG_BinaryEncoder, "Int8", rb_cPG_SimpleEncoder ); */
154
+ pg_define_coder( "Int8", pg_bin_enc_int8, rb_cPG_SimpleEncoder, rb_mPG_BinaryEncoder );
155
+ /* dummy = rb_define_class_under( rb_mPG_BinaryEncoder, "String", rb_cPG_SimpleEncoder ); */
156
+ pg_define_coder( "String", pg_coder_enc_to_s, rb_cPG_SimpleEncoder, rb_mPG_BinaryEncoder );
157
+ /* dummy = rb_define_class_under( rb_mPG_BinaryEncoder, "Bytea", rb_cPG_SimpleEncoder ); */
158
+ pg_define_coder( "Bytea", pg_coder_enc_to_s, rb_cPG_SimpleEncoder, rb_mPG_BinaryEncoder );
159
+
160
+ /* dummy = rb_define_class_under( rb_mPG_BinaryEncoder, "FromBase64", rb_cPG_CompositeEncoder ); */
161
+ pg_define_coder( "FromBase64", pg_bin_enc_from_base64, rb_cPG_CompositeEncoder, rb_mPG_BinaryEncoder );
162
+ }
@@ -0,0 +1,500 @@
1
+ /*
2
+ * pg_coder.c - PG::Coder class extension
3
+ *
4
+ */
5
+
6
+ #include "pg.h"
7
+
8
+ VALUE rb_cPG_Coder;
9
+ VALUE rb_cPG_SimpleCoder;
10
+ VALUE rb_cPG_SimpleEncoder;
11
+ VALUE rb_cPG_SimpleDecoder;
12
+ VALUE rb_cPG_CompositeCoder;
13
+ VALUE rb_cPG_CompositeEncoder;
14
+ VALUE rb_cPG_CompositeDecoder;
15
+ VALUE rb_mPG_BinaryFormatting;
16
+ static ID s_id_encode;
17
+ static ID s_id_decode;
18
+ static ID s_id_CFUNC;
19
+
20
+ static VALUE
21
+ pg_coder_allocate( VALUE klass )
22
+ {
23
+ rb_raise( rb_eTypeError, "PG::Coder cannot be instantiated directly");
24
+ }
25
+
26
+ void
27
+ pg_coder_init_encoder( VALUE self )
28
+ {
29
+ t_pg_coder *this = DATA_PTR( self );
30
+ VALUE klass = rb_class_of(self);
31
+ if( rb_const_defined( klass, s_id_CFUNC ) ){
32
+ VALUE cfunc = rb_const_get( klass, s_id_CFUNC );
33
+ this->enc_func = DATA_PTR(cfunc);
34
+ } else {
35
+ this->enc_func = NULL;
36
+ }
37
+ this->dec_func = NULL;
38
+ this->coder_obj = self;
39
+ this->oid = 0;
40
+ this->format = 0;
41
+ rb_iv_set( self, "@name", Qnil );
42
+ }
43
+
44
+ void
45
+ pg_coder_init_decoder( VALUE self )
46
+ {
47
+ t_pg_coder *this = DATA_PTR( self );
48
+ VALUE klass = rb_class_of(self);
49
+ this->enc_func = NULL;
50
+ if( rb_const_defined( klass, s_id_CFUNC ) ){
51
+ VALUE cfunc = rb_const_get( klass, s_id_CFUNC );
52
+ this->dec_func = DATA_PTR(cfunc);
53
+ } else {
54
+ this->dec_func = NULL;
55
+ }
56
+ this->coder_obj = self;
57
+ this->oid = 0;
58
+ this->format = 0;
59
+ rb_iv_set( self, "@name", Qnil );
60
+ }
61
+
62
+ static VALUE
63
+ pg_simple_encoder_allocate( VALUE klass )
64
+ {
65
+ t_pg_coder *this;
66
+ VALUE self = Data_Make_Struct( klass, t_pg_coder, NULL, -1, this );
67
+ pg_coder_init_encoder( self );
68
+ return self;
69
+ }
70
+
71
+ static VALUE
72
+ pg_composite_encoder_allocate( VALUE klass )
73
+ {
74
+ t_pg_composite_coder *this;
75
+ VALUE self = Data_Make_Struct( klass, t_pg_composite_coder, NULL, -1, this );
76
+ pg_coder_init_encoder( self );
77
+ this->elem = NULL;
78
+ this->needs_quotation = 1;
79
+ this->delimiter = ',';
80
+ rb_iv_set( self, "@elements_type", Qnil );
81
+ return self;
82
+ }
83
+
84
+ static VALUE
85
+ pg_simple_decoder_allocate( VALUE klass )
86
+ {
87
+ t_pg_coder *this;
88
+ VALUE self = Data_Make_Struct( klass, t_pg_coder, NULL, -1, this );
89
+ pg_coder_init_decoder( self );
90
+ return self;
91
+ }
92
+
93
+ static VALUE
94
+ pg_composite_decoder_allocate( VALUE klass )
95
+ {
96
+ t_pg_composite_coder *this;
97
+ VALUE self = Data_Make_Struct( klass, t_pg_composite_coder, NULL, -1, this );
98
+ pg_coder_init_decoder( self );
99
+ this->elem = NULL;
100
+ this->needs_quotation = 1;
101
+ this->delimiter = ',';
102
+ rb_iv_set( self, "@elements_type", Qnil );
103
+ return self;
104
+ }
105
+
106
+ /*
107
+ * call-seq:
108
+ * coder.encode( value )
109
+ *
110
+ * Encodes the given Ruby object into string representation, without
111
+ * sending data to/from the database server.
112
+ *
113
+ * A nil value is passed through.
114
+ *
115
+ */
116
+ static VALUE
117
+ pg_coder_encode(int argc, VALUE *argv, VALUE self)
118
+ {
119
+ VALUE res;
120
+ VALUE intermediate;
121
+ VALUE value;
122
+ int len, len2;
123
+ int enc_idx;
124
+ t_pg_coder *this = DATA_PTR(self);
125
+
126
+ if(argc < 1 || argc > 2){
127
+ rb_raise(rb_eArgError, "wrong number of arguments (%i for 1..2)", argc);
128
+ }else if(argc == 1){
129
+ enc_idx = rb_ascii8bit_encindex();
130
+ }else{
131
+ enc_idx = rb_to_encoding_index(argv[1]);
132
+ }
133
+ value = argv[0];
134
+
135
+ if( NIL_P(value) )
136
+ return Qnil;
137
+
138
+ if( !this->enc_func ){
139
+ rb_raise(rb_eRuntimeError, "no encoder function defined");
140
+ }
141
+
142
+ len = this->enc_func( this, value, NULL, &intermediate, enc_idx );
143
+
144
+ if( len == -1 ){
145
+ /* The intermediate value is a String that can be used directly. */
146
+ OBJ_INFECT(intermediate, value);
147
+ return intermediate;
148
+ }
149
+
150
+ res = rb_str_new(NULL, len);
151
+ PG_ENCODING_SET_NOCHECK(res, enc_idx);
152
+ len2 = this->enc_func( this, value, RSTRING_PTR(res), &intermediate, enc_idx );
153
+ if( len < len2 ){
154
+ rb_bug("%s: result length of first encoder run (%i) is less than second run (%i)",
155
+ rb_obj_classname( self ), len, len2 );
156
+ }
157
+ rb_str_set_len( res, len2 );
158
+ OBJ_INFECT(res, value);
159
+
160
+ RB_GC_GUARD(intermediate);
161
+
162
+ return res;
163
+ }
164
+
165
+ /*
166
+ * call-seq:
167
+ * coder.decode( string, tuple=nil, field=nil )
168
+ *
169
+ * Decodes the given string representation into a Ruby object, without
170
+ * sending data to/from the database server.
171
+ *
172
+ * A nil value is passed through and non String values are expected to have
173
+ * #to_str defined.
174
+ *
175
+ */
176
+ static VALUE
177
+ pg_coder_decode(int argc, VALUE *argv, VALUE self)
178
+ {
179
+ char *val;
180
+ int tuple = -1;
181
+ int field = -1;
182
+ VALUE res;
183
+ t_pg_coder *this = DATA_PTR(self);
184
+
185
+ if(argc < 1 || argc > 3){
186
+ rb_raise(rb_eArgError, "wrong number of arguments (%i for 1..3)", argc);
187
+ }else if(argc >= 3){
188
+ tuple = NUM2INT(argv[1]);
189
+ field = NUM2INT(argv[2]);
190
+ }
191
+
192
+ if( NIL_P(argv[0]) )
193
+ return Qnil;
194
+
195
+ val = StringValuePtr(argv[0]);
196
+ if( !this->dec_func ){
197
+ rb_raise(rb_eRuntimeError, "no decoder function defined");
198
+ }
199
+
200
+ res = this->dec_func(this, val, RSTRING_LEN(argv[0]), tuple, field, ENCODING_GET(argv[0]));
201
+ OBJ_INFECT(res, argv[0]);
202
+
203
+ return res;
204
+ }
205
+
206
+ /*
207
+ * call-seq:
208
+ * coder.oid = Integer
209
+ *
210
+ * Specifies the type OID that is sent alongside with an encoded
211
+ * query parameter value.
212
+ *
213
+ * The default is +0+.
214
+ */
215
+ static VALUE
216
+ pg_coder_oid_set(VALUE self, VALUE oid)
217
+ {
218
+ t_pg_coder *this = DATA_PTR(self);
219
+ this->oid = NUM2UINT(oid);
220
+ return oid;
221
+ }
222
+
223
+ /*
224
+ * call-seq:
225
+ * coder.oid -> Integer
226
+ *
227
+ * The type OID that is sent alongside with an encoded
228
+ * query parameter value.
229
+ */
230
+ static VALUE
231
+ pg_coder_oid_get(VALUE self)
232
+ {
233
+ t_pg_coder *this = DATA_PTR(self);
234
+ return UINT2NUM(this->oid);
235
+ }
236
+
237
+ /*
238
+ * call-seq:
239
+ * coder.format = Integer
240
+ *
241
+ * Specifies the format code that is sent alongside with an encoded
242
+ * query parameter value.
243
+ *
244
+ * The default is +0+.
245
+ */
246
+ static VALUE
247
+ pg_coder_format_set(VALUE self, VALUE format)
248
+ {
249
+ t_pg_coder *this = DATA_PTR(self);
250
+ this->format = NUM2INT(format);
251
+ return format;
252
+ }
253
+
254
+ /*
255
+ * call-seq:
256
+ * coder.format -> Integer
257
+ *
258
+ * The format code that is sent alongside with an encoded
259
+ * query parameter value.
260
+ */
261
+ static VALUE
262
+ pg_coder_format_get(VALUE self)
263
+ {
264
+ t_pg_coder *this = DATA_PTR(self);
265
+ return INT2NUM(this->format);
266
+ }
267
+
268
+ /*
269
+ * call-seq:
270
+ * coder.needs_quotation = Boolean
271
+ *
272
+ * Specifies whether the assigned #elements_type requires quotation marks to
273
+ * be transferred safely. Encoding with #needs_quotation=false is somewhat
274
+ * faster.
275
+ *
276
+ * The default is +true+. This option is ignored for decoding of values.
277
+ */
278
+ static VALUE
279
+ pg_coder_needs_quotation_set(VALUE self, VALUE needs_quotation)
280
+ {
281
+ t_pg_composite_coder *this = DATA_PTR(self);
282
+ this->needs_quotation = RTEST(needs_quotation);
283
+ return needs_quotation;
284
+ }
285
+
286
+ /*
287
+ * call-seq:
288
+ * coder.needs_quotation -> Boolean
289
+ *
290
+ * Specifies whether the assigned #elements_type requires quotation marks to
291
+ * be transferred safely.
292
+ */
293
+ static VALUE
294
+ pg_coder_needs_quotation_get(VALUE self)
295
+ {
296
+ t_pg_composite_coder *this = DATA_PTR(self);
297
+ return this->needs_quotation ? Qtrue : Qfalse;
298
+ }
299
+
300
+ /*
301
+ * call-seq:
302
+ * coder.delimiter = String
303
+ *
304
+ * Specifies the character that separates values within the composite type.
305
+ * The default is a comma.
306
+ * This must be a single one-byte character.
307
+ */
308
+ static VALUE
309
+ pg_coder_delimiter_set(VALUE self, VALUE delimiter)
310
+ {
311
+ t_pg_composite_coder *this = DATA_PTR(self);
312
+ StringValue(delimiter);
313
+ if(RSTRING_LEN(delimiter) != 1)
314
+ rb_raise( rb_eArgError, "delimiter size must be one byte");
315
+ this->delimiter = *RSTRING_PTR(delimiter);
316
+ return delimiter;
317
+ }
318
+
319
+ /*
320
+ * call-seq:
321
+ * coder.delimiter -> String
322
+ *
323
+ * The character that separates values within the composite type.
324
+ */
325
+ static VALUE
326
+ pg_coder_delimiter_get(VALUE self)
327
+ {
328
+ t_pg_composite_coder *this = DATA_PTR(self);
329
+ return rb_str_new(&this->delimiter, 1);
330
+ }
331
+
332
+ /*
333
+ * call-seq:
334
+ * coder.elements_type = coder
335
+ *
336
+ * Specifies the PG::Coder object that is used to encode or decode
337
+ * the single elementes of this composite type.
338
+ *
339
+ * If set to +nil+ all values are encoded and decoded as String objects.
340
+ */
341
+ static VALUE
342
+ pg_coder_elements_type_set(VALUE self, VALUE elem_type)
343
+ {
344
+ t_pg_composite_coder *this = DATA_PTR( self );
345
+
346
+ if ( NIL_P(elem_type) ){
347
+ this->elem = NULL;
348
+ } else if ( rb_obj_is_kind_of(elem_type, rb_cPG_Coder) ){
349
+ this->elem = DATA_PTR( elem_type );
350
+ } else {
351
+ rb_raise( rb_eTypeError, "wrong elements type %s (expected some kind of PG::Coder)",
352
+ rb_obj_classname( elem_type ) );
353
+ }
354
+
355
+ rb_iv_set( self, "@elements_type", elem_type );
356
+ return elem_type;
357
+ }
358
+
359
+ void
360
+ pg_define_coder( const char *name, void *func, VALUE base_klass, VALUE nsp )
361
+ {
362
+ VALUE cfunc_obj = Data_Wrap_Struct( rb_cObject, NULL, NULL, func );
363
+ VALUE coder_klass = rb_define_class_under( nsp, name, base_klass );
364
+ if( nsp==rb_mPG_BinaryEncoder || nsp==rb_mPG_BinaryDecoder )
365
+ rb_include_module( coder_klass, rb_mPG_BinaryFormatting );
366
+
367
+ rb_define_const( coder_klass, "CFUNC", cfunc_obj );
368
+
369
+ RB_GC_GUARD(cfunc_obj);
370
+ }
371
+
372
+
373
+ static int
374
+ pg_text_enc_in_ruby(t_pg_coder *conv, VALUE value, char *out, VALUE *intermediate, int enc_idx)
375
+ {
376
+ int arity = rb_obj_method_arity(conv->coder_obj, s_id_encode);
377
+ if( arity == 1 ){
378
+ VALUE out_str = rb_funcall( conv->coder_obj, s_id_encode, 1, value );
379
+ StringValue( out_str );
380
+ *intermediate = rb_str_export_to_enc(out_str, rb_enc_from_index(enc_idx));
381
+ }else{
382
+ VALUE enc = rb_enc_from_encoding(rb_enc_from_index(enc_idx));
383
+ VALUE out_str = rb_funcall( conv->coder_obj, s_id_encode, 2, value, enc );
384
+ StringValue( out_str );
385
+ *intermediate = out_str;
386
+ }
387
+ return -1;
388
+ }
389
+
390
+ t_pg_coder_enc_func
391
+ pg_coder_enc_func(t_pg_coder *this)
392
+ {
393
+ if( this ){
394
+ if( this->enc_func ){
395
+ return this->enc_func;
396
+ }else{
397
+ return pg_text_enc_in_ruby;
398
+ }
399
+ }else{
400
+ /* no element encoder defined -> use std to_str conversion */
401
+ return pg_coder_enc_to_s;
402
+ }
403
+ }
404
+
405
+ static VALUE
406
+ pg_text_dec_in_ruby(t_pg_coder *this, char *val, int len, int tuple, int field, int enc_idx)
407
+ {
408
+ VALUE string = pg_text_dec_string(this, val, len, tuple, field, enc_idx);
409
+ return rb_funcall( this->coder_obj, s_id_decode, 3, string, INT2NUM(tuple), INT2NUM(field) );
410
+ }
411
+
412
+ static VALUE
413
+ pg_bin_dec_in_ruby(t_pg_coder *this, char *val, int len, int tuple, int field, int enc_idx)
414
+ {
415
+ VALUE string = pg_bin_dec_bytea(this, val, len, tuple, field, enc_idx);
416
+ return rb_funcall( this->coder_obj, s_id_decode, 3, string, INT2NUM(tuple), INT2NUM(field) );
417
+ }
418
+
419
+ t_pg_coder_dec_func
420
+ pg_coder_dec_func(t_pg_coder *this, int binary)
421
+ {
422
+ if( this ){
423
+ if( this->dec_func ){
424
+ return this->dec_func;
425
+ }else{
426
+ return binary ? pg_bin_dec_in_ruby : pg_text_dec_in_ruby;
427
+ }
428
+ }else{
429
+ /* no element decoder defined -> use std String conversion */
430
+ return binary ? pg_bin_dec_bytea : pg_text_dec_string;
431
+ }
432
+ }
433
+
434
+
435
+ void
436
+ init_pg_coder()
437
+ {
438
+ s_id_encode = rb_intern("encode");
439
+ s_id_decode = rb_intern("decode");
440
+ s_id_CFUNC = rb_intern("CFUNC");
441
+
442
+ /* Document-class: PG::Coder < Object
443
+ *
444
+ * This is the base class for all type cast encoder and decoder classes.
445
+ *
446
+ * It can be used for implicit type casts by a PG::TypeMap or to
447
+ * convert single values to/from their string representation by #encode
448
+ * and #decode.
449
+ *
450
+ * Ruby +nil+ values are not handled by encoders, but are always transmitted
451
+ * as SQL +NULL+ value. Vice versa SQL +NULL+ values are not handled by decoders,
452
+ * but are always returned as a +nil+ value.
453
+ */
454
+ rb_cPG_Coder = rb_define_class_under( rb_mPG, "Coder", rb_cObject );
455
+ rb_define_alloc_func( rb_cPG_Coder, pg_coder_allocate );
456
+ rb_define_method( rb_cPG_Coder, "oid=", pg_coder_oid_set, 1 );
457
+ rb_define_method( rb_cPG_Coder, "oid", pg_coder_oid_get, 0 );
458
+ rb_define_method( rb_cPG_Coder, "format=", pg_coder_format_set, 1 );
459
+ rb_define_method( rb_cPG_Coder, "format", pg_coder_format_get, 0 );
460
+ /*
461
+ * Name of the coder or the corresponding data type.
462
+ *
463
+ * This accessor is only used in PG::Coder#inspect .
464
+ */
465
+ rb_define_attr( rb_cPG_Coder, "name", 1, 1 );
466
+ rb_define_method( rb_cPG_Coder, "encode", pg_coder_encode, -1 );
467
+ rb_define_method( rb_cPG_Coder, "decode", pg_coder_decode, -1 );
468
+
469
+ /* Document-class: PG::SimpleCoder < PG::Coder */
470
+ rb_cPG_SimpleCoder = rb_define_class_under( rb_mPG, "SimpleCoder", rb_cPG_Coder );
471
+
472
+ /* Document-class: PG::SimpleEncoder < PG::SimpleCoder */
473
+ rb_cPG_SimpleEncoder = rb_define_class_under( rb_mPG, "SimpleEncoder", rb_cPG_SimpleCoder );
474
+ rb_define_alloc_func( rb_cPG_SimpleEncoder, pg_simple_encoder_allocate );
475
+ /* Document-class: PG::SimpleDecoder < PG::SimpleCoder */
476
+ rb_cPG_SimpleDecoder = rb_define_class_under( rb_mPG, "SimpleDecoder", rb_cPG_SimpleCoder );
477
+ rb_define_alloc_func( rb_cPG_SimpleDecoder, pg_simple_decoder_allocate );
478
+
479
+ /* Document-class: PG::CompositeCoder < PG::Coder
480
+ *
481
+ * This is the base class for all type cast classes of PostgreSQL types,
482
+ * that are made up of some sub type.
483
+ */
484
+ rb_cPG_CompositeCoder = rb_define_class_under( rb_mPG, "CompositeCoder", rb_cPG_Coder );
485
+ rb_define_method( rb_cPG_CompositeCoder, "elements_type=", pg_coder_elements_type_set, 1 );
486
+ rb_define_attr( rb_cPG_CompositeCoder, "elements_type", 1, 0 );
487
+ rb_define_method( rb_cPG_CompositeCoder, "needs_quotation=", pg_coder_needs_quotation_set, 1 );
488
+ rb_define_method( rb_cPG_CompositeCoder, "needs_quotation?", pg_coder_needs_quotation_get, 0 );
489
+ rb_define_method( rb_cPG_CompositeCoder, "delimiter=", pg_coder_delimiter_set, 1 );
490
+ rb_define_method( rb_cPG_CompositeCoder, "delimiter", pg_coder_delimiter_get, 0 );
491
+
492
+ /* Document-class: PG::CompositeEncoder < PG::CompositeCoder */
493
+ rb_cPG_CompositeEncoder = rb_define_class_under( rb_mPG, "CompositeEncoder", rb_cPG_CompositeCoder );
494
+ rb_define_alloc_func( rb_cPG_CompositeEncoder, pg_composite_encoder_allocate );
495
+ /* Document-class: PG::CompositeDecoder < PG::CompositeCoder */
496
+ rb_cPG_CompositeDecoder = rb_define_class_under( rb_mPG, "CompositeDecoder", rb_cPG_CompositeCoder );
497
+ rb_define_alloc_func( rb_cPG_CompositeDecoder, pg_composite_decoder_allocate );
498
+
499
+ rb_mPG_BinaryFormatting = rb_define_module_under( rb_cPG_Coder, "BinaryFormatting");
500
+ }