Sha256: 530184c876482adca2d789ee5d474ed557293a224c5c27c9ebe6eb4d08b4a880

Contents?: true

Size: 588 Bytes

Versions: 5

Compression:

Stored size: 588 Bytes

Contents

module Influxer
  module Scoping
    module Default
      extend ActiveSupport::Concern

      included do
        class_attribute :default_scopes
        self.default_scopes = []
      end

      module ClassMethods
        def default_scope(scope)
          self.default_scopes += [scope] unless scope.nil?
        end

        def unscoped
          Relation.new self
        end

        def default_scoped
          self.default_scopes.inject(Relation.new(self)) do |rel, scope| 
            rel.merge!(rel.scoping{ scope.call })
          end
        end
      end
    end
  end
end

Version data entries

5 entries across 5 versions & 1 rubygems

Version Path
influxer-0.2.2 lib/influxer/metrics/scoping/default.rb
influxer-0.2.0 lib/influxer/metrics/scoping/default.rb
influxer-0.1.2 lib/influxer/metrics/scoping/default.rb
influxer-0.1.1 lib/influxer/metrics/scoping/default.rb
influxer-0.1.0 lib/influxer/metrics/scoping/default.rb