Redmine 4.1.1

This commit is contained in:
Manuel Cillero 2020-11-22 21:20:06 +01:00
parent 33e7b881a5
commit 3d976f1b3b
1593 changed files with 36180 additions and 19489 deletions

View file

@ -2,4 +2,4 @@ Description:
Generates a plugin model.
Examples:
./script/rails generate redmine_plugin_model meetings pool
bundle exec rails generate redmine_plugin_model meetings pool

View file

@ -1,9 +1,28 @@
# frozen_string_literal: true
# Redmine - project management software
# Copyright (C) 2006-2019 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.
class RedminePluginModelGenerator < Rails::Generators::NamedBase
source_root File.expand_path("../templates", __FILE__)
argument :model, :type => :string
argument :attributes, :type => :array, :default => [], :banner => "field[:type][:index] field[:type][:index]"
class_option :migration, :type => :boolean
class_option :migration, :type => :boolean, :default => true
class_option :timestamps, :type => :boolean
class_option :parent, :type => :string, :desc => "The parent class for the generated model"
class_option :indexes, :type => :boolean, :default => true, :desc => "Add indexes for references and belongs_to columns"
@ -24,11 +43,14 @@ class RedminePluginModelGenerator < Rails::Generators::NamedBase
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"
migration_filename = "%03i_#{@migration_filename}.rb" % (migration_number + 1)
return unless options[:migration]
migration_filename = "%.14d_#{@migration_filename}.rb" % migration_number
template "migration.rb", "#{plugin_path}/db/migrate/#{migration_filename}"
end
private
def attributes_with_index
attributes.select { |a| a.has_index? || (a.reference? && options[:indexes]) }
end
@ -37,5 +59,11 @@ class RedminePluginModelGenerator < Rails::Generators::NamedBase
current = Dir.glob("#{plugin_path}/db/migrate/*.rb").map do |file|
File.basename(file).split("_").first.to_i
end.max.to_i
[current + 1, Time.now.utc.strftime("%Y%m%d%H%M%S").to_i].max
end
def parent_class_name
options[:parent] || "ActiveRecord::Base"
end
end

View file

@ -1,4 +1,4 @@
class <%= @migration_class_name %> < ActiveRecord::Migration
class <%= @migration_class_name %> < ActiveRecord::Migration[<%= ActiveRecord::Migration.current_version %>]
def change
create_table :<%= @table_name %> do |t|
<% attributes.each do |attribute| -%>

View file

@ -1,2 +1,2 @@
class <%= @model_class %> < ActiveRecord::Base
class <%= @model_class %> < <%= parent_class_name.classify %>
end