Class: Para::OrderableGenerator
- Inherits:
-
Generators::NamedBase
- Object
- Generators::NamedBase
- Para::OrderableGenerator
- Includes:
- Rails::Generators::Migration
- Defined in:
- lib/generators/para/orderable/orderable_generator.rb
Class Method Summary collapse
Instance Method Summary collapse
- #add_field_to_model ⇒ Object
- #add_orderable_to_model ⇒ Object
- #fianl_message ⇒ Object
- #migrate ⇒ Object
- #welcome ⇒ Object
Class Method Details
.next_migration_number(dir) ⇒ Object
41 42 43 |
# File 'lib/generators/para/orderable/orderable_generator.rb', line 41 def self.next_migration_number(dir) Time.now.utc.strftime("%Y%m%d%H%M%S") end |
Instance Method Details
#add_field_to_model ⇒ Object
15 16 17 18 19 20 |
# File 'lib/generators/para/orderable/orderable_generator.rb', line 15 def add_field_to_model migration_template( 'orderable_migration.rb', "db/migrate/add_orderable_position_to_#{ table_name }.rb" ) end |
#add_orderable_to_model ⇒ Object
22 23 24 25 26 27 28 |
# File 'lib/generators/para/orderable/orderable_generator.rb', line 22 def add_orderable_to_model class_definition = /class #{ class_name } < (ActiveRecord::Base|ApplicationRecord)\n/ inject_into_file "app/models/#{ singular_namespaced_path }.rb", after: class_definition do " acts_as_orderable\n" end end |
#fianl_message ⇒ Object
34 35 36 37 38 39 |
# File 'lib/generators/para/orderable/orderable_generator.rb', line 34 def = "The #{ class_name } model is now orderable.\n" << "Please migrate to update your model's table\n" unless [:migrate] say() end |
#migrate ⇒ Object
30 31 32 |
# File 'lib/generators/para/orderable/orderable_generator.rb', line 30 def migrate rake 'db:migrate' if [:migrate] end |
#welcome ⇒ Object
11 12 13 |
# File 'lib/generators/para/orderable/orderable_generator.rb', line 11 def welcome say "Making #{ class_name } model orderable ..." end |