Class: Pageflow::Quota
- Inherits:
-
Object
show all
- Defined in:
- lib/pageflow/quota.rb
Defined Under Namespace
Classes: ExceededError, ExhaustedError, Unlimited
Instance Attribute Summary collapse
Instance Method Summary
collapse
Constructor Details
#initialize(name, account) ⇒ Quota
Returns a new instance of Quota.
15
16
17
18
|
# File 'lib/pageflow/quota.rb', line 15
def initialize(name, account)
@name = name
@account = account
end
|
Instance Attribute Details
#account ⇒ Object
Returns the value of attribute account.
13
14
15
|
# File 'lib/pageflow/quota.rb', line 13
def account
@account
end
|
#name ⇒ Object
Returns the value of attribute name.
13
14
15
|
# File 'lib/pageflow/quota.rb', line 13
def name
@name
end
|
Instance Method Details
#assume(assumptions) ⇒ Object
48
49
50
|
# File 'lib/pageflow/quota.rb', line 48
def assume(assumptions)
self
end
|
#available? ⇒ Boolean
28
29
30
|
# File 'lib/pageflow/quota.rb', line 28
def available?
state == 'available'
end
|
#exceeded? ⇒ Boolean
36
37
38
|
# File 'lib/pageflow/quota.rb', line 36
def exceeded?
state == 'exceeded'
end
|
#exhausted? ⇒ Boolean
32
33
34
|
# File 'lib/pageflow/quota.rb', line 32
def exhausted?
!available?
end
|
#state ⇒ Object
20
21
22
|
# File 'lib/pageflow/quota.rb', line 20
def state
raise(NotImplementedError, 'Quota#state must be implemented and return either "available", "exhausted" or "exceeded".')
end
|
#state_description ⇒ Object
24
25
26
|
# File 'lib/pageflow/quota.rb', line 24
def state_description
raise(NotImplementedError, 'Quota#state_description must be implemented.')
end
|
#verify_available! ⇒ Object
40
41
42
|
# File 'lib/pageflow/quota.rb', line 40
def verify_available!
raise(ExhaustedError.new(self), "Quota '#{name}' exhausted.") unless available?
end
|
#verify_not_exceeded! ⇒ Object
44
45
46
|
# File 'lib/pageflow/quota.rb', line 44
def verify_not_exceeded!
raise(ExceededError.new(self), "Quota '#{name}' exceeded.") if exceeded?
end
|