Sha256: a52bb6559c5a7f73c8834ff000e78721c1f99927c002539e3aa6a99ff6e4161d

Contents?: true

Size: 680 Bytes

Versions: 3

Compression:

Stored size: 680 Bytes

Contents

module Flipper
  module Adapters
    class ActorLimit < Wrapper
      LimitExceeded = Class.new(Flipper::Error)

      attr_reader :limit

      def initialize(adapter, limit = 100)
        super(adapter)
        @limit = limit
      end

      def enable(feature, gate, resource)
        if gate.is_a?(Flipper::Gates::Actor) && over_limit?(feature)
          raise LimitExceeded, "Actor limit of #{@limit} exceeded for feature #{feature.key}. See https://www.flippercloud.io/docs/features/actors#limitations"
        else
          super
        end
      end

      private

      def over_limit?(feature)
        feature.actors_value.size >= @limit
      end
    end
  end
end

Version data entries

3 entries across 3 versions & 1 rubygems

Version Path
flipper-1.3.2 lib/flipper/adapters/actor_limit.rb
flipper-1.3.1 lib/flipper/adapters/actor_limit.rb
flipper-1.3.0 lib/flipper/adapters/actor_limit.rb