Class: Mrsk::Configuration::Accessory
- Inherits:
-
Object
- Object
- Mrsk::Configuration::Accessory
- Defined in:
- lib/mrsk/configuration/accessory.rb
Instance Attribute Summary collapse
-
#name ⇒ Object
Returns the value of attribute name.
-
#specifics ⇒ Object
Returns the value of attribute specifics.
Instance Method Summary collapse
- #cmd ⇒ Object
- #directories ⇒ Object
- #env ⇒ Object
- #env_args ⇒ Object
- #files ⇒ Object
- #hosts ⇒ Object
- #image ⇒ Object
-
#initialize(name, config:) ⇒ Accessory
constructor
A new instance of Accessory.
- #label_args ⇒ Object
- #labels ⇒ Object
- #option_args ⇒ Object
- #port ⇒ Object
- #publish_args ⇒ Object
- #service_name ⇒ Object
- #volume_args ⇒ Object
- #volumes ⇒ Object
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
#name ⇒ Object
Returns the value of attribute name.
4 5 6 |
# File 'lib/mrsk/configuration/accessory.rb', line 4 def name @name end |
#specifics ⇒ Object
Returns the value of attribute specifics.
4 5 6 |
# File 'lib/mrsk/configuration/accessory.rb', line 4 def specifics @specifics end |
Instance Method Details
#cmd ⇒ Object
82 83 84 |
# File 'lib/mrsk/configuration/accessory.rb', line 82 def cmd specifics["cmd"] end |
#directories ⇒ Object
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(":") [ (host_relative_path), container_path ] end || {} end |
#env ⇒ Object
44 45 46 |
# File 'lib/mrsk/configuration/accessory.rb', line 44 def env specifics["env"] || {} end |
#env_args ⇒ Object
48 49 50 |
# File 'lib/mrsk/configuration/accessory.rb', line 48 def env_args argumentize_env_with_secrets env end |
#files ⇒ Object
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(":") [ (local_file), (remote_file) ] end || {} end |
#hosts ⇒ Object
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 |
#image ⇒ Object
14 15 16 |
# File 'lib/mrsk/configuration/accessory.rb', line 14 def image specifics["image"] end |
#label_args ⇒ Object
40 41 42 |
# File 'lib/mrsk/configuration/accessory.rb', line 40 def label_args argumentize "--label", labels end |
#labels ⇒ Object
36 37 38 |
# File 'lib/mrsk/configuration/accessory.rb', line 36 def labels default_labels.merge(specifics["labels"] || {}) end |
#option_args ⇒ Object
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 |
#port ⇒ Object
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_args ⇒ Object
32 33 34 |
# File 'lib/mrsk/configuration/accessory.rb', line 32 def publish_args argumentize "--publish", port if port end |
#service_name ⇒ Object
10 11 12 |
# File 'lib/mrsk/configuration/accessory.rb', line 10 def service_name "#{config.service}-#{name}" end |
#volume_args ⇒ Object
70 71 72 |
# File 'lib/mrsk/configuration/accessory.rb', line 70 def volume_args argumentize "--volume", volumes end |
#volumes ⇒ Object
66 67 68 |
# File 'lib/mrsk/configuration/accessory.rb', line 66 def volumes specific_volumes + remote_files_as_volumes + remote_directories_as_volumes end |