Class: Kamal::Commander::Specifics

Inherits:
Object
  • Object
show all
Defined in:
lib/kamal/commander/specifics.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(config, specific_hosts, specific_roles) ⇒ Specifics

Returns a new instance of Specifics.



5
6
7
8
9
10
11
12
13
14
15
# File 'lib/kamal/commander/specifics.rb', line 5

def initialize(config, specific_hosts, specific_roles)
  @config, @specific_hosts, @specific_roles = config, specific_hosts, specific_roles

  @roles, @hosts = specified_roles, specified_hosts

  @primary_host = specific_hosts&.first || primary_specific_role&.primary_host || config.primary_host
  @primary_role = primary_or_first_role(roles_on(primary_host))

  stable_sort!(roles) { |role| role == primary_role ? 0 : 1 }
  stable_sort!(hosts) { |host| roles_on(host).any? { |role| role == primary_role } ? 0 : 1 }
end

Instance Attribute Details

#hostsObject (readonly)

Returns the value of attribute hosts.



2
3
4
# File 'lib/kamal/commander/specifics.rb', line 2

def hosts
  @hosts
end

#primary_hostObject (readonly)

Returns the value of attribute primary_host.



2
3
4
# File 'lib/kamal/commander/specifics.rb', line 2

def primary_host
  @primary_host
end

#primary_roleObject (readonly)

Returns the value of attribute primary_role.



2
3
4
# File 'lib/kamal/commander/specifics.rb', line 2

def primary_role
  @primary_role
end

#rolesObject (readonly)

Returns the value of attribute roles.



2
3
4
# File 'lib/kamal/commander/specifics.rb', line 2

def roles
  @roles
end

Instance Method Details

#accessory_hostsObject



25
26
27
# File 'lib/kamal/commander/specifics.rb', line 25

def accessory_hosts
  config.accessories.flat_map(&:hosts) & specified_hosts
end

#proxy_hostsObject



21
22
23
# File 'lib/kamal/commander/specifics.rb', line 21

def proxy_hosts
  config.proxy_hosts & specified_hosts
end

#roles_on(host) ⇒ Object



17
18
19
# File 'lib/kamal/commander/specifics.rb', line 17

def roles_on(host)
  roles.select { |role| role.hosts.include?(host.to_s) }
end