Class: Kamal::Lint::Checks::AccessoryPlacementMissing

Inherits:
Kamal::Lint::Check show all
Defined in:
lib/kamal/lint/checks/accessory_placement_missing.rb

Overview

Accessories must declare placement via at least one of:

- host: <single host>
- hosts: [<host>, ...]
- roles: [<role>, ...]

An accessory with none of these has no defined target and Kamal won’t deploy it.

Instance Attribute Summary

Attributes inherited from Kamal::Lint::Check

#context

Instance Method Summary collapse

Methods inherited from Kamal::Lint::Check

applies_to?, autofixable, id, #initialize, severity, since, title, until_version

Constructor Details

This class inherits a constructor from Kamal::Lint::Check

Instance Method Details

#callObject



18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
# File 'lib/kamal/lint/checks/accessory_placement_missing.rb', line 18

def call
  accessories = parsed["accessories"]
  return [] unless accessories.is_a?(Hash)

  findings = []
  accessories.each do |name, accessory|
    next unless accessory.is_a?(Hash)

    has_placement = %w[host hosts roles].any? do |k|
      value = accessory[k]
      case value
      when String then !value.empty?
      when Array then value.any?
      else !value.nil?
      end
    end

    next if has_placement

    findings << finding(
      message: "accessory `#{name}` has no `host`, `hosts`, or `roles` declared; it will not be deployed anywhere",
      line: context.line_for([ "accessories", name ])
    )
  end
  findings
end