Sha256: 7a270cec5f1e135bb372950bb955b9431ae877e9a8dd3d2f9b1d9d72f7754d19

Contents?: true

Size: 1.59 KB

Versions: 1

Compression:

Stored size: 1.59 KB

Contents

###########################################

require 'rails/generators/active_record'
require 'exception_handler/exception' # => ATTRS constant (for attributes)

###########################################

# => Migration Generator (for adding errors table)
# => Ref: https://github.com/plataformatec/devise/blob/master/lib/generators/active_record/devise_generator.rb

module ExceptionHandler
  class MigrationGenerator < ActiveRecord::Generators::Base

    # => Name - from http://old.thoughtsincomputation.com/posts/cgfr3-part-3-adding-a-generator
    argument :name, default: "migration"

    # => Source of Migrations
    source_root File.expand_path("../../templates", __FILE__)

    ###########################################

    # => Table Name - false = off, true = errors, value = value
    # => Always outputs string for some reason...
    def table_name
      ExceptionHandler.config.db
    end

    ###########################################

    # => Create
    def create_errors_migration
      migration_template "migration.rb.erb", "db/migrate/create_#{table_name.to_s.gsub("_","")}.rb", migration_version: migration_version
    end

    ###########################################

    # => From Devise
    # => https://github.com/plataformatec/devise/blob/master/lib/generators/active_record/devise_generator.rb#L81

    # => Rails 5?
    def rails5?
      Rails.version.start_with? '5'
    end

    # => Migration Version
    def migration_version
      if rails5?
        "[#{Rails::VERSION::MAJOR}.#{Rails::VERSION::MINOR}]"
      end
    end

    ###########################################

  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
exception_handler-0.7.0 lib/generators/exception_handler/migration_generator.rb