Class: CometDataGenerator

Inherits:
CrailsDataGenerator show all
Defined in:
lib/metarecord/generators/comet/data_generator.rb

Instance Attribute Summary

Attributes inherited from CrailsDataGenerator

#forward_declarations

Class Method Summary collapse

Instance Method Summary collapse

Methods inherited from CrailsDataGenerator

#_append, #_append_macro, #_id_based_has_many, #_join_based_has_many, #datatree_property, extension, #generate_for, #get_headers, #has_many, #has_one, make_file, #make_pragma_db, #order_by, #property, #render, #reset, #visibility, #with_visibility

Methods inherited from GeneratorBase

#_append, _use_by_files, _use_by_models, #get_classname, #get_pluralized_name, #get_singular_name, #get_type, #get_value, #has_many, #has_one, #id_type, #indent, is_file_based?, #make_block, #null_id, #order_by, prepare, #property, #ptr_type, #reset, #should_generate_for, #should_generate_from_manifest, #should_skip_on_client?, sourcefile_to_destfile, #unindent, use, #visibility

Class Method Details

.client_defineObject



57
58
59
# File 'lib/metarecord/generators/comet/data_generator.rb', line 57

def client_define
  "__COMET_CLIENT__"
end

.client_super_classObject



61
62
63
# File 'lib/metarecord/generators/comet/data_generator.rb', line 61

def client_super_class
  "MODELS_CLIENT_SUPER_CLASS"
end

.generate_includesObject



65
66
67
68
69
70
71
72
73
74
75
76
77
# File 'lib/metarecord/generators/comet/data_generator.rb', line 65

def generate_includes
<<CPP
#{super}
#ifdef #{client_define}
# include <comet/mvc/model.hpp>
# include <comet/mvc/archive_model.hpp>
# include <comet/promise.hpp>
# ifndef #{client_super_class}
#  define #{client_super_class} Comet::JsonModel<>
# endif
#endif
CPP
end

Instance Method Details

#edit_resource_declarationObject



18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
# File 'lib/metarecord/generators/comet/data_generator.rb', line 18

def edit_resource_declaration
  with_visibility :protected do
    _append_macro "#ifdef #{self.class.client_define}"
    _append "#{id_type} id = #{null_id};"
    _append_macro "#endif"
  end
  _append_macro "#ifdef #{self.class.client_define}"
  _append "#{id_type} get_id() const { return id; }"
  _append "void         set_id(#{id_type} value) { id = value; }"
  _append "void         from_json(Data data);"
  _append "virtual std::vector<std::string> find_missing_parameters(Data) const;"
  _append "virtual void                     edit(Data);"
  _append "virtual void                     merge_data(Data) const;"
  _append "virtual std::string              to_json() const;"
  _append "virtual bool                     is_valid();"
  _append_macro "#else"
  super
  _append_macro "#endif"
  _append ""
end

#generate_class_head(object) ⇒ Object



4
5
6
7
8
9
10
# File 'lib/metarecord/generators/comet/data_generator.rb', line 4

def generate_class_head object
  _append_macro "#ifndef #{self.class.client_define}"
  super object
  _append_macro "#else"
  _append "struct #{object[:name]} : public #{self.class.client_super_class}"
  _append_macro "#endif"
end

#has_many_fetch(list_type, name, options) ⇒ Object



46
47
48
49
50
51
52
53
54
# File 'lib/metarecord/generators/comet/data_generator.rb', line 46

def has_many_fetch list_type, name, options
  with_visibility :public do
    _append_macro "#ifdef #{self.class.client_define}"
    _append "Comet::Promise fetch_#{name}();"
    _append_macro "#else"
    _append "void fetch_#{name}();"
    _append_macro "#endif"
  end
end

#prepare_order_byObject



12
13
14
15
16
# File 'lib/metarecord/generators/comet/data_generator.rb', line 12

def prepare_order_by
  _append_macro "#ifndef #{self.class.client_define}"
  super
  _append_macro "#endif"
end

#resource_name(name) ⇒ Object



39
40
41
42
43
44
# File 'lib/metarecord/generators/comet/data_generator.rb', line 39

def resource_name name
  super name
  _append_macro "#ifdef #{self.class.client_define}"
  _append "std::string get_resource_name() const { return scope; }"
  _append_macro "#endif"
end