Sha256: 981e04241873e29afb27df4981b0d660bf0be4dcb5a28f1508ca5e243bf99f52

Contents?: true

Size: 880 Bytes

Versions: 2

Compression:

Stored size: 880 Bytes

Contents

module Adalog
  module SimpleLoggingAdapter

    def self.new(service_name, repo)
      new_logger_class = Class.new(self::Base)
      new_logger_class.instance_variable_set(:@service_name, service_name)
      new_logger_class.instance_variable_set(:@repo, repo)
      new_logger_class
    end


    class Base

      class << self
        def service_name; @service_name ; end
        def repo        ; @repo         ; end
      end

      attr_reader :service_name, :repo

      def initialize(*args, **kwargs, &block)
        @service_name = self.class.service_name
        @repo         = self.class.repo
      end

      ##
      # TODO: Record something w.r.t. whether or not a block is given?
      def method_missing(msg, *args, &block)
        repo.insert(
          title:    service_name,
          message:  msg,
          details:  args)
      end
    end

  end
end

Version data entries

2 entries across 2 versions & 1 rubygems

Version Path
adalog-0.5.0 lib/adalog/simple_logging_adapter.rb
adalog-0.4.1 lib/adalog/simple_logging_adapter.rb