Class: CrailsViewGenerator
Class Method Summary
collapse
Instance Method Summary
collapse
#_append, _use_by_files, _use_by_models, #get_classname, #get_pluralized_name, #get_singular_name, #get_type, #get_value, #id_type, #indent, #make_block, #null_id, #order_by, prepare, #ptr_type, #resource_name, #should_generate_from_manifest, #should_skip_on_client?, sourcefile_to_destfile, #unindent, use, #visibility
Class Method Details
.extension ⇒ Object
67
|
# File 'lib/metarecord/generators/crails/view_generator.rb', line 67
def extension ; ".json" ; end
|
.is_file_based? ⇒ Boolean
5
|
# File 'lib/metarecord/generators/crails/view_generator.rb', line 5
def self.is_file_based? ; false ; end
|
.make_file(filename, data) ⇒ Object
69
70
71
72
73
74
75
76
77
78
|
# File 'lib/metarecord/generators/crails/view_generator.rb', line 69
def make_file filename, data
source = ""
source += "#include <crails/odb/helpers.hpp>\n"
source += (collect_includes_for filename).join("\n")
source += "\n" + (data[:headers].join "\n")
source += "\n// END LINKING\n"
source += "\n" + (data[:bodies].join "\n")
source
end
|
Instance Method Details
#generate_for(object) ⇒ Object
17
18
19
20
21
22
23
24
|
# File 'lib/metarecord/generators/crails/view_generator.rb', line 17
def generate_for object
reset
@declarations << "#include \"#{object[:header]}\"\n"
@declarations << "#{object[:classname]}& @model;"
property id_type, "id"
self.instance_eval &object[:block]
@src
end
|
26
27
28
|
# File 'lib/metarecord/generators/crails/view_generator.rb', line 26
def
@declarations.join "\n"
end
|
#has_many(type, name, options = {}) ⇒ Object
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
|
# File 'lib/metarecord/generators/crails/view_generator.rb', line 50
def has_many type, name, options = {}
return if should_skip_on_client? options
_append "{"
@indent += 1
id_attr = (get_singular_name name) + "_ids"
id_collector = if options[:joined] == false
"model.get_#{id_attr}()"
else
"collect_ids_from(model.get_#{name}())"
end
_append "const auto relation_ids = #{id_collector};"
_append "json_array(#{id_attr.inspect}, relation_ids.begin(), relation_ids.end());"
@indent -= 1
_append "}"
end
|
#has_one(type, name, options = {}) ⇒ Object
39
40
41
42
43
44
45
46
47
48
|
# File 'lib/metarecord/generators/crails/view_generator.rb', line 39
def has_one type, name, options = {}
return if should_skip_on_client? options
if options[:joined] == false
_append "if (model.get_#{name}_id() != 0)"
_append " json(\"#{name}_id\", model.get_#{name}_id());"
else
_append "if (model.get_#{name}())"
_append " json(\"#{name}_id\", model.get_#{name}()->get_id());"
end
end
|
#property(type, name, options = {}) ⇒ Object
30
31
32
33
34
35
36
37
|
# File 'lib/metarecord/generators/crails/view_generator.rb', line 30
def property type, name, options = {}
return if should_skip_on_client? options
if type == "DataTree" || type == "LocaleString"
_append "json(#{name.inspect}, model.get_#{name}().as_data());"
else
_append "json(#{name.inspect}, model.get_#{name}());"
end
end
|
#reset ⇒ Object
7
8
9
10
11
|
# File 'lib/metarecord/generators/crails/view_generator.rb', line 7
def reset
@src = ""
@declarations = []
super
end
|
#should_generate_for(object) ⇒ Object
13
14
15
|
# File 'lib/metarecord/generators/crails/view_generator.rb', line 13
def should_generate_for object
(not object[:header].nil?) && (not object[:classname].nil?)
end
|