Sha256: 91eb2640a2253b16ec6f06905df27875dcfd0eca21cf86032bcb5accb732e4ba

Contents?: true

Size: 748 Bytes

Versions: 1

Compression:

Stored size: 748 Bytes

Contents

module Pageflow
  module Quota
    class ExceededError < RuntimeError
      attr_reader :quota_name

      def initialize(quota_name)
        @quota_name = quota_name
      end
    end

    def exceeded?(name, account)
      raise(NotImplementedError, 'Quota#exceeded? must be implemented.')
    end

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

    def verify!(name, account)
      raise(ExceededError.new(name), "Quota #{name} exceeded.") if exceeded?(name, account)
    end

    class Unlimited
      include Quota

      def exceeded?(name, account)
        false
      end

      def state_description(name, account)
        nil
      end
    end
  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
pageflow-0.1.0 lib/pageflow/quota.rb