Sha256: 4d5c4dcde7f17cbac72772b0b96bda8ae90ff931b61378a7c254652f09db7632

Contents?: true

Size: 1022 Bytes

Versions: 3

Compression:

Stored size: 1022 Bytes

Contents

# frozen_string_literal: true

require_relative "group_set"
require_relative "option_set"

module Eye::Patch

  class Application < Hash

    def initialize(settings)
      super()
      @settings = settings
      self[settings[:name]] = parse
    end

    private

    def parse
      parse_configuration
      parse_processes

      @config
    end

    def parse_configuration
      @config = @settings.fetch(:application, {}).merge(
        name: @settings[:name],
        notify: notifications,
        triggers: triggers,
        checks: checks,
      )
    end

    def parse_processes
      @config[:groups] = GroupSet.new(@config, @settings[:processes])
    end

    def notifications
      Array(@settings[:notifications]).each_with_object({}) do |notify, monitors|
        monitors[notify[:name]] = notify[:level].to_sym
      end
    end

    def triggers
      OptionSet.new(Eye::Trigger, @settings[:triggers])
    end

    def checks
      OptionSet.new(Eye::Checker, @settings[:checks])
    end

  end

end

Version data entries

3 entries across 3 versions & 1 rubygems

Version Path
eye-patch-1.1.0 lib/eye/patch/application.rb
eye-patch-1.0.1 lib/eye/patch/application.rb
eye-patch-1.0.0 lib/eye/patch/application.rb