Class: Allowed::Throttle
- Inherits:
-
Object
- Object
- Allowed::Throttle
- Defined in:
- lib/allowed/throttle.rb
Instance Attribute Summary collapse
-
#limit ⇒ Object
readonly
Returns the value of attribute limit.
-
#options ⇒ Object
readonly
Returns the value of attribute options.
Instance Method Summary collapse
- #callback ⇒ Object
-
#initialize(limit, options = {}) ⇒ Throttle
constructor
A new instance of Throttle.
- #message ⇒ Object
- #valid?(record) ⇒ Boolean
Constructor Details
#initialize(limit, options = {}) ⇒ Throttle
Returns a new instance of Throttle.
5 6 7 8 |
# File 'lib/allowed/throttle.rb', line 5 def initialize(limit, = {}) @limit = limit @options = end |
Instance Attribute Details
#limit ⇒ Object (readonly)
Returns the value of attribute limit.
3 4 5 |
# File 'lib/allowed/throttle.rb', line 3 def limit @limit end |
#options ⇒ Object (readonly)
Returns the value of attribute options.
3 4 5 |
# File 'lib/allowed/throttle.rb', line 3 def @options end |
Instance Method Details
#callback ⇒ Object
10 11 12 |
# File 'lib/allowed/throttle.rb', line 10 def callback .fetch(:callback, -> (record) { }) end |
#message ⇒ Object
14 15 16 |
# File 'lib/allowed/throttle.rb', line 14 def .fetch(:message, "Limit reached.") end |
#valid?(record) ⇒ Boolean
18 19 20 21 22 |
# File 'lib/allowed/throttle.rb', line 18 def valid?(record) return true if skip?(record) scope_for(record).count < allowed_count(record) end |