Sha256: 82ba15fa8734a3f7a6696296ab532c9867fd235f11a440498b09f26796f7e6e9

Contents?: true

Size: 1.42 KB

Versions: 17

Compression:

Stored size: 1.42 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.written_attributes.present?
          Rails::Generators.invoke('migration', ["create_#{plural_name}"] + invokable(resource.belong_tos_attributes) + (invokable(resource.written_attributes) | timestamps))
        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

17 entries across 17 versions & 1 rubygems

Version Path
effective_developer-0.3.0 lib/generators/effective/migration_generator.rb
effective_developer-0.2.14 lib/generators/effective/migration_generator.rb
effective_developer-0.2.13 lib/generators/effective/migration_generator.rb
effective_developer-0.2.12 lib/generators/effective/migration_generator.rb
effective_developer-0.2.11 lib/generators/effective/migration_generator.rb
effective_developer-0.2.10 lib/generators/effective/migration_generator.rb
effective_developer-0.2.9 lib/generators/effective/migration_generator.rb
effective_developer-0.2.8 lib/generators/effective/migration_generator.rb
effective_developer-0.2.7 lib/generators/effective/migration_generator.rb
effective_developer-0.2.6 lib/generators/effective/migration_generator.rb
effective_developer-0.2.5 lib/generators/effective/migration_generator.rb
effective_developer-0.2.4 lib/generators/effective/migration_generator.rb
effective_developer-0.2.3 lib/generators/effective/migration_generator.rb
effective_developer-0.2.2 lib/generators/effective/migration_generator.rb
effective_developer-0.2.1 lib/generators/effective/migration_generator.rb
effective_developer-0.2 lib/generators/effective/migration_generator.rb
effective_developer-0.1.1 lib/generators/effective/migration_generator.rb