Index: lib/generators/redmine_plugin_model/templates/model.rb.erb IDEA additional info: Subsystem: com.intellij.openapi.diff.impl.patch.CharsetEP <+>UTF-8 =================================================================== --- lib/generators/redmine_plugin_model/templates/model.rb.erb (date 1511795734000) +++ lib/generators/redmine_plugin_model/templates/model.rb.erb (revision ) @@ -1,3 +1,3 @@ -class <%= @model_class %> < ActiveRecord::Base +class <%= @model_class %> < <%= parent_class_name.classify %> unloadable end Index: lib/generators/redmine_plugin_model/redmine_plugin_model_generator.rb IDEA additional info: Subsystem: com.intellij.openapi.diff.impl.patch.CharsetEP <+>UTF-8 =================================================================== --- lib/generators/redmine_plugin_model/redmine_plugin_model_generator.rb (date 1511795734000) +++ lib/generators/redmine_plugin_model/redmine_plugin_model_generator.rb (revision ) @@ -1,12 +1,12 @@ 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" + 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 @@ -24,18 +24,27 @@ 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]) } + 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 + + [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