Sha256: faabe4efcd31967ccb71cb36de7e9438ff5a658372e5282a72d8f9e707c25d49

Contents?: true

Size: 1.69 KB

Versions: 11

Compression:

Stored size: 1.69 KB

Contents

require 'rails/generators/migration'

module Hicube
  module Generators
    class InstallGenerator < ::Rails::Generators::Base
      include Rails::Generators::Migration

      source_root File.expand_path('../templates', __FILE__)
      desc "add migrations and configurations"

      def self.next_migration_number(path)
        unless @prev_migration_nr
          @prev_migration_nr = Time.now.utc.strftime("%Y%m%d%H%M%S").to_i
        else
          @prev_migration_nr += 1
        end
        @prev_migration_nr.to_s
      end

      def copy_migrations
        copy_migration "generate_hicube_accounts"
        copy_migration "generate_hicube_users"
        copy_migration "generate_hicube_pages"
        # migration_template "generate_hicube_accounts.rb", "db/migrate/generate_hicube_accounts.rb"
        # migration_template "generate_hicube_users.rb", "db/migrate/generate_hicube_users.rb", "--force"
        # migration_template "generate_hicube_pages.rb", "db/migrate/generate_hicube_pages.rb"
        rake "db:migrate"
      end

      def copy_config
        template "sitemap.rb", "config/sitemap.rb"
        append_to_file 'public/robots.txt', "\nSitemap: #{ENV['AWS_ASSET_HOST']}/#{ENV['S3_BUCKET_NAME']}/sitemaps/#{Rails.application.class.to_s.split('::').first}/sitemap.xml.gz"
      end

      # def copy_tasks
      #   template "scheduler.rake", "lib/tasks/scheduler.rake"
      # end
      private

      def copy_migration(filename)
        if self.class.migration_exists?("db/migrate", "#{filename}")
          say_status("skipped", "Migration #{filename}.rb already exists")
        else
          migration_template "#{filename}.rb", "db/migrate/#{filename}.rb"
        end
      end
    end
  end
end

Version data entries

11 entries across 11 versions & 1 rubygems

Version Path
hicube-0.0.11 lib/generators/hicube/install/install_generator.rb
hicube-0.0.10 lib/generators/hicube/install/install_generator.rb
hicube-0.0.9 lib/generators/hicube/install/install_generator.rb
hicube-0.0.8 lib/generators/hicube/install/install_generator.rb
hicube-0.0.7 lib/generators/hicube/install/install_generator.rb
hicube-0.0.6 lib/generators/hicube/install/install_generator.rb
hicube-0.0.5 lib/generators/hicube/install/install_generator.rb
hicube-0.0.4 lib/generators/hicube/install/install_generator.rb
hicube-0.0.3 lib/generators/hicube/install/install_generator.rb
hicube-0.0.2 lib/generators/hicube/install/install_generator.rb
hicube-0.0.1 lib/generators/hicube/install/install_generator.rb