Sha256: 613bf8ced0b338bb9c1ef45bc477ddd85e2c3d36206b7b621e23ae5f55eb7fbf

Contents?: true

Size: 1.01 KB

Versions: 7

Compression:

Stored size: 1.01 KB

Contents

module Eye::Patch

  class ProcessSet < Hash

    def initialize(group, processes)
      @group = group

      Array(processes).each do |process|
        parse_process(process)
      end
    end

    private

    def parse_process(process)
      if process[:count]
        parse_process_cluster(process)
      else
        parse_single_process(process[:name], process[:config])
      end
    end

    def parse_process_cluster(process)
      process[:count].times do |index|
        name = "#{process[:name]}-#{index}"
        parse_single_process(name, indexed_config(process[:config], index))
      end
    end

    def parse_single_process(name, config)
      self[name] = @group
        .merge(stdout: config[:stdall], stderr: config[:stdall])
        .merge(config)
        .merge(name: name, group: @group[:name])
    end

    def indexed_config(config, index)
      config.each_with_object({}) do |(key, value), result|
        result[key] = value.is_a?(String) ? value.gsub("{ID}", index.to_s) : value
      end
    end
  end
end

Version data entries

7 entries across 7 versions & 1 rubygems

Version Path
eye-patch-0.1.4 lib/eye/patch/process_set.rb
eye-patch-0.1.3 lib/eye/patch/process_set.rb
eye-patch-0.1.2 lib/eye/patch/process_set.rb
eye-patch-0.1.1 lib/eye/patch/process_set.rb
eye-patch-0.1.0 lib/eye/patch/process_set.rb
eye-patch-0.0.9 lib/eye/patch/process_set.rb
eye-patch-0.0.8 lib/eye/patch/process_set.rb