Sha256: e9f8dd54104430883c19c0a080c28d91daebcdc455c379db21afb1f6905256ee

Contents?: true

Size: 1.08 KB

Versions: 3

Compression:

Stored size: 1.08 KB

Contents

require 'observed/observer'
require 'observed/reporter'

module Observed
  class System

    def initialize(args={})
      @config = args[:config] if args[:config]
      @logger = args[:logger] if args[:logger]
      @context = args[:context]
    end

    def config=(config)
      @config = config
    end

    def config
      @config
    end

    def run(observation_name=nil, data=nil, options=nil)
      options = { tag: (options && options[:tag]) || observation_name, time: now }.merge(options || {})
      params = [data, options]
      if observation_name
        fail "No configuration found for observation name '#{observation_name}'" if @context.config_builder.group(observation_name).empty?
        @context.config_builder.run_group(observation_name).send :now, *params
      else
        observers_to_run = @context.config_builder.observers
        fail "No configuration found for observation name '#{observation_name}'" if observers_to_run.empty?
        observers_to_run.each do |o|
          o.send :now, *params
        end
      end
    end

    def now
      Time.now
    end

  end

end

Version data entries

3 entries across 3 versions & 1 rubygems

Version Path
observed-0.2.0 lib/observed/system.rb
observed-0.2.0.rc2 lib/observed/system.rb
observed-0.2.0.rc1 lib/observed/system.rb