Sha256: dbe86c8e201bf9f589f8b9b57c3f743e73ecbe4f0ebd93c4215dae42209bcfd1

Contents?: true

Size: 1.16 KB

Versions: 52

Compression:

Stored size: 1.16 KB

Contents

module Para
  class OrderableGenerator < Para::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_#{ table_name }.rb"
      )
    end

    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

    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]

      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

52 entries across 52 versions & 1 rubygems

Version Path
para-0.8.12 lib/generators/para/orderable/orderable_generator.rb
para-0.8.11 lib/generators/para/orderable/orderable_generator.rb
para-0.8.10 lib/generators/para/orderable/orderable_generator.rb
para-0.8.9 lib/generators/para/orderable/orderable_generator.rb
para-0.8.8 lib/generators/para/orderable/orderable_generator.rb
para-0.8.7 lib/generators/para/orderable/orderable_generator.rb
para-0.8.5 lib/generators/para/orderable/orderable_generator.rb
para-0.8.3.3 lib/generators/para/orderable/orderable_generator.rb
para-0.8.3.2 lib/generators/para/orderable/orderable_generator.rb
para-0.8.3.1 lib/generators/para/orderable/orderable_generator.rb
para-0.8.3 lib/generators/para/orderable/orderable_generator.rb
para-0.8.2.3 lib/generators/para/orderable/orderable_generator.rb
para-0.8.2.2 lib/generators/para/orderable/orderable_generator.rb
para-0.8.2.1 lib/generators/para/orderable/orderable_generator.rb
para-0.8.2 lib/generators/para/orderable/orderable_generator.rb
para-0.8.1 lib/generators/para/orderable/orderable_generator.rb
para-0.8.0 lib/generators/para/orderable/orderable_generator.rb
para-0.7.4.p1 lib/generators/para/orderable/orderable_generator.rb
para-0.7.4 lib/generators/para/orderable/orderable_generator.rb
para-0.7.3.p6 lib/generators/para/orderable/orderable_generator.rb