Sha256: ed6d883014d41c5bb94ae51c2e1d23289edd62cb3c8fa10fa5b737f3cd977f15

Contents?: true

Size: 602 Bytes

Versions: 3

Compression:

Stored size: 602 Bytes

Contents

# frozen_string_literal: true

class ServiceSkeleton
  module MetricsMethods
    def service=(svc)
      @service = svc
    end

    def register(metric)
      method_name = metric.name.to_s.gsub(/\A#{Regexp.quote(@service.service_name)}_/, '').to_sym

      if self.class.method_defined?(method_name)
        raise ServiceSkeleton::Error::InvalidMetricNameError,
              "There is already a method named #{method_name} on ##metrics, so you can't have a metric named #{metric.name}"
      end

      define_singleton_method(method_name) do
        metric
      end

      super
    end
  end
end

Version data entries

3 entries across 3 versions & 1 rubygems

Version Path
service_skeleton-0.0.0.44.g75d07d7 lib/service_skeleton/metrics_methods.rb
service_skeleton-0.0.0.43.g678698a lib/service_skeleton/metrics_methods.rb
service_skeleton-0.0.0.41.g9507cda lib/service_skeleton/metrics_methods.rb