<commit_before>require "parity/backup"

module Parity
  class Environment
    def initialize(environment, subcommands)
      self.environment = environment
      self.subcommand = subcommands[0]
      self.arguments = subcommands[1..-1]
    end

    def run
      if subcommand == "redis-cli"
        redis_cli
      elsif self.class.private_method_defined?(subcommand)
        send(subcommand)
      else
        run_via_cli
      end
    end

    private

    attr_accessor :environment, :subcommand, :arguments

    def open
      run_via_cli
    end

    def run_via_cli
      Kernel.system("heroku", subcommand, *arguments, "--remote", environment)
    end

    def backup
      Kernel.system("heroku pg:backups capture --remote #{environment}")
    end

    def deploy
      if deploy_to_heroku && run_migration?
        migrate
      end
    end

    def deploy_to_heroku
      if environment == "production"
        Kernel.system("git push production master")
      else
        Kernel.system(
          "git push #{environment} HEAD:master --force",
        )
      end
    end

    def restore
      if environment == "production"
        $stdout.puts "Parity does not support restoring backups into your "\
          "production environment."
      else
        Backup.new(
          from: arguments.first,
          to: environment,
          additional_args: arguments.drop(1).join(" ")
        ).restore
      end
    end

    def console
      Kernel.system("heroku run rails console --remote #{environment}")
    end<commit_msg>Add production? method<commit_after>require "parity/backup"

module Parity
  class Environment
    def initialize(environment, subcommands)
      self.environment = environment
      self.subcommand = subcommands[0]
      self.arguments = subcommands[1..-1]
    end

    def run
      if subcommand == "redis-cli"
        redis_cli
      elsif self.class.private_method_defined?(subcommand)
        send(subcommand)
      else
        run_via_cli
      end
    end

    private

    attr_accessor :environment, :subcommand, :arguments

    def open
      run_via_cli
    end

    def run_via_cli
      Kernel.system("heroku", subcommand, *arguments, "--remote", environment)
    end

    def backup
      Kernel.system("heroku pg:backups capture --remote #{environment}")
    end

    def deploy
      if deploy_to_heroku && run_migration?
        migrate
      end
    end

    def deploy_to_heroku
      if production?
        Kernel.system("git push production master")
      else
        Kernel.system(
          "git push #{environment} HEAD:master --force",
        )
      end
    end

    def restore
      if production?
        $stdout.puts "Parity does not support restoring backups into your "\
          "production environment."
      else
        Backup.new(
          from: arguments.first,
          to: environment,
          additional_args: arguments.drop(1).join(" ")
        ).restore
      end
    end

    def production?
      environment == "production"
    end

    def console
      Kernel.system("heroku run rails console --remote #{environment}")
    end
{'fraction_non_alphanumeric': 0.08184143222506395, 'fraction_numerical': 0.0025575447570332483, 'mean_word_length': 2.110337972166998, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '7358994', 'n_tokens_mistral': 886, 'n_tokens_neox': 856, 'n_words': 236}