meta-record 1.0.17 → 1.0.19
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/lib/metarecord/generators/comet/archive_renderer_generator.rb +1 -1
- data/lib/metarecord/generators/comet/edit_generator.rb +17 -0
- data/lib/metarecord/generators/crails/data_generator.rb +29 -18
- data/lib/metarecord/generators/crails/destroy_generator.rb +2 -2
- data/lib/metarecord/generators/crails/edit_generator.rb +30 -15
- data/lib/metarecord/generators/crails/helpers/validations.rb +0 -2
- data/lib/metarecord/generators/crails/query_generator.rb +1 -1
- data/lib/metarecord/generators/crails/view_generator.rb +4 -1
- metadata +3 -3
checksums.yaml
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
---
|
|
2
2
|
SHA256:
|
|
3
|
-
metadata.gz:
|
|
4
|
-
data.tar.gz:
|
|
3
|
+
metadata.gz: 3e41de506b9fa767e378c13c840d5737d7b9ac2d740a6a6d358ff8ba5d2d68f1
|
|
4
|
+
data.tar.gz: eae697f4c148f9d6407e2e7ba7370db54874f172acec8be2c39bcabb94e84ab1
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: 2f29757b10fccb207b2cd907fb612dd6803977712f20eb7c8091af74f5358743e4182ee52cbc203d6f871264833c3796f13da7ad1dad7295f1f93e59e234092e
|
|
7
|
+
data.tar.gz: 5fffc5333a7a04642657038e0d66574e3ae6efff86bfbe41a379eaee54405385d57b40af6239877b79b9beaadce5580e10b49d211229aafe6e12797323e4af62
|
|
@@ -21,6 +21,23 @@ class CometEditGenerator < CrailsEditGenerator
|
|
|
21
21
|
@rendering_from_json = false
|
|
22
22
|
end
|
|
23
23
|
|
|
24
|
+
def generate_is_valid object
|
|
25
|
+
_append_macro "#ifndef #{CometDataGenerator.client_define}"
|
|
26
|
+
super
|
|
27
|
+
_append_macro "#else"
|
|
28
|
+
_append "bool #{@klassname}::is_valid()"
|
|
29
|
+
_append "{"
|
|
30
|
+
@indent += 1
|
|
31
|
+
_append "errors.clear();"
|
|
32
|
+
@rendering_validations = true
|
|
33
|
+
self.instance_eval &object[:block]
|
|
34
|
+
@rendering_validations = false
|
|
35
|
+
_append "return errors.as_data().get_keys().size() == 0;"
|
|
36
|
+
@indent -= 1
|
|
37
|
+
_append "}"
|
|
38
|
+
_append_macro "#endif"
|
|
39
|
+
end
|
|
40
|
+
|
|
24
41
|
def validation type, name, data
|
|
25
42
|
if data[:uniqueness] == true
|
|
26
43
|
_append_macro "#ifndef #{CometDataGenerator.client_define}"
|
|
@@ -69,11 +69,11 @@ class CrailsDataGenerator < GeneratorBase
|
|
|
69
69
|
|
|
70
70
|
def edit_resource_declaration
|
|
71
71
|
_append "virtual std::vector<std::string> find_missing_parameters(Data) const;"
|
|
72
|
-
_append "virtual void edit(Data);"
|
|
72
|
+
_append "virtual void edit(#{GeneratorBase.odb_connection[:object]}&, Data);"
|
|
73
73
|
_append "virtual void merge_data(Data) const;"
|
|
74
74
|
_append "virtual std::string to_json() const;"
|
|
75
|
-
_append "virtual bool is_valid();"
|
|
76
|
-
_append "virtual void on_dependent_destroy(
|
|
75
|
+
_append "virtual bool is_valid(#{GeneratorBase.odb_connection[:object]}&);"
|
|
76
|
+
_append "virtual void on_dependent_destroy(#{GeneratorBase.odb_connection[:object]}&, #{id_type});"
|
|
77
77
|
_append ""
|
|
78
78
|
end
|
|
79
79
|
|
|
@@ -173,32 +173,39 @@ class CrailsDataGenerator < GeneratorBase
|
|
|
173
173
|
_append "#{virt}#{tptr} get_#{name}() const { return #{name}; }"
|
|
174
174
|
_append "#{virt}void set_#{name}(#{tptr} v) { this->#{name} = v; }"
|
|
175
175
|
_append "#{virt}#{id_type} get_#{name}_id() const;"
|
|
176
|
-
|
|
176
|
+
_append <<CPP
|
|
177
|
+
template<typename ARRAY>
|
|
178
|
+
static void collect_#{name}(ARRAY& array, std::map<#{id_type}, #{tptr} >& results)
|
|
179
|
+
{
|
|
180
|
+
for (auto model : array)
|
|
181
|
+
{
|
|
182
|
+
if (results.find(model.get_#{name}_id()) == results.end())
|
|
183
|
+
results[model.get_#{name}_id()] = model.get_#{name}();
|
|
184
|
+
}
|
|
185
|
+
}
|
|
186
|
+
CPP
|
|
187
|
+
end
|
|
177
188
|
_append "#{tptr} #{name};"
|
|
178
189
|
else
|
|
179
190
|
with_visibility :public do
|
|
180
|
-
_append "#{virt}#{tptr} get_#{name}() const;"
|
|
191
|
+
_append "#{virt}#{tptr} get_#{name}(#{GeneratorBase.odb_connection[:object]}&) const;"
|
|
181
192
|
_append "#{virt}void set_#{name}(#{tptr} v);"
|
|
182
193
|
_append "#{id_type} get_#{name}_id() const { return #{name}_id; }"
|
|
183
194
|
_append "void set_#{name}_id(#{id_type} v) { #{name}_id = v; }"
|
|
184
|
-
|
|
185
|
-
make_pragma_db options[:db] unless options[:db].nil?
|
|
186
|
-
_append "#{id_type} #{name}_id = #{null_id};"
|
|
187
|
-
end
|
|
188
|
-
with_visibility :public do
|
|
189
|
-
_append <<CPP
|
|
190
|
-
|
|
195
|
+
_append <<CPP
|
|
191
196
|
template<typename ARRAY>
|
|
192
|
-
static void collect_#{name}(ARRAY& array, std::map<#{id_type}, #{tptr} >& results)
|
|
197
|
+
static void collect_#{name}(#{GeneratorBase.odb_connection[:object]}& database, ARRAY& array, std::map<#{id_type}, #{tptr} >& results)
|
|
193
198
|
{
|
|
194
199
|
for (auto model : array)
|
|
195
200
|
{
|
|
196
201
|
if (results.find(model.get_#{name}_id()) == results.end())
|
|
197
|
-
results[model.get_#{name}_id()] = model.get_#{name}();
|
|
202
|
+
results[model.get_#{name}_id()] = model.get_#{name}(database);
|
|
198
203
|
}
|
|
199
204
|
}
|
|
200
|
-
|
|
201
205
|
CPP
|
|
206
|
+
end
|
|
207
|
+
make_pragma_db options[:db] unless options[:db].nil?
|
|
208
|
+
_append "#{id_type} #{name}_id = #{null_id};"
|
|
202
209
|
end
|
|
203
210
|
end
|
|
204
211
|
|
|
@@ -213,7 +220,11 @@ CPP
|
|
|
213
220
|
_append "#{virt}bool update_#{name}(Data);"
|
|
214
221
|
_append "#{virt}void add_#{singular_name}(#{tptr});"
|
|
215
222
|
_append "#{virt}void remove_#{singular_name}(const #{type}&);"
|
|
216
|
-
|
|
223
|
+
if options[:joined] != false
|
|
224
|
+
_append "#{virt}void collect_#{name}(std::map<#{id_type}, #{tptr} >&);"
|
|
225
|
+
else
|
|
226
|
+
_append "#{virt}void collect_#{name}(#{GeneratorBase.odb_connection[:object]}&, std::map<#{id_type}, #{tptr} >&);"
|
|
227
|
+
end
|
|
217
228
|
end
|
|
218
229
|
if options[:joined] != false
|
|
219
230
|
_join_based_has_many list_type, name, options
|
|
@@ -233,7 +244,7 @@ CPP
|
|
|
233
244
|
|
|
234
245
|
def has_many_fetch list_type, name, options
|
|
235
246
|
with_visibility :public do
|
|
236
|
-
_append "void fetch_#{name}();"
|
|
247
|
+
_append "void fetch_#{name}(#{GeneratorBase.odb_connection[:object]}&);"
|
|
237
248
|
end
|
|
238
249
|
end
|
|
239
250
|
|
|
@@ -242,7 +253,7 @@ CPP
|
|
|
242
253
|
store_type = "std::vector<#{id_type}>"
|
|
243
254
|
with_visibility :public do
|
|
244
255
|
_append "const #{store_type}& get_#{singular_name}_ids() const { return #{singular_name}_ids; }"
|
|
245
|
-
_append "const #{list_type}& get_#{name}();"
|
|
256
|
+
_append "const #{list_type}& get_#{name}(#{GeneratorBase.odb_connection[:object]}&);"
|
|
246
257
|
_append "void set_#{singular_name}_ids(const #{store_type}& val) { #{singular_name}_ids = val; #{name}_fetched = false; }"
|
|
247
258
|
end
|
|
248
259
|
has_many_fetch list_type, name, options
|
|
@@ -47,9 +47,9 @@ class CrailsDestroyGenerator < GeneratorBase
|
|
|
47
47
|
def extension ; ".destroy.cpp" ; end
|
|
48
48
|
|
|
49
49
|
def make_file filename, data
|
|
50
|
-
include = "
|
|
50
|
+
include = "app/autogen/" + filename[0...-2] + "hpp"
|
|
51
51
|
source = "#include \"#{include}\"\n"
|
|
52
|
-
source += "#include \"
|
|
52
|
+
source += "#include \"app/autogen/#{filename[0...-2]}queries.hpp\"\n"
|
|
53
53
|
source += "#include <crails/odb/helpers.hpp>\n"
|
|
54
54
|
source += "#include <crails/odb/any.hpp>\n"
|
|
55
55
|
source += "#include <#{GeneratorBase.odb_connection[:include]}>\n"
|
|
@@ -26,7 +26,8 @@ class CrailsEditGenerator < GeneratorBase
|
|
|
26
26
|
end
|
|
27
27
|
|
|
28
28
|
def generate_edit_method object
|
|
29
|
-
|
|
29
|
+
db_param = "#{GeneratorBase.odb_connection[:object]}& database"
|
|
30
|
+
_append "void #{@klassname}::edit(#{db_param}, Data data)"
|
|
30
31
|
_append "{"
|
|
31
32
|
@indent += 1
|
|
32
33
|
self.instance_eval &object[:block]
|
|
@@ -64,8 +65,11 @@ class CrailsEditGenerator < GeneratorBase
|
|
|
64
65
|
end
|
|
65
66
|
@indent -= 1
|
|
66
67
|
_append "}"
|
|
68
|
+
generate_is_valid object
|
|
69
|
+
end
|
|
67
70
|
|
|
68
|
-
|
|
71
|
+
def generate_is_valid object
|
|
72
|
+
_append "bool #{@klassname}::is_valid(#{GeneratorBase.odb_connection[:object]}& database)"
|
|
69
73
|
_append "{"
|
|
70
74
|
@indent += 1
|
|
71
75
|
_append "errors.clear();"
|
|
@@ -99,11 +103,16 @@ class CrailsEditGenerator < GeneratorBase
|
|
|
99
103
|
else _append "data[\"#{name}\"] = #{name};"
|
|
100
104
|
end
|
|
101
105
|
elsif options[:read_only] != true && rendering_edit?
|
|
102
|
-
setter = "
|
|
103
|
-
|
|
106
|
+
setter = if type == "LocaleString"
|
|
107
|
+
"#{name}.from_data(data[\"#{name}\"]);"
|
|
108
|
+
elsif not (type =~ /^(unsigned)?\s*char$/).nil?
|
|
109
|
+
"set_#{name}(data[\"#{name}\"].as<int>());"
|
|
110
|
+
else
|
|
111
|
+
"set_#{name}(data[\"#{name}\"]);"
|
|
112
|
+
end
|
|
104
113
|
if options[:required] == true
|
|
105
114
|
@required_params.push "\"#{name}\""
|
|
106
|
-
|
|
115
|
+
_append setter
|
|
107
116
|
else
|
|
108
117
|
_append "if (data[\"#{name}\"].exists())"
|
|
109
118
|
@indent += 1
|
|
@@ -135,9 +144,8 @@ class CrailsEditGenerator < GeneratorBase
|
|
|
135
144
|
def has_one_getter type, name, options
|
|
136
145
|
type = get_type type
|
|
137
146
|
tptr = ptr_type type
|
|
138
|
-
_append "#{tptr} #{@klassname}::get_#{name}() const"
|
|
147
|
+
_append "#{tptr} #{@klassname}::get_#{name}(#{GeneratorBase.odb_connection[:object]}& database) const"
|
|
139
148
|
_append "{"
|
|
140
|
-
_append " #{GeneratorBase.odb_connection[:object]} database;"
|
|
141
149
|
_append " #{tptr} result;\n"
|
|
142
150
|
_append " database.find_one(result, #{name}_id);"
|
|
143
151
|
_append " return result;"
|
|
@@ -161,7 +169,6 @@ class CrailsEditGenerator < GeneratorBase
|
|
|
161
169
|
_append " set_#{name}(nullptr);"
|
|
162
170
|
_append " else if (!get_#{name}() || #{data_id} != get_#{name}()->get_id())"
|
|
163
171
|
_append " {"
|
|
164
|
-
_append " #{GeneratorBase.odb_connection[:object]} database;"
|
|
165
172
|
_append " #{tptr} linked_resource;"
|
|
166
173
|
_append " database.find_one(linked_resource, data[\"#{name}_id\"].as<#{id_type}>());"
|
|
167
174
|
_append " set_#{name}(linked_resource);"
|
|
@@ -216,10 +223,19 @@ class CrailsEditGenerator < GeneratorBase
|
|
|
216
223
|
else
|
|
217
224
|
_id_based_has_many type, name, options
|
|
218
225
|
end
|
|
219
|
-
_append "
|
|
226
|
+
_append "// options[:joined] = #{options[:joined]}, #{options[:joined] != false}"
|
|
227
|
+
if options[:joined] != false
|
|
228
|
+
_append "void #{@klassname}::collect_#{name}(std::map<#{id_type}, #{ptr_type type}>& results)"
|
|
229
|
+
else
|
|
230
|
+
_append "void #{@klassname}::collect_#{name}(#{GeneratorBase.odb_connection[:object]}& database, std::map<#{id_type}, #{ptr_type type}>& results)"
|
|
231
|
+
end
|
|
220
232
|
_append "{"
|
|
221
233
|
@indent += 1
|
|
222
|
-
|
|
234
|
+
if options[:joined] != false
|
|
235
|
+
_append "for (auto model : get_#{name}())"
|
|
236
|
+
else
|
|
237
|
+
_append "for (auto model : get_#{name}(database))"
|
|
238
|
+
end
|
|
223
239
|
_append "{"
|
|
224
240
|
@indent += 1
|
|
225
241
|
_append "if (results.find(model->get_id()) == results.end())"
|
|
@@ -311,12 +327,12 @@ class CrailsEditGenerator < GeneratorBase
|
|
|
311
327
|
@indent -= 2
|
|
312
328
|
_append "}\n"
|
|
313
329
|
|
|
314
|
-
_append "const std::list<#{tptr} >& #{@klassname}::get_#{name}()"
|
|
330
|
+
_append "const std::list<#{tptr} >& #{@klassname}::get_#{name}(#{GeneratorBase.odb_connection[:object]}& database)"
|
|
315
331
|
_append "{"
|
|
316
332
|
@indent += 1
|
|
317
333
|
_append "if (!#{name}_fetched)"
|
|
318
334
|
@indent += 1
|
|
319
|
-
_append "fetch_#{name}();"
|
|
335
|
+
_append "fetch_#{name}(database);"
|
|
320
336
|
@indent -= 1
|
|
321
337
|
_append "return #{name};"
|
|
322
338
|
@indent -= 1
|
|
@@ -328,11 +344,10 @@ class CrailsEditGenerator < GeneratorBase
|
|
|
328
344
|
def has_many_fetch type, name, options
|
|
329
345
|
singular_name = get_singular_name name
|
|
330
346
|
|
|
331
|
-
_append "void #{@klassname}::fetch_#{name}()"
|
|
347
|
+
_append "void #{@klassname}::fetch_#{name}(#{GeneratorBase.odb_connection[:object]}& database)"
|
|
332
348
|
_append "{"
|
|
333
349
|
@indent += 1
|
|
334
350
|
_append "typedef odb::pgsql::query<#{type}> query;"
|
|
335
|
-
_append "#{GeneratorBase.odb_connection[:object]} database;"
|
|
336
351
|
_append "odb::result<#{type}> results;"
|
|
337
352
|
_append "#{name}.clear();"
|
|
338
353
|
_append "database.find<#{type}>(results,"
|
|
@@ -356,7 +371,7 @@ class CrailsEditGenerator < GeneratorBase
|
|
|
356
371
|
end
|
|
357
372
|
|
|
358
373
|
def make_file filename, data
|
|
359
|
-
base = "
|
|
374
|
+
base = "app/autogen/" + filename[0...-3]
|
|
360
375
|
include = base + ".hpp"
|
|
361
376
|
data[:bodies].each do |body|
|
|
362
377
|
body.gsub! "${view-placeholder}", base.split("/")[0...-2].join("/")
|
|
@@ -25,7 +25,6 @@ def validate_uniqueness source_type, name
|
|
|
25
25
|
type = source_type[16..-2]
|
|
26
26
|
<<CPP
|
|
27
27
|
{
|
|
28
|
-
#{GeneratorBase.odb_connection[:object]} database;
|
|
29
28
|
odb::result<#{source_type}> results;
|
|
30
29
|
|
|
31
30
|
database.find(results, odb::query<#{source_type}::#{name}->id == get_#{name}_id());
|
|
@@ -36,7 +35,6 @@ CPP
|
|
|
36
35
|
else
|
|
37
36
|
<<CPP
|
|
38
37
|
{
|
|
39
|
-
#{GeneratorBase.odb_connection[:object]} database;
|
|
40
38
|
odb::result<#{source_type}> results;
|
|
41
39
|
|
|
42
40
|
database.find(results, odb::query<#{source_type}::#{name} == #{name});
|
|
@@ -72,7 +72,7 @@ CPP
|
|
|
72
72
|
def extension ; ".queries.hpp" ; end
|
|
73
73
|
|
|
74
74
|
def make_file filename, data
|
|
75
|
-
base = "
|
|
75
|
+
base = "app/autogen/" + filename[0...-3]
|
|
76
76
|
include = base + ".hpp"
|
|
77
77
|
file_define = "_#{filename[0...-3].upcase.gsub "/", "_"}_QUERIES_HPP"
|
|
78
78
|
source = <<CPP
|
|
@@ -18,6 +18,7 @@ class CrailsViewGenerator < GeneratorBase
|
|
|
18
18
|
reset
|
|
19
19
|
@declarations << "#include \"#{object[:header]}\"\n"
|
|
20
20
|
@declarations << "#{object[:classname]}& @model;"
|
|
21
|
+
@declarations << "Crails::Odb::Connection& @database;"
|
|
21
22
|
property id_type, "id"
|
|
22
23
|
self.instance_eval &object[:block]
|
|
23
24
|
@src
|
|
@@ -52,7 +53,9 @@ class CrailsViewGenerator < GeneratorBase
|
|
|
52
53
|
_append "{"
|
|
53
54
|
@indent += 1
|
|
54
55
|
id_attr = (get_singular_name name) + "_ids"
|
|
55
|
-
id_collector = if options
|
|
56
|
+
id_collector = if options.key? :ids_getter
|
|
57
|
+
options[:ids_getter]
|
|
58
|
+
elsif options[:joined] == false
|
|
56
59
|
"model.get_#{id_attr}()"
|
|
57
60
|
else
|
|
58
61
|
"collect_ids_from(model.get_#{name}())"
|
metadata
CHANGED
|
@@ -1,13 +1,13 @@
|
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
|
2
2
|
name: meta-record
|
|
3
3
|
version: !ruby/object:Gem::Version
|
|
4
|
-
version: 1.0.
|
|
4
|
+
version: 1.0.19
|
|
5
5
|
platform: ruby
|
|
6
6
|
authors:
|
|
7
7
|
- Michael Martin Moro
|
|
8
8
|
bindir: bin
|
|
9
9
|
cert_chain: []
|
|
10
|
-
date: 2026-11-
|
|
10
|
+
date: 2026-11-13 00:00:00.000000000 Z
|
|
11
11
|
dependencies: []
|
|
12
12
|
description: |2
|
|
13
13
|
MetaRecord is a code generator that allows you to define your application
|
|
@@ -58,7 +58,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
|
|
|
58
58
|
requirements:
|
|
59
59
|
- - ">="
|
|
60
60
|
- !ruby/object:Gem::Version
|
|
61
|
-
version:
|
|
61
|
+
version: 2.5.0
|
|
62
62
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
|
63
63
|
requirements:
|
|
64
64
|
- - ">="
|