Class: EasyCaddy::Commands::Down

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

Instance Method Summary collapse

Constructor Details

#initialize(name:) ⇒ Down

Returns a new instance of Down.



11
12
13
14
# File 'lib/easy_caddy/commands/down.rb', line 11

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

Instance Method Details

#callObject



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

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

  if !site.enabled
    puts "  '#{@name}' is already down."
    return
  end

  active = Paths.site_file(@name)
  unless active.exist?
    warn "  Fragment not found in sites/: #{active}"
    exit 1
  end

  Paths.disabled_dir.mkpath
  active.rename(Paths.disabled_file(@name))
  @registry.update(Site.new(name: site.name, enabled: false, source_path: site.source_path))
  Caddy.reload(Paths.caddyfile)
  puts "  '#{@name}' is down. Run `ecaddy up #{@name}` to bring it back."
end