Sha256: a3f424879a1292004c11e579667873567c9244fa6339caede9003fa18013b51b

Contents?: true

Size: 571 Bytes

Versions: 15

Compression:

Stored size: 571 Bytes

Contents

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

15 entries across 15 versions & 1 rubygems

Version Path
service_skeleton-0.0.0.34.g4f6fdb0 lib/service_skeleton/metrics_methods.rb
service_skeleton-0.0.0.30.g32b8169 lib/service_skeleton/metrics_methods.rb
service_skeleton-0.0.0.29.g23642ab lib/service_skeleton/metrics_methods.rb
service_skeleton-0.0.0.28.gae2711b lib/service_skeleton/metrics_methods.rb
service_skeleton-0.0.0.25.gbf57918 lib/service_skeleton/metrics_methods.rb
service_skeleton-0.0.0.20.gb9a0460 lib/service_skeleton/metrics_methods.rb
service_skeleton-0.0.0.16.g99ff4d7 lib/service_skeleton/metrics_methods.rb
service_skeleton-0.0.0.15.g53952e3 lib/service_skeleton/metrics_methods.rb
service_skeleton-0.0.0.14.g60b4507 lib/service_skeleton/metrics_methods.rb
service_skeleton-0.0.0.13.ga523c90 lib/service_skeleton/metrics_methods.rb
service_skeleton-0.0.0.11.gc1cf3ce lib/service_skeleton/metrics_methods.rb
service_skeleton-0.0.0.3.g1269800.1.gaaa2fa1.6.gf4e308e lib/service_skeleton/metrics_methods.rb
service_skeleton-0.0.0.3.g1269800.1.gaaa2fa1 lib/service_skeleton/metrics_methods.rb
service_skeleton-0.0.0.3.g1269800 lib/service_skeleton/metrics_methods.rb
service_skeleton-0.0.0.2.g46c1e0e lib/service_skeleton/metrics_methods.rb