Redmine 3.4.4
This commit is contained in:
commit
64924a6376
2112 changed files with 259028 additions and 0 deletions
5
lib/generators/redmine_plugin_model/USAGE
Normal file
5
lib/generators/redmine_plugin_model/USAGE
Normal file
|
@ -0,0 +1,5 @@
|
|||
Description:
|
||||
Generates a plugin model.
|
||||
|
||||
Examples:
|
||||
./script/rails generate redmine_plugin_model meetings pool
|
|
@ -0,0 +1,41 @@
|
|||
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 :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"
|
||||
|
||||
attr_reader :plugin_path, :plugin_name, :plugin_pretty_name
|
||||
|
||||
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
|
||||
|
||||
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)
|
||||
template "migration.rb", "#{plugin_path}/db/migrate/#{migration_filename}"
|
||||
end
|
||||
|
||||
def attributes_with_index
|
||||
attributes.select { |a| a.has_index? || (a.reference? && options[:indexes]) }
|
||||
end
|
||||
|
||||
def migration_number
|
||||
current = Dir.glob("#{plugin_path}/db/migrate/*.rb").map do |file|
|
||||
File.basename(file).split("_").first.to_i
|
||||
end.max.to_i
|
||||
end
|
||||
end
|
15
lib/generators/redmine_plugin_model/templates/migration.rb
Normal file
15
lib/generators/redmine_plugin_model/templates/migration.rb
Normal file
|
@ -0,0 +1,15 @@
|
|||
class <%= @migration_class_name %> < ActiveRecord::Migration
|
||||
def change
|
||||
create_table :<%= @table_name %> do |t|
|
||||
<% attributes.each do |attribute| -%>
|
||||
t.<%= attribute.type %> :<%= attribute.name %><%= attribute.inject_options %>
|
||||
<% end -%>
|
||||
<% if options[:timestamps] %>
|
||||
t.timestamps
|
||||
<% end -%>
|
||||
end
|
||||
<% attributes_with_index.each do |attribute| -%>
|
||||
add_index :<%= table_name %>, :<%= attribute.index_name %><%= attribute.inject_index_options %>
|
||||
<% end -%>
|
||||
end
|
||||
end
|
|
@ -0,0 +1,2 @@
|
|||
class <%= @model_class %> < ActiveRecord::Base
|
||||
end
|
|
@ -0,0 +1,9 @@
|
|||
require File.expand_path('../../test_helper', __FILE__)
|
||||
|
||||
class <%= @model_class %>Test < ActiveSupport::TestCase
|
||||
|
||||
# Replace this with your real tests.
|
||||
def test_truth
|
||||
assert true
|
||||
end
|
||||
end
|
Loading…
Add table
Add a link
Reference in a new issue