Sha256: bf0fac345107981690146fefdc90c1a6b2188b4f3e3549e90ee2149cbbee2eda

Contents?: true

Size: 1.64 KB

Versions: 4

Compression:

Stored size: 1.64 KB

Contents

require File.expand_path('../../formats', __FILE__)

module Neutral
  module Generators
    class UninstallGenerator < ::Rails::Generators::Base
      include ::Rails::Generators::Migration
      include Neutral::Formats

      source_root File.expand_path("../templates", __FILE__)

      def remove_route
        comment_lines "config/routes.rb", /neutral/
      end

      def remove_locale
        remove_file "config/locales/neutral.yml"
      end

      def remove_stylesheet
        if File.binread(css_format[0]).include? "require neutral"
          gsub_file css_format[0], "\n#{css_format[1]} require neutral\n", ""
        else
          say_status("skipped", "remove from '#{css_format[0]}'", :yellow)
        end
      end

      def remove_database_entities
        -> {
          migration_template "drop_neutral_votes_table.rb", "db/migrate/drop_neutral_votes_table"
          migration_template "drop_neutral_votings_table.rb", "db/migrate/drop_neutral_votings_table"

          rake("db:migrate")

          Dir.glob("db/migrate/*").keep_if { |f| f.include?("neutral") }.each do |file|
            remove_file(file)
          end if yes?("Remove also remaining migration files?")

        }.call if yes?("Remove database entities?('neutral_votes' and 'neutral_votings' tables)")
      end

      def remove_initializer
        remove_file "config/initializers/neutral.rb"
      end

      private
      def self.next_migration_number(dirname)
        if ActiveRecord::Base.timestamped_migrations
          Time.now.utc.strftime("%Y%m%d%H%M%S%6N")
        else
          "%.3d" % (current_migration_number(dirname) + 1)
        end
      end
    end
  end
end

Version data entries

4 entries across 4 versions & 1 rubygems

Version Path
neutral-0.0.4 lib/generators/neutral/uninstall/uninstall_generator.rb
neutral-0.0.3 lib/generators/neutral/uninstall/uninstall_generator.rb
neutral-0.0.2 lib/generators/neutral/uninstall/uninstall_generator.rb
neutral-0.0.1 lib/generators/neutral/uninstall/uninstall_generator.rb