Class: Mrsk::Configuration::Accessory

Inherits:
Object
  • Object
show all
Defined in:
lib/mrsk/configuration/accessory.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(name, config:) ⇒ Accessory

Returns a new instance of Accessory.



6
7
8
# File 'lib/mrsk/configuration/accessory.rb', line 6

def initialize(name, config:)
  @name, @config, @specifics = name.inquiry, config, config.raw_config["accessories"][name]
end

Instance Attribute Details

#nameObject

Returns the value of attribute name.



4
5
6
# File 'lib/mrsk/configuration/accessory.rb', line 4

def name
  @name
end

#specificsObject

Returns the value of attribute specifics.



4
5
6
# File 'lib/mrsk/configuration/accessory.rb', line 4

def specifics
  @specifics
end

Instance Method Details

#cmdObject



82
83
84
# File 'lib/mrsk/configuration/accessory.rb', line 82

def cmd
  specifics["cmd"]
end

#directoriesObject



59
60
61
62
63
64
# File 'lib/mrsk/configuration/accessory.rb', line 59

def directories
  specifics["directories"]&.to_h do |host_to_container_mapping|
    host_relative_path, container_path = host_to_container_mapping.split(":")
    [ expand_host_path(host_relative_path), container_path ]
  end || {}
end

#envObject



44
45
46
# File 'lib/mrsk/configuration/accessory.rb', line 44

def env
  specifics["env"] || {}
end

#env_argsObject



48
49
50
# File 'lib/mrsk/configuration/accessory.rb', line 48

def env_args
  argumentize_env_with_secrets env
end

#filesObject



52
53
54
55
56
57
# File 'lib/mrsk/configuration/accessory.rb', line 52

def files
  specifics["files"]&.to_h do |local_to_remote_mapping|
    local_file, remote_file = local_to_remote_mapping.split(":")
    [ expand_local_file(local_file), expand_remote_file(remote_file) ]
  end || {}
end

#hostsObject



18
19
20
21
22
23
24
# File 'lib/mrsk/configuration/accessory.rb', line 18

def hosts
  if (specifics.keys & ["host", "hosts", "roles"]).size != 1
    raise ArgumentError, "Specify one of `host`, `hosts` or `roles` for accessory `#{name}`"
  end

  hosts_from_host || hosts_from_hosts || hosts_from_roles
end

#imageObject



14
15
16
# File 'lib/mrsk/configuration/accessory.rb', line 14

def image
  specifics["image"]
end

#label_argsObject



40
41
42
# File 'lib/mrsk/configuration/accessory.rb', line 40

def label_args
  argumentize "--label", labels
end

#labelsObject



36
37
38
# File 'lib/mrsk/configuration/accessory.rb', line 36

def labels
  default_labels.merge(specifics["labels"] || {})
end

#option_argsObject



74
75
76
77
78
79
80
# File 'lib/mrsk/configuration/accessory.rb', line 74

def option_args
  if args = specifics["options"]
    optionize args
  else
    []
  end
end

#portObject



26
27
28
29
30
# File 'lib/mrsk/configuration/accessory.rb', line 26

def port
  if port = specifics["port"]&.to_s
    port.include?(":") ? port : "#{port}:#{port}"
  end
end

#publish_argsObject



32
33
34
# File 'lib/mrsk/configuration/accessory.rb', line 32

def publish_args
  argumentize "--publish", port if port
end

#service_nameObject



10
11
12
# File 'lib/mrsk/configuration/accessory.rb', line 10

def service_name
  "#{config.service}-#{name}"
end

#volume_argsObject



70
71
72
# File 'lib/mrsk/configuration/accessory.rb', line 70

def volume_args
  argumentize "--volume", volumes
end

#volumesObject



66
67
68
# File 'lib/mrsk/configuration/accessory.rb', line 66

def volumes
  specific_volumes + remote_files_as_volumes + remote_directories_as_volumes
end