Sha256: 583a95ec32414f5d1a643ad9c95c74c3d5798e60cbb61fb51049d1f1925ef161
Contents?: true
Size: 1.36 KB
Versions: 4
Compression:
Stored size: 1.36 KB
Contents
module Para class OrderableGenerator < Rails::Generators::NamedBase include Rails::Generators::Migration source_root File.expand_path('../templates', __FILE__) class_option :migrate, type: :boolean, default: false, :aliases => "-m" desc 'Para orderable model updater' def welcome say "Making #{ class_name } model orderable ..." end def add_field_to_model migration_template( 'orderable_migration.rb', "db/migrate/add_orderable_position_to_#{ plural_file_name }.rb" ) end def add_orderable_to_model class_definition = "class #{ class_name } < ActiveRecord::Base\n" inject_into_file "app/models/#{ file_name }.rb", after: class_definition do " acts_as_orderable\n" end end def migrate rake 'db:migrate' if options[:migrate] end def fianl_message message = "The #{ class_name } model is now orderable.\n" message << "* Please migrate to update your model's table\n" unless options[:migrate] message << <<-MESSAGE * Please add to your model resource's routes the ordering path. e.g.: resources :#{ plural_file_name } do collection do patch 'order' end end MESSAGE say(message) end def self.next_migration_number(dir) Time.now.utc.strftime("%Y%m%d%H%M%S") end end end
Version data entries
4 entries across 4 versions & 1 rubygems