Sha256: 2606b603fc93161dc1cd905e4fd1316c6103099f0becbde3b06bee781249b9cc

Contents?: true

Size: 1.36 KB

Versions: 22

Compression:

Stored size: 1.36 KB

Contents

# rails generate effective:migration NAME [field[:type] field[:type]] [options]

# TODO - add default options

# Generates a create_* migration
# rails generate effective:migration Thing
# rails generate effective:migration Thing name:string description:text

module Effective
  module Generators
    class MigrationGenerator < Rails::Generators::NamedBase
      include Helpers

      source_root File.expand_path(('../' * 4) + 'lib/scaffolds', __FILE__)

      desc 'Creates a migration.'

      argument :attributes, type: :array, default: [], banner: 'field[:type] field[:type]'

      def invoke_migration
        say_status :invoke, :migration, :white
      end

      def create_migration
        if invoked_attributes.present?
          Rails::Generators.invoke('migration', ["create_#{plural_name}"] + (invokable(invoked_attributes) | timestamps))
        elsif resource.klass_attributes.present?
          raise 'klass_attributes already exist.  We cant migrate (yet). Exiting.'
        elsif resource.model_attributes.present?
          Rails::Generators.invoke('migration', ["create_#{plural_name}"] + invokable(resource.model_attributes))
        else
          raise 'You need to specify some attributes or have a model file present'
        end
      end

      protected

      def timestamps
        ['created_at:datetime', 'updated_at:datetime']
      end

    end
  end
end

Version data entries

22 entries across 22 versions & 1 rubygems

Version Path
effective_developer-0.5.5 lib/generators/effective/migration_generator.rb
effective_developer-0.5.4 lib/generators/effective/migration_generator.rb
effective_developer-0.5.3 lib/generators/effective/migration_generator.rb
effective_developer-0.5.2 lib/generators/effective/migration_generator.rb
effective_developer-0.5.1 lib/generators/effective/migration_generator.rb
effective_developer-0.5.0 lib/generators/effective/migration_generator.rb
effective_developer-0.4.16 lib/generators/effective/migration_generator.rb
effective_developer-0.4.15 lib/generators/effective/migration_generator.rb
effective_developer-0.4.14 lib/generators/effective/migration_generator.rb
effective_developer-0.4.13 lib/generators/effective/migration_generator.rb
effective_developer-0.4.12 lib/generators/effective/migration_generator.rb
effective_developer-0.4.11 lib/generators/effective/migration_generator.rb
effective_developer-0.4.10 lib/generators/effective/migration_generator.rb
effective_developer-0.4.9 lib/generators/effective/migration_generator.rb
effective_developer-0.4.8 lib/generators/effective/migration_generator.rb
effective_developer-0.4.7 lib/generators/effective/migration_generator.rb
effective_developer-0.4.6 lib/generators/effective/migration_generator.rb
effective_developer-0.4.5 lib/generators/effective/migration_generator.rb
effective_developer-0.4.4 lib/generators/effective/migration_generator.rb
effective_developer-0.4.3 lib/generators/effective/migration_generator.rb