Class: EasyCaddy::Commands::Up

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

Instance Method Summary collapse

Constructor Details

#initialize(name:) ⇒ Up

Returns a new instance of Up.



11
12
13
14
# File 'lib/easy_caddy/commands/up.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/up.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 up."
    return
  end

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

  disabled.rename(Paths.site_file(@name))
  @registry.update(Site.new(name: site.name, enabled: true, source_path: site.source_path))
  Caddy.validate!(Paths.caddyfile)
  Caddy.reload(Paths.caddyfile)
  puts "  '#{@name}' is up."
end