Class: Greenhouse::Commands::Purge

Inherits:
Object
  • Object
show all
Includes:
Command
Defined in:
lib/greenhouse/commands/purge.rb

Class Method Summary collapse

Instance Method Summary collapse

Methods included from Command

included

Class Method Details

.usageObject



11
12
13
14
15
16
17
18
19
20
21
# File 'lib/greenhouse/commands/purge.rb', line 11

def usage
  puts "usage: \#{::Greenhouse::CLI.command_name} \#{command_name} [<project>] \#{valid_arguments.to_s}\n\nArguments:\n\#{valid_arguments.to_help}\n\nProjects:\n\#{project_arguments.to_help}\n"
end

Instance Method Details

#clean?Boolean

Returns:

  • (Boolean)


24
25
26
27
28
29
30
# File 'lib/greenhouse/commands/purge.rb', line 24

def clean?
  return false if Projects::projects_file.exists?
  return false if Projects::ignore_file.exists?
  return false if Projects::procfile.exists?
  return false if Projects::projects.any?(&:exists?)
  true
end

#force?Boolean

Returns:

  • (Boolean)


32
33
34
# File 'lib/greenhouse/commands/purge.rb', line 32

def force?
  arguments.map(&:key).include?("-f")
end

#promptObject



66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
# File 'lib/greenhouse/commands/purge.rb', line 66

def prompt
  puts "\\e[31mThis will completely clean out the ecosystem, removing all projects and \noptionally dropping the database and wiping configuration files.\\e[0m\n\n" 
  puts "You will be prompted if you have any uncommitted local changes or unpushed branches\nin any of your projects and may choose to either take action or skip that project\nto avoid losing any work.\n\n"
  puts "You will be prompted separately to confirm whether you'd like to drop or keep your\ndatabases.\n"

  puts
  print "Are you sure you want to continue? ([y]es/[N]o): "
  continue = STDIN.gets.chomp.downcase
  ["y","yes"].include?(continue)
end

#purgeObject



58
59
60
61
62
63
64
# File 'lib/greenhouse/commands/purge.rb', line 58

def purge
  Projects.projects.each do |project|
    Tasks::PurgeProject.perform(project, force?)
  end

  Tasks::RemoveGreenhouseFiles.perform(force?) if purge_all?
end

#purge_all?Boolean

Returns:

  • (Boolean)


36
37
38
# File 'lib/greenhouse/commands/purge.rb', line 36

def purge_all?
  arguments.map(&:key).include?("-a")
end

#runObject



40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
# File 'lib/greenhouse/commands/purge.rb', line 40

def run
  app = Projects::projects.select { |project| arguments.map(&:key).include?(project.name) }.first
  if app.nil?
    if clean?
      puts "Nothing to do."
      return
    end
    #return unless force? || prompt
  
    purge
  else
    Tasks::PurgeProject.perform(app, force?)
  end

  puts "\e[33mDone\e[0m"
  return
end