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.4.2 lib/generators/effective/migration_generator.rb
effective_developer-0.4.1 lib/generators/effective/migration_generator.rb