Sha256: c7134dbbaa03054e70c7629dbbc0efa49fb21374ac9497254eea18ddc33f209f

Contents?: true

Size: 1.33 KB

Versions: 17

Compression:

Stored size: 1.33 KB

Contents

# -*- encoding : utf-8 -*-

require 'generators/card'

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

      def create_migration_file
        migration_type = options['core'] ? :core_cards : :deck_cards
        mig_paths = Cardio.migration_paths(migration_type)
        raise "No migration directory for #{migration_type}" if mig_paths.blank?
        set_local_assigns!
        migration_template @migration_template, File.join( mig_paths.first, "#{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'] ? 'Card::CoreMigration' : 'Card::Migration'
        case file_name
        when /^(import)_(.*)(?:\.json)?/
          @migration_action = $1
          @json_filename    = "#{$2}.json"
        end
      end
    end
  end
end

Version data entries

17 entries across 17 versions & 1 rubygems

Version Path
card-1.16.6 lib/generators/card/migration/migration_generator.rb
card-1.16.5 lib/generators/card/migration/migration_generator.rb
card-1.16.4 lib/generators/card/migration/migration_generator.rb
card-1.16.3 lib/generators/card/migration/migration_generator.rb
card-1.16.2 lib/generators/card/migration/migration_generator.rb
card-1.16.1 lib/generators/card/migration/migration_generator.rb
card-1.16.0 lib/generators/card/migration/migration_generator.rb
card-1.15.7 lib/generators/card/migration/migration_generator.rb
card-1.15.6 lib/generators/card/migration/migration_generator.rb
card-1.15.5 lib/generators/card/migration/migration_generator.rb
card-1.15.4 lib/generators/card/migration/migration_generator.rb
card-1.15.3 lib/generators/card/migration/migration_generator.rb
card-1.15.2 lib/generators/card/migration/migration_generator.rb
card-1.15.1 lib/generators/card/migration/migration_generator.rb
card-1.15.0 lib/generators/card/migration/migration_generator.rb
card-1.15.pre2 lib/generators/card/migration/migration_generator.rb
card-1.15.pre lib/generators/card/migration/migration_generator.rb