Sha256: 33936a4587bc9990a2e54da6d9f7bccec69b5f859d57b16aac20f9e0c96fe011

Contents?: true

Size: 1.35 KB

Versions: 1

Compression:

Stored size: 1.35 KB

Contents

module SocialFramework
  module Generators
    # Generator to add migrations in the application
    class InstallMigrationsGenerator < Rails::Generators::Base
      class_option :migrations, aliases: "-m", type: :array,
        desc: "Select specific migrations to generate (edges, users, schedules, events, events_schedules)"

      source_root File.expand_path('../../../db/migrate', __FILE__)

      desc "Install migrations to application"

      # Copy the migrations to application
      # 
      # Without '-m' option copy all migrations,
      # With '-m' option copy specifics migrations.
      def add_migrations
      	migrations = Dir.glob(SocialFramework::Engine.config.paths["db/migrate"].first + "/*")

        if options[:migrations]
          options[:migrations].each do |migrate|
            file = "social_framework_#{migrate.pluralize}.rb"
            file = migrations.select { |m| m.include?(file) }.first
            unless file.nil? or file.empty?
              file_name = file.split("/").last
              copy_file file, "db/migrate/#{file_name}"
            else
              puts "Could not find migration: '#{migrate}'"
            end
          end
        else
          migrations.each do |migrate|
            file = migrate.split("/").last 
            copy_file migrate, "db/migrate/#{file}"
          end
        end
      end
    end
  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
social_framework-0.0.2 lib/generators/social_framework/install_migrations_generator.rb