class Parity::Environment
Constants
- PROTECTED_ENVIRONMENTS
Attributes
app_argument[RW]
arguments[RW]
environment[RW]
subcommand[RW]
Public Class Methods
new(environment, subcommands, app_argument: "--remote")
click to toggle source
# File lib/parity/environment.rb, line 5 def initialize(environment, subcommands, app_argument: "--remote") self.environment = environment self.subcommand = subcommands[0] self.arguments = subcommands[1..-1] self.app_argument = app_argument end
Public Instance Methods
run()
click to toggle source
# File lib/parity/environment.rb, line 12 def run run_command || false end
Private Instance Methods
additional_restore_arguments()
click to toggle source
# File lib/parity/environment.rb, line 93 def additional_restore_arguments (arguments.drop(1) - ["--force", "--parallelize"] + [restore_confirmation_argument]).compact.join(" ") end
backup()
click to toggle source
# File lib/parity/environment.rb, line 38 def backup Kernel.system("heroku pg:backups:capture #{app_argument} #{environment}") end
branch_ref()
click to toggle source
# File lib/parity/environment.rb, line 52 def branch_ref main_ref_exists = system("git show-ref --verify --quiet refs/heads/main") master_ref_exists = system( "git show-ref --verify --quiet refs/heads/master", ) if main_ref_exists && !master_ref_exists "main" else "master" end end
command_for_remote(command)
click to toggle source
# File lib/parity/environment.rb, line 133 def command_for_remote(command) "heroku #{command} #{app_argument} #{environment}" end
console()
click to toggle source
# File lib/parity/environment.rb, line 108 def console Kernel.system( command_for_remote( "run bundle exec rails console #{arguments.join(' ')}", ), ) end
deploy()
click to toggle source
# File lib/parity/environment.rb, line 42 def deploy if production? Kernel.system("git push production #{branch_ref}") else Kernel.system( "git push #{environment} HEAD:#{branch_ref} --force", ) end end
forced?()
click to toggle source
# File lib/parity/environment.rb, line 85 def forced? arguments.include?("--force") end
from_development?()
click to toggle source
# File lib/parity/environment.rb, line 104 def from_development? arguments.first == "development" end
heroku_app_name()
click to toggle source
# File lib/parity/environment.rb, line 129 def heroku_app_name HerokuAppName.new(environment).to_s end
methodized_subcommand()
click to toggle source
# File lib/parity/environment.rb, line 137 def methodized_subcommand subcommand.gsub("-", "_").to_sym end
migrate()
click to toggle source
# File lib/parity/environment.rb, line 116 def migrate Kernel.system(%{ #{command_for_remote('run rake db:migrate')} && #{command_for_remote('restart')} }) end
open()
click to toggle source
# File lib/parity/environment.rb, line 30 def open run_via_cli end
parallelize?()
click to toggle source
# File lib/parity/environment.rb, line 89 def parallelize? arguments.include?("--parallelize") end
production?()
click to toggle source
# File lib/parity/environment.rb, line 81 def production? environment == "production" end
restore()
click to toggle source
# File lib/parity/environment.rb, line 65 def restore if production? && !forced? $stdout.puts "Parity does not support restoring backups into your "\ "production environment. Use `--force` to override." else Backup.new( from: arguments.first, to: environment, parallelize: parallelize?, additional_args: additional_restore_arguments, ).restore end end
Also aliased as: restore_from
restore_confirmation_argument()
click to toggle source
# File lib/parity/environment.rb, line 98 def restore_confirmation_argument unless PROTECTED_ENVIRONMENTS.include?(environment) || from_development? "--confirm #{heroku_app_name}" end end
run_command()
click to toggle source
# File lib/parity/environment.rb, line 22 def run_command if self.class.private_method_defined?(methodized_subcommand) send(methodized_subcommand) else run_via_cli end end
run_via_cli()
click to toggle source
# File lib/parity/environment.rb, line 34 def run_via_cli Kernel.exec("heroku", subcommand, *arguments, app_argument, environment) end
tail()
click to toggle source
# File lib/parity/environment.rb, line 123 def tail Kernel.system( command_for_remote("logs --tail #{arguments.join(' ')}"), ) end