Sha256: e0e8cc57f73e9c97cfc020624e71554c84665cbf247ec1a00996638a10268604

Contents?: true

Size: 1.15 KB

Versions: 108

Compression:

Stored size: 1.15 KB

Contents

module Pageflow
  class Quota
    class ExhaustedError < RuntimeError
      attr_reader :quota

      def initialize(quota)
        @quota = quota
      end
    end

    class ExceededError < ExhaustedError; end

    attr_reader :name, :account

    def initialize(name, account)
      @name = name
      @account = account
    end

    def state
      raise(NotImplementedError, 'Quota#state must be implemented and return either "available", "exhausted" or "exceeded".')
    end

    def state_description
      raise(NotImplementedError, 'Quota#state_description must be implemented.')
    end

    def available?
      state == 'available'
    end

    def exhausted?
      !available?
    end

    def exceeded?
      state == 'exceeded'
    end

    def verify_available!
      raise(ExhaustedError.new(self), "Quota '#{name}' exhausted.") unless available?
    end

    def verify_not_exceeded!
      raise(ExceededError.new(self), "Quota '#{name}' exceeded.") if exceeded?
    end

    def assume(assumptions)
      self
    end

    class Unlimited < Quota
      def state
        'available'
      end

      def state_description
        nil
      end
    end
  end
end

Version data entries

108 entries across 108 versions & 1 rubygems

Version Path
pageflow-15.0.0.beta2 lib/pageflow/quota.rb
pageflow-15.0.0.beta1 lib/pageflow/quota.rb
pageflow-14.3.0 lib/pageflow/quota.rb
pageflow-14.2.1 lib/pageflow/quota.rb
pageflow-14.2.0 lib/pageflow/quota.rb
pageflow-14.1.1 lib/pageflow/quota.rb
pageflow-14.1.0 lib/pageflow/quota.rb
pageflow-14.0.0 lib/pageflow/quota.rb
pageflow-14.0.0.rc2 lib/pageflow/quota.rb
pageflow-14.0.0.rc1 lib/pageflow/quota.rb
pageflow-14.0.0.beta3 lib/pageflow/quota.rb
pageflow-14.0.0.beta2 lib/pageflow/quota.rb
pageflow-14.0.0.beta1 lib/pageflow/quota.rb
pageflow-13.6.0 lib/pageflow/quota.rb
pageflow-13.5.0 lib/pageflow/quota.rb
pageflow-13.4.0 lib/pageflow/quota.rb
pageflow-13.3.0 lib/pageflow/quota.rb
pageflow-13.2.0 lib/pageflow/quota.rb
pageflow-12.6.0 lib/pageflow/quota.rb
pageflow-13.1.0 lib/pageflow/quota.rb