Class: RedminePluginModelGenerator
- Inherits:
-
Rails::Generators::NamedBase
- Object
- Rails::Generators::NamedBase
- RedminePluginModelGenerator
- Defined in:
- lib/generators/redmine_plugin_model/redmine_plugin_model_generator.rb
Overview
Instance Attribute Summary collapse
-
#plugin_name ⇒ Object
readonly
Returns the value of attribute plugin_name.
-
#plugin_path ⇒ Object
readonly
Returns the value of attribute plugin_path.
-
#plugin_pretty_name ⇒ Object
readonly
Returns the value of attribute plugin_pretty_name.
Instance Method Summary collapse
- #attributes_with_index ⇒ Object
- #copy_templates ⇒ Object
-
#initialize(*args) ⇒ RedminePluginModelGenerator
constructor
A new instance of RedminePluginModelGenerator.
- #migration_number ⇒ Object
Constructor Details
#initialize(*args) ⇒ RedminePluginModelGenerator
Returns a new instance of RedminePluginModelGenerator
13 14 15 16 17 18 19 20 21 22 |
# File 'lib/generators/redmine_plugin_model/redmine_plugin_model_generator.rb', line 13 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_name ⇒ Object (readonly)
Returns the value of attribute plugin_name
11 12 13 |
# File 'lib/generators/redmine_plugin_model/redmine_plugin_model_generator.rb', line 11 def plugin_name @plugin_name end |
#plugin_path ⇒ Object (readonly)
Returns the value of attribute plugin_path
11 12 13 |
# File 'lib/generators/redmine_plugin_model/redmine_plugin_model_generator.rb', line 11 def plugin_path @plugin_path end |
#plugin_pretty_name ⇒ Object (readonly)
Returns the value of attribute plugin_pretty_name
11 12 13 |
# File 'lib/generators/redmine_plugin_model/redmine_plugin_model_generator.rb', line 11 def plugin_pretty_name @plugin_pretty_name end |
Instance Method Details
#attributes_with_index ⇒ Object
32 33 34 |
# File 'lib/generators/redmine_plugin_model/redmine_plugin_model_generator.rb', line 32 def attributes_with_index attributes.select { |a| a.has_index? || (a.reference? && [:indexes]) } end |
#copy_templates ⇒ Object
24 25 26 27 28 29 30 |
# File 'lib/generators/redmine_plugin_model/redmine_plugin_model_generator.rb', line 24 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 |
#migration_number ⇒ Object
36 37 38 39 40 |
# File 'lib/generators/redmine_plugin_model/redmine_plugin_model_generator.rb', line 36 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 |