Sha256: a3451031eed379d7e0aa03efa8ef82485da53b250799d132a23084a3114888e6

Contents?: true

Size: 493 Bytes

Versions: 4

Compression:

Stored size: 493 Bytes

Contents

require 'active_support/concern'

module Influxer
  module Scoping
    module Named # :nodoc: all
      extend ActiveSupport::Concern

      module ClassMethods
        def scope(name, scope)
          fail "Scope not defined: #{name}" if scope.nil? || !scope.respond_to?(:call)
          singleton_class.send(:define_method, name) do |*args|
            rel = all
            rel.merge!(rel.scoping { scope.call(*args) })
            rel
          end
        end
      end
    end
  end
end

Version data entries

4 entries across 4 versions & 1 rubygems

Version Path
influxer-0.5.0 lib/influxer/metrics/scoping/named.rb
influxer-0.4.0 lib/influxer/metrics/scoping/named.rb
influxer-0.3.1 lib/influxer/metrics/scoping/named.rb
influxer-0.2.4 lib/influxer/metrics/scoping/named.rb