Sha256: d33468f19a68b4ab15f904cf7597b66f48b3dd125909912084f3b9042878665f

Contents?: true

Size: 1.21 KB

Versions: 2

Compression:

Stored size: 1.21 KB

Contents

require_relative 'constants'

module UnderConstruction
  module Generators
    class ClearGenerator < ::Rails::Generators::Base
      desc 'Clears configs application controller'
      def clear_application_controller
        if File.exist?('app/controllers/application_controller.rb')
          # remove the exact block we've inserted. We don't want
          # to remove the block if user has edited it
          gsub_file 'app/controllers/application_controller.rb', /#{Regexp.escape(APPLICATION_CONFIG_TXT)}/,
            ''
        end
      end

      def clear_routes_file
        file_path = 'config/routes.rb'
        gsub_file file_path, /#{Regexp.escape(ROUTES_CONFIG_TXT)}/, ''
        gsub_file file_path, /#{Regexp.escape(ROUTES_REDIRECT_TO_TXT)}/, ''
        if ::Rails::VERSION::MAJOR >= 4
          insert_into_file file_path, ROUTES_CLEAR_TXT, after: /Rails.application.routes.draw do/
        else
          insert_into_file file_path, ROUTES_CLEAR_TXT, after: /Application.routes.draw do/
        end
      end

      def remove_scheduler_file
        file_path = 'config/initializers/under_construction_scheduler.rb'
        if File.exist? file_path
          remove_file file_path
        end
      end
    end
  end
end

Version data entries

2 entries across 2 versions & 1 rubygems

Version Path
under_construction-0.2.2 lib/generators/under_construction/clear_generator.rb
under_construction-0.2.1 lib/generators/under_construction/clear_generator.rb