Sha256: 659982ebe65fa906633f26731365e2b310cc2036c00ca35c0a82dac58d8d0b98

Contents?: true

Size: 1.14 KB

Versions: 7

Compression:

Stored size: 1.14 KB

Contents

# -*- encoding : utf-8 -*-
require 'rails/generators/active_record'

class CardMigrationGenerator < ActiveRecord::Generators::Base
  source_root File.expand_path('../templates', __FILE__)
  
  class_option 'core', :type => :boolean, aliases: '-c', :default => false, :group => :runtime, 
    desc: "Create card migration for wagn core"

  def create_migration_file
    migration_type = options['core'] ? :core_cards : :deck_cards
    root = Wagn::Migration.paths(migration_type).first
    set_local_assigns!
    migration_template @migration_template, File.join( root, "#{file_name}.rb")
  end
  
  protected
  
  # sets the default migration template that is being used for the generation of the migration
  # depending on the arguments which would be sent out in the command line, the migration template 
  # and the table name instance variables are setup.

  def set_local_assigns!
    @migration_template = "card_migration.erb"
    @migration_parent_class = options['core'] ? 'Wagn::CoreMigration' : 'Wagn::Migration'
    case file_name
    when /^(import)_(.*)(?:\.json)?/
      @migration_action = $1
      @json_filename    = "#{$2}.json"
    end
  end
end

Version data entries

7 entries across 7 versions & 1 rubygems

Version Path
wagn-1.14.7 lib/card/generators/card_migration/card_migration_generator.rb
wagn-1.14.6 lib/card/generators/card_migration/card_migration_generator.rb
wagn-1.14.5 lib/card/generators/card_migration/card_migration_generator.rb
wagn-1.14.4 lib/card/generators/card_migration/card_migration_generator.rb
wagn-1.14.3 lib/card/generators/card_migration/card_migration_generator.rb
wagn-1.14.2 lib/card/generators/card_migration/card_migration_generator.rb
wagn-1.14.1 lib/card/generators/card_migration/card_migration_generator.rb