Class: RedminePluginModelGenerator

Inherits:
Rails::Generators::NamedBase
  • Object
show all
Defined in:
lib/generators/redmine_plugin_model/redmine_plugin_model_generator.rb

Overview

Redmine - project management software Copyright © 2006-2022 Jean-Philippe Lang

This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation; either version 2 of the License, or (at your option) any later version.

This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details.

You should have received a copy of the GNU General Public License along with this program; if not, write to the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(*args) ⇒ RedminePluginModelGenerator

Returns a new instance of RedminePluginModelGenerator.



31
32
33
34
35
36
37
38
39
40
# File 'lib/generators/redmine_plugin_model/redmine_plugin_model_generator.rb', line 31

def initialize(*args)
  super
  @plugin_name = file_name.underscore
  @plugin_pretty_name = plugin_name.titleize
  @plugin_path = File.join(Redmine::Plugin.directory, plugin_name)
  @model_class = model.camelize
  @table_name = @model_class.tableize
  @migration_filename = "create_#{@table_name}"
  @migration_class_name = @migration_filename.camelize
end

Instance Attribute Details

#plugin_nameObject (readonly)

Returns the value of attribute plugin_name.



29
30
31
# File 'lib/generators/redmine_plugin_model/redmine_plugin_model_generator.rb', line 29

def plugin_name
  @plugin_name
end

#plugin_pathObject (readonly)

Returns the value of attribute plugin_path.



29
30
31
# File 'lib/generators/redmine_plugin_model/redmine_plugin_model_generator.rb', line 29

def plugin_path
  @plugin_path
end

#plugin_pretty_nameObject (readonly)

Returns the value of attribute plugin_pretty_name.



29
30
31
# File 'lib/generators/redmine_plugin_model/redmine_plugin_model_generator.rb', line 29

def plugin_pretty_name
  @plugin_pretty_name
end

Instance Method Details

#copy_templatesObject



42
43
44
45
46
47
48
49
# File 'lib/generators/redmine_plugin_model/redmine_plugin_model_generator.rb', line 42

def copy_templates
  template 'model.rb.erb', "#{plugin_path}/app/models/#{model.underscore}.rb"
  template 'unit_test.rb.erb', "#{plugin_path}/test/unit/#{model.underscore}_test.rb"
  return unless options[:migration]

  migration_filename = "%.14d_#{@migration_filename}.rb" % migration_number
  template "migration.rb", "#{plugin_path}/db/migrate/#{migration_filename}"
end