Class: Pageflow::Quota

Inherits:
Object
  • Object
show all
Defined in:
lib/pageflow/quota.rb

Direct Known Subclasses

Unlimited

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, )
  @name = name
  @account = 
end

Instance Attribute Details

#accountObject (readonly)

Returns the value of attribute account


13
14
15
# File 'lib/pageflow/quota.rb', line 13

def 
  @account
end

#nameObject (readonly)

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

Returns:

  • (Boolean)

28
29
30
# File 'lib/pageflow/quota.rb', line 28

def available?
  state == 'available'
end

#exceeded?Boolean

Returns:

  • (Boolean)

36
37
38
# File 'lib/pageflow/quota.rb', line 36

def exceeded?
  state == 'exceeded'
end

#exhausted?Boolean

Returns:

  • (Boolean)

32
33
34
# File 'lib/pageflow/quota.rb', line 32

def exhausted?
  !available?
end

#stateObject

Raises:

  • (NotImplementedError)

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_descriptionObject

Raises:

  • (NotImplementedError)

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

Raises:


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

Raises:


44
45
46
# File 'lib/pageflow/quota.rb', line 44

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