Class: AureliaGenerator
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, prepare, #ptr_type, #should_generate_for, #should_generate_from_manifest, #should_skip_on_client?, sourcefile_to_destfile, #unindent, use, #visibility
Class Method Details
.extension ⇒ Object
132
|
# File 'lib/metarecord/generators/aurelia_generator.rb', line 132
def extension ; ".js" ; end
|
.is_file_based? ⇒ Boolean
134
|
# File 'lib/metarecord/generators/aurelia_generator.rb', line 134
def is_file_based? ; false ; end
|
.make_file(filename, data) ⇒ Object
144
145
146
147
148
|
# File 'lib/metarecord/generators/aurelia_generator.rb', line 144
def make_file filename, data
src = "import {Model} from '#{model_import_path}';\n"
src += "import {Fields} from 'aurelia-metarecord';\n\n"
src + (data[:bodies].join "\n")
end
|
.model_import_path ⇒ Object
136
137
138
139
140
141
142
|
# File 'lib/metarecord/generators/aurelia_generator.rb', line 136
def model_import_path
if defined? METARECORD_AURELIA_MODEL_IMPORT
METARECORD_AURELIA_MODEL_IMPORT
else
"aurelia-metarecord"
end
end
|
Instance Method Details
#cppToJsType(type) ⇒ Object
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
|
# File 'lib/metarecord/generators/aurelia_generator.rb', line 113
def cppToJsType type
case type
when 'std::string' then 'string'
when 'std::time_t' then 'timestamp'
when 'unsigned long' then 'integer'
when 'unsigned short' then 'integer'
when 'unsigned char' then 'integer'
when 'unsigned int' then 'integer'
when 'long' then 'integer'
when 'short' then 'integer'
when 'char' then 'integer'
when 'int' then 'integer'
when 'DataTree' then 'object'
when 'LocaleString' then 'locale-string'
else type
end
end
|
#generate_class(object) ⇒ Object
26
27
28
29
30
31
32
33
34
35
36
37
|
# File 'lib/metarecord/generators/aurelia_generator.rb', line 26
def generate_class object
_append "export class #{@class_name} extends Model {"
@indent += 1
_append "constructor() {"
_append " super();"
_append "}"
@state = :class_scope
self.instance_eval &object[:block]
@indent -= 1
_append "}\n"
end
|
#generate_fields(object) ⇒ Object
39
40
41
42
43
44
45
46
47
48
49
50
|
# File 'lib/metarecord/generators/aurelia_generator.rb', line 39
def generate_fields object
@state = :field_scope
_append "#{@class_name}.fields = ["
@indent += 1
@fields = []
self.instance_eval &object[:block]
@indent -= 1
@src += "\n"
_append "];"
_append "Fields.inject(#{@class_name}.fields);"
_append "#{@class_name}.fields._mapFields();"
end
|
#generate_for(object) ⇒ Object
12
13
14
15
16
17
18
19
|
# File 'lib/metarecord/generators/aurelia_generator.rb', line 12
def generate_for object
reset
@class_name = object[:name] + "Data"
generate_class object
generate_global_scope object
generate_fields object
@src
end
|
#generate_global_scope(object) ⇒ Object
21
22
23
24
|
# File 'lib/metarecord/generators/aurelia_generator.rb', line 21
def generate_global_scope object
@state = :global_scope
self.instance_eval &object[:block]
end
|
#has_many(type, name, options = {}) ⇒ Object
93
94
95
96
97
98
99
100
101
102
103
104
105
|
# File 'lib/metarecord/generators/aurelia_generator.rb', line 93
def has_many type, name, options = {}
return if options[:client] == false
type = type.split("::").last
if @state == :field_scope
@src += ",\n" if @fields.count > 0
@fields << ({
name: "#{get_singular_name name}_ids",
type: "array[#{type}]",
label: name
})
_append @fields.last.to_json, no_line_return: true
end
end
|
#has_one(type, name, options = {}) ⇒ Object
78
79
80
81
82
83
84
85
86
87
88
89
90
91
|
# File 'lib/metarecord/generators/aurelia_generator.rb', line 78
def has_one type, name, options = {}
return if options[:client] == false
type = type.split("::").last
if @state == :field_scope
@src += ",\n" if @fields.count > 0
field = { name: "#{name}_id", type: type, label: name }
if not options[:validate].nil?
field[:required] = options[:validate][:required] unless options[:validate][:required].nil?
end
@fields << field
_append field.to_json, no_line_return: true
end
end
|
#order_by(name) ⇒ Object
52
53
54
55
56
|
# File 'lib/metarecord/generators/aurelia_generator.rb', line 52
def order_by name
if @state == :global_scope
_append "#{@class_name}.defaultOrderBy = \"#{name}\""
end
end
|
#property(type, name, options = {}) ⇒ Object
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
|
# File 'lib/metarecord/generators/aurelia_generator.rb', line 58
def property type, name, options = {}
return if not options[:client].nil? and options[:client][:ignore] == true
if @state == :field_scope
type = cppToJsType type
unless options[:client].nil?
type = options[:client][:type] unless options[:client][:type].nil?
end
@src += ",\n" if @fields.count > 0
field = { name: name, type: type }
field[:default] = options[:default] if not options[:default].nil?
if not options[:validate].nil?
field[:min] = options[:validate][:min] unless options[:validate][:min].nil?
field[:max] = options[:validate][:max] unless options[:validate][:max].nil?
field[:required] = options[:validate][:required] unless options[:validate][:required].nil?
end
@fields << field
_append field.to_json, no_line_return: true
end
end
|
#reset ⇒ Object
5
6
7
8
9
10
|
# File 'lib/metarecord/generators/aurelia_generator.rb', line 5
def reset
super
@state = nil
@relations = {}
@fields = []
end
|
#resource_name(name) ⇒ Object
107
108
109
110
111
|
# File 'lib/metarecord/generators/aurelia_generator.rb', line 107
def resource_name name
if @state == :global_scope
_append "#{@class_name}.scope = \"#{name}\";"
end
end
|