Sha256: 342e53bf93225412704f4b4360a9d339345811b20ce62d9db02b1285dad1856b

Contents?: true

Size: 1.25 KB

Versions: 1

Compression:

Stored size: 1.25 KB

Contents

require 'rails'

module BinInstall
  module Rails
    def self.db_setup
      puts 'Preparing database...'.white
      rails_or_rake('db:setup')
      rails_or_rake!('db:setup RAILS_ENV=test')
    end

    def self.db_setup!
      puts 'Preparing database...'.white
      rails_or_rake!('db:setup')
      rails_or_rake!('db:setup RAILS_ENV=test')
    end

    def self.db_migrate
      puts 'Migrating database...'.white
      rails_or_rake('db:migrate')
    end

    def self.db_migrate!
      puts 'Migrating database...'.white
      rails_or_rake!('db:migrate')
    end

    def self.clear
      puts 'Removing unnecessary files...'.white
      rails_or_rake('log:clear')
      rails_or_rake('tmp:clear')
    end

    def self.clear!
      puts 'Removing unnecessary files...'.white
      rails_or_rake!('log:clear')
      rails_or_rake!('tmp:clear')
    end

    def self.rails_or_rake(command)
      if rails5?
        system("bin/rails #{command}")
      else
        system("bin/rake #{command}")
      end
    end

    def self.rails_or_rake!(command)
      if rails5?
        BinInstall.system!("bin/rails #{command}")
      else
        BinInstall.system!("bin/rake #{command}")
      end
    end

    def self.rails5?
      ::Rails::VERSION::MAJOR >= 5
    end
  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
bin_install-0.0.6 lib/bin_install/rails.rb