Sha256: 41e393498a22e138ef1e8ce0829a640edaebadb61c4e69cf0d97bb18c0cba94a

Contents?: true

Size: 980 Bytes

Versions: 10

Compression:

Stored size: 980 Bytes

Contents

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[: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

10 entries across 10 versions & 1 rubygems

Version Path
eye-patch-0.1.4 lib/eye/patch/application.rb
eye-patch-0.1.3 lib/eye/patch/application.rb
eye-patch-0.1.2 lib/eye/patch/application.rb
eye-patch-0.1.1 lib/eye/patch/application.rb
eye-patch-0.1.0 lib/eye/patch/application.rb
eye-patch-0.0.9 lib/eye/patch/application.rb
eye-patch-0.0.8 lib/eye/patch/application.rb
eye-patch-0.0.7 lib/eye/patch/application.rb
eye-patch-0.0.6 lib/eye/patch/application.rb
eye-patch-0.0.5 lib/eye/patch/application.rb