Class: ThreeScale::Backend::AlertLimit
Instance Attribute Summary collapse
Class Method Summary
collapse
Instance Method Summary
collapse
Methods included from Storable
included, #initialize, #storage
#encode_key
Instance Attribute Details
#service_id ⇒ Object
Returns the value of attribute service_id.
9
10
11
|
# File 'lib/3scale/backend/alert_limit.rb', line 9
def service_id
@service_id
end
|
#value ⇒ Object
Returns the value of attribute value.
9
10
11
|
# File 'lib/3scale/backend/alert_limit.rb', line 9
def value
@value
end
|
Class Method Details
.delete(service_id, value) ⇒ Object
38
39
40
|
# File 'lib/3scale/backend/alert_limit.rb', line 38
def self.delete(service_id, value)
storage.srem(key_allowed_set(service_id), value.to_i) if valid_value?(value)
end
|
.load_all(service_id) ⇒ Object
26
27
28
29
30
31
|
# File 'lib/3scale/backend/alert_limit.rb', line 26
def self.load_all(service_id)
values = storage.smembers(key_allowed_set(service_id))
values.map do |value|
new(service_id: service_id, value: value.to_i)
end
end
|
.save(service_id, value) ⇒ Object
33
34
35
36
|
# File 'lib/3scale/backend/alert_limit.rb', line 33
def self.save(service_id, value)
alert_limit = new(service_id: service_id, value: value)
alert_limit if alert_limit.save
end
|
.valid_value?(value) ⇒ Boolean
42
43
44
45
|
# File 'lib/3scale/backend/alert_limit.rb', line 42
def self.valid_value?(value)
val = value.to_i
Alerts::ALERT_BINS.include?(val) && val.to_s == value.to_s
end
|
Instance Method Details
#save ⇒ Object
11
12
13
14
15
16
17
|
# File 'lib/3scale/backend/alert_limit.rb', line 11
def save
if valid?
res = storage.sadd(key_allowed_set(service_id), value.to_i)
Alerts::UsagesChecked.invalidate_for_service(service_id)
res
end
end
|
#to_hash ⇒ Object
19
20
21
22
23
24
|
# File 'lib/3scale/backend/alert_limit.rb', line 19
def to_hash
{
service_id: service_id,
value: value.to_i,
}
end
|