Class: Resty::Generators::ScaffoldGenerator

Inherits:
Base
  • Object
show all
Includes:
Rails::Generators::ResourceHelpers
Defined in:
lib/generators/resty/scaffold/scaffold_generator.rb

Instance Method Summary collapse

Instance Method Details

#actionsObject



132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
# File 'lib/generators/resty/scaffold/scaffold_generator.rb', line 132

def actions
  @actions ||= 
    begin
      keys = action_map.keys
      if options[:singleton]
        keys.delete('index')
        keys.delete('create')
        keys.delete('destroy')
      end
      if options[:read_only]
        keys.delete('update')
        keys.delete('create')
        keys.delete('destroy')
      end
      keys
    end
end

#add_to_activity_factoryObject



57
58
59
60
61
62
63
64
65
66
67
68
69
# File 'lib/generators/resty/scaffold/scaffold_generator.rb', line 57

def add_to_activity_factory
  factory_file = File.join(java_root, managed_package.gsub(/\./, "/"), class_path, "ActivityFactory.java")
  if File.exists?(factory_file)
    factory = File.read(factory_file)
    if factory =~ /@Named\(.#{table_name}.\)/
      log 'keep', factory_file
    else
      factory.sub! /interface\s+ActivityFactory\s+\{/, "interface ActivityFactory {\n    @Named(\"#{table_name}\") Activity create(#{places_package}.#{class_name}Place place);"
      File.open(factory_file, 'w') { |f| f.print factory }
      log "added to", factory_file
    end
  end
end

#add_to_menu_panelObject



87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
# File 'lib/generators/resty/scaffold/scaffold_generator.rb', line 87

def add_to_menu_panel
  file = File.join(java_root, managed_package.gsub(/\./, "/"), class_path, "#{application_name}MenuPanel.java")
  if File.exists?(file)
    content = File.read(file)
    if content =~ /#{class_name}Place\(/
      log 'keep', file
    else
      # TODO non session case !!!
      t_name = options[:singleton] ? singular_table_name : table_name
      content.sub! /super\(\s*sessionManager\s*,\s*placeController\s*\)\s*;/, "super(sessionManager, placeController);\n        addButton(\"#{t_name.underscore.humanize}\", new #{places_package}.#{class_name}Place(#{options[:singleton] ? 'SHOW' : 'INDEX'}));"
      content.sub! /super\(\s*placeController\s*\)\s*;/, "super(placeController);\n        addButton(\"#{t_name.underscore.humanize}\", new #{places_package}.#{class_name}Place(#{options[:singleton] ? 'SHOW' : 'INDEX'}));"
      File.open(file, 'w') { |f| f.print content }
      log "added to", file
    end
  end
end

#add_to_moduleObject



104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
# File 'lib/generators/resty/scaffold/scaffold_generator.rb', line 104

def add_to_module
  file = File.join(java_root, managed_package.gsub(/\./, "/"), class_path, "#{application_name}Module.java")
  if File.exists?(file)
    content = File.read(file)
    if content =~ /#{class_name.pluralize}RestService.class/
      log 'keep', file
    else content =~ /super.configure\(\);/
      content.sub! /super.configure\(\);/, "super.configure();\n        bind(#{restservices_package}.#{class_name.pluralize}RestService.class).toProvider(#{class_name.pluralize}RestServiceProvider.class);"

      content.sub! /new GinFactoryModuleBuilder\(\)/, "new GinFactoryModuleBuilder()\n            .implement(Activity.class, Names.named(\"#{table_name}\"), #{activities_package}.#{class_name}Activity.class)"

      content.sub! /^\}/, <<-EOF

    @Singleton
    public static class #{class_name.pluralize}RestServiceProvider implements Provider<#{restservices_package}.#{class_name.pluralize}RestService> {
  private final #{restservices_package}.#{class_name.pluralize}RestService service = GWT.create(#{restservices_package}.#{class_name.pluralize}RestService.class);
  public #{restservices_package}.#{class_name.pluralize}RestService get() {
      return service;
  }
    }
}
EOF
      File.open(file, 'w') { |f| f.print content }
      log "added to", file
    end
  end
end

#add_to_place_histroy_mapperObject



71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
# File 'lib/generators/resty/scaffold/scaffold_generator.rb', line 71

def add_to_place_histroy_mapper
  file = File.join(java_root, managed_package.gsub(/\./, "/"), class_path, "#{application_name}PlaceHistoryMapper.java")
  if File.exists?(file)
    content = File.read(file)
    if content =~ /#{class_name}PlaceTokenizer/
      log 'keep', file
    else
      content.sub! /public\s+#{application_name}PlaceHistoryMapper.(.*).\s*\{/ do |m|
        "public #{application_name}PlaceHistoryMapper(#{$1}){\n        register(\"#{table_name}\", new #{places_package}.#{class_name}PlaceTokenizer());"
end
      File.open(file, 'w') { |f| f.print content }
      log "added to", file
    end
  end
end

#create_activity_fileObject



53
54
55
# File 'lib/generators/resty/scaffold/scaffold_generator.rb', line 53

def create_activity_file
  template 'Activity.java', File.join(java_root, activities_package.gsub(/\./, "/"), class_path, "#{class_name}Activity.java")
end

#create_cache_fileObject



22
23
24
25
26
# File 'lib/generators/resty/scaffold/scaffold_generator.rb', line 22

def create_cache_file
  if !options[:singleton] && !options[:read_only]
    template 'Cache.java', File.join(java_root, caches_package.gsub(/\./, "/"), class_path, "#{class_name.pluralize}Cache.java")
  end
end

#create_editor_filesObject



43
44
45
46
# File 'lib/generators/resty/scaffold/scaffold_generator.rb', line 43

def create_editor_files
  template 'Editor.java', File.join(java_root, editors_package.gsub(/\./, "/"), class_path, "#{class_name}Editor.java")
  template 'Editor.ui.xml', File.join(java_root, editors_package.gsub(/\./, "/"), class_path, "#{class_name}Editor.ui.xml")
end

#create_event_filesObject



28
29
30
31
# File 'lib/generators/resty/scaffold/scaffold_generator.rb', line 28

def create_event_files
  template 'Event.java', File.join(java_root, events_package.gsub(/\./, "/"), class_path, "#{class_name}Event.java")
  template 'EventHandler.java', File.join(java_root, events_package.gsub(/\./, "/"), class_path, "#{class_name}EventHandler.java")
end

#create_model_fileObject



18
19
20
# File 'lib/generators/resty/scaffold/scaffold_generator.rb', line 18

def create_model_file
  template 'Model.java', File.join(java_root, models_package.gsub(/\./, "/"), class_path, "#{class_name}.java")
end

#create_place_filesObject



48
49
50
51
# File 'lib/generators/resty/scaffold/scaffold_generator.rb', line 48

def create_place_files
  template 'Place.java', File.join(java_root, places_package.gsub(/\./, "/"), class_path, "#{class_name}Place.java")
  template 'PlaceTokenizer.java', File.join(java_root, places_package.gsub(/\./, "/"), class_path, "#{class_name}PlaceTokenizer.java")
end

#create_rest_service_fileObject



33
34
35
# File 'lib/generators/resty/scaffold/scaffold_generator.rb', line 33

def create_rest_service_file
  template 'RestService.java', File.join(java_root, restservices_package.gsub(/\./, "/"), class_path, "#{controller_class_name}RestService.java")
end

#create_view_filesObject



37
38
39
40
41
# File 'lib/generators/resty/scaffold/scaffold_generator.rb', line 37

def create_view_files
  template 'View.java', File.join(java_root, views_package.gsub(/\./, "/"), class_path, "#{class_name}View.java")
  template 'View.ui.xml', File.join(java_root, views_package.gsub(/\./, "/"), class_path, "#{class_name}View.ui.xml")
  template 'ViewImpl.java', File.join(java_root, views_package.gsub(/\./, "/"), class_path, "#{class_name}ViewImpl.java")
end