Class: EasyCaddy::Commands::Remove

Inherits:
Object
  • Object
show all
Defined in:
lib/easy_caddy/commands/remove.rb

Instance Method Summary collapse

Constructor Details

#initialize(name:, force:, prompt:) ⇒ Remove

Returns a new instance of Remove.



10
11
12
13
14
15
# File 'lib/easy_caddy/commands/remove.rb', line 10

def initialize(name:, force:, prompt:)
  @name     = name.downcase
  @force    = force
  @prompt   = prompt
  @registry = Registry.load
end

Instance Method Details

#callObject



17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
# File 'lib/easy_caddy/commands/remove.rb', line 17

def call
  site = @registry.find(@name)
  unless site
    warn "  Site '#{@name}' is not registered."
    exit 1
  end

  unless @force
    unless @prompt.yes?("Remove #{@name} and delete its Caddy fragment?")
      puts '  Aborted.'
      return
    end
  end

  [Paths.site_file(@name), Paths.disabled_file(@name)].each do |f|
    f.delete if f.exist?
  end

  @registry.remove(@name)
  Caddy.reload(Paths.caddyfile)
  puts "  Removed '#{@name}'."
end